Skip to content

Commit

Permalink
community[patch]: re-arrange the addtional_kwargs of returned qianfan…
Browse files Browse the repository at this point in the history
… structure to avoid _merge_dict issue (#18889)

fix issue: #18441
PTAL, thanks
@baskaryan, @efriis, @eyurtsev, @hwchase17.

---------

Co-authored-by: Bagatur <[email protected]>
Co-authored-by: Bagatur <[email protected]>
  • Loading branch information
3 people authored Mar 12, 2024
1 parent 7512264 commit 471f2ed
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", []),
),
)


Expand Down

0 comments on commit 471f2ed

Please sign in to comment.