mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 15:19:33 +00:00
community[patch]: re-arrange the addtional_kwargs of returned qianfan structure to avoid _merge_dict issue (#18889)
fix issue: https://github.com/langchain-ai/langchain/issues/18441 PTAL, thanks @baskaryan, @efriis, @eyurtsev, @hwchase17. --------- Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
This commit is contained in:
parent
75122646b5
commit
471f2ed40a
@ -50,16 +50,22 @@ def convert_message_to_dict(message: BaseMessage) -> dict:
|
||||
|
||||
def _convert_dict_to_message(_dict: Mapping[str, Any]) -> AIMessage:
|
||||
content = _dict.get("result", "") or ""
|
||||
additional_kwargs: Mapping[str, Any] = {}
|
||||
if _dict.get("function_call"):
|
||||
additional_kwargs = {"function_call": dict(_dict["function_call"])}
|
||||
if "thoughts" in additional_kwargs["function_call"]:
|
||||
# align to api sample, which affects the llm function_call output
|
||||
additional_kwargs["function_call"].pop("thoughts")
|
||||
else:
|
||||
additional_kwargs = {}
|
||||
|
||||
additional_kwargs = {**_dict.get("body", {}), **additional_kwargs}
|
||||
return AIMessage(
|
||||
content=content,
|
||||
additional_kwargs={**_dict.get("body", {}), **additional_kwargs},
|
||||
additional_kwargs=dict(
|
||||
finish_reason=additional_kwargs.get("finish_reason", ""),
|
||||
request_id=additional_kwargs["id"],
|
||||
object=additional_kwargs.get("object", ""),
|
||||
search_info=additional_kwargs.get("search_info", []),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user