diff --git a/libs/community/langchain_community/adapters/openai.py b/libs/community/langchain_community/adapters/openai.py index 8db939d5c9705..673e5fa567be8 100644 --- a/libs/community/langchain_community/adapters/openai.py +++ b/libs/community/langchain_community/adapters/openai.py @@ -180,6 +180,12 @@ def _convert_message_chunk(chunk: BaseMessageChunk, i: int) -> dict: # not missing, but None. if i == 0: _dict["content"] = None + if "tool_calls" in chunk.additional_kwargs: + _dict["tool_calls"] = chunk.additional_kwargs["tool_calls"] + # If the first chunk is tool calls, the content is not empty string, + # not missing, but None. + if i == 0: + _dict["content"] = None else: _dict["content"] = chunk.content else: diff --git a/libs/community/langchain_community/utilities/polygon.py b/libs/community/langchain_community/utilities/polygon.py index c7ab49f405467..f14069bd4fa61 100644 --- a/libs/community/langchain_community/utilities/polygon.py +++ b/libs/community/langchain_community/utilities/polygon.py @@ -45,7 +45,7 @@ def get_financials(self, ticker: str) -> Optional[dict]: data = response.json() status = data.get("status", None) - if status not in ("OK", "STOCKBUSINESS"): + if status not in ("OK", "STOCKBUSINESS", "STOCKSBUSINESS"): raise ValueError(f"API Error: {data}") return data.get("results", None) @@ -61,7 +61,7 @@ def get_last_quote(self, ticker: str) -> Optional[dict]: data = response.json() status = data.get("status", None) - if status not in ("OK", "STOCKBUSINESS"): + if status not in ("OK", "STOCKBUSINESS", "STOCKSBUSINESS"): raise ValueError(f"API Error: {data}") return data.get("results", None) @@ -82,7 +82,7 @@ def get_ticker_news(self, ticker: str) -> Optional[dict]: data = response.json() status = data.get("status", None) - if status not in ("OK", "STOCKBUSINESS"): + if status not in ("OK", "STOCKBUSINESS", "STOCKSBUSINESS"): raise ValueError(f"API Error: {data}") return data.get("results", None) @@ -116,7 +116,7 @@ def get_aggregates(self, ticker: str, **kwargs: Any) -> Optional[dict]: data = response.json() status = data.get("status", None) - if status not in ("OK", "STOCKBUSINESS"): + if status not in ("OK", "STOCKBUSINESS", "STOCKSBUSINESS"): raise ValueError(f"API Error: {data}") return data.get("results", None)