mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 15:43:54 +00:00
community: Add the additonnal kward 'context' for openai (#28351)
- **Description:** Add the additonnal kward 'context' for openai into `convert_dict_to_message` and `convert_message_to_dict` functions.
This commit is contained in:
parent
28487597b2
commit
60021e54b5
@ -91,6 +91,8 @@ def convert_dict_to_message(_dict: Mapping[str, Any]) -> BaseMessage:
|
|||||||
additional_kwargs["function_call"] = dict(function_call)
|
additional_kwargs["function_call"] = dict(function_call)
|
||||||
if tool_calls := _dict.get("tool_calls"):
|
if tool_calls := _dict.get("tool_calls"):
|
||||||
additional_kwargs["tool_calls"] = tool_calls
|
additional_kwargs["tool_calls"] = tool_calls
|
||||||
|
if context := _dict.get("context"):
|
||||||
|
additional_kwargs["context"] = context
|
||||||
return AIMessage(content=content, additional_kwargs=additional_kwargs)
|
return AIMessage(content=content, additional_kwargs=additional_kwargs)
|
||||||
elif role == "system":
|
elif role == "system":
|
||||||
return SystemMessage(content=_dict.get("content", ""))
|
return SystemMessage(content=_dict.get("content", ""))
|
||||||
@ -135,6 +137,11 @@ def convert_message_to_dict(message: BaseMessage) -> dict:
|
|||||||
# If tool calls only, content is None not empty string
|
# If tool calls only, content is None not empty string
|
||||||
if message_dict["content"] == "":
|
if message_dict["content"] == "":
|
||||||
message_dict["content"] = None
|
message_dict["content"] = None
|
||||||
|
if "context" in message.additional_kwargs:
|
||||||
|
message_dict["context"] = message.additional_kwargs["context"]
|
||||||
|
# If context only, content is None not empty string
|
||||||
|
if message_dict["content"] == "":
|
||||||
|
message_dict["content"] = None
|
||||||
elif isinstance(message, SystemMessage):
|
elif isinstance(message, SystemMessage):
|
||||||
message_dict = {"role": "system", "content": message.content}
|
message_dict = {"role": "system", "content": message.content}
|
||||||
elif isinstance(message, FunctionMessage):
|
elif isinstance(message, FunctionMessage):
|
||||||
|
Loading…
Reference in New Issue
Block a user