From 6792a3557dc396804a12ba8892b36a322434c7c6 Mon Sep 17 00:00:00 2001 From: David Preti Date: Wed, 19 Jul 2023 16:31:18 +0200 Subject: [PATCH] Update openai.py compatibility with azure 2023-07-01-preview (#7937) Fixed missing "content" field in azure. Added a check for "content" in _dict (missing for azure api=2023-07-01-preview) @baskaryan --------- Co-authored-by: Bagatur --- langchain/chat_models/openai.py | 4 +++- langchain/vectorstores/base.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/langchain/chat_models/openai.py b/langchain/chat_models/openai.py index e09ac9abf72..0a8d7b84fd3 100644 --- a/langchain/chat_models/openai.py +++ b/langchain/chat_models/openai.py @@ -100,7 +100,9 @@ def _convert_dict_to_message(_dict: Mapping[str, Any]) -> BaseMessage: if role == "user": return HumanMessage(content=_dict["content"]) elif role == "assistant": - content = _dict["content"] or "" # OpenAI returns None for tool invocations + # Fix for azure + # Also OpenAI returns None for tool invocations + content = _dict.get("content", "") if _dict.get("function_call"): additional_kwargs = {"function_call": dict(_dict["function_call"])} else: diff --git a/langchain/vectorstores/base.py b/langchain/vectorstores/base.py index a09ee25759c..73b2710228a 100644 --- a/langchain/vectorstores/base.py +++ b/langchain/vectorstores/base.py @@ -445,7 +445,7 @@ class VectorStoreRetriever(BaseRetriever): search_kwargs: dict = Field(default_factory=dict) allowed_search_types: ClassVar[Collection[str]] = ( "similarity", - "similarity_score_threshold", + "similarityatscore_threshold", "mmr", )