diff --git a/libs/community/langchain_community/chat_models/tongyi.py b/libs/community/langchain_community/chat_models/tongyi.py index a39e744531a84..74a7d8a597475 100644 --- a/libs/community/langchain_community/chat_models/tongyi.py +++ b/libs/community/langchain_community/chat_models/tongyi.py @@ -547,6 +547,18 @@ def _stream_completion_with_retry(**_kwargs: Any) -> Any: if _kwargs.get("stream") and not _kwargs.get( "incremental_output", False ): + # inline fix response text logic + resp_copy = json.loads(json.dumps(resp)) + choice = resp_copy["output"]["choices"][0] + message = choice["message"] + if isinstance(message.get("content"), list): + content_text = "".join( + item.get("text", "") + for item in message["content"] + if isinstance(item, dict) + ) + message["content"] = content_text + resp = resp_copy if prev_resp is None: delta_resp = resp else: