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 <baskaryan@gmail.com>
This commit is contained in:
David Preti 2023-07-19 16:31:18 +02:00 committed by GitHub
parent b65102bdb2
commit 6792a3557d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -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:

View File

@ -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",
)