Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partners: replace deprecated .dict() with .model_dump() in openai base.py #16629

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions libs/partners/openai/langchain_openai/chat_models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,11 @@ def _stream(
default_chunk_class = AIMessageChunk
for chunk in self.client.create(messages=message_dicts, **params):
if not isinstance(chunk, dict):
chunk = chunk.dict()
chunk = (
getattr(chunk, "model_dump")()
if hasattr(chunk, "model_dump")
else chunk.dict()
)
if len(chunk["choices"]) == 0:
continue
choice = chunk["choices"][0]
Expand Down Expand Up @@ -465,7 +469,11 @@ def _create_message_dicts(
def _create_chat_result(self, response: Union[dict, BaseModel]) -> ChatResult:
generations = []
if not isinstance(response, dict):
response = response.dict()
response = (
getattr(response, "model_dump")()
if hasattr(response, "model_dump")
else response.dict()
)
for res in response["choices"]:
message = _convert_dict_to_message(res["message"])
generation_info = dict(finish_reason=res.get("finish_reason"))
Expand Down Expand Up @@ -499,7 +507,11 @@ async def _astream(
messages=message_dicts, **params
):
if not isinstance(chunk, dict):
chunk = chunk.dict()
chunk = (
getattr(chunk, "model_dump")()
if hasattr(chunk, "model_dump")
else chunk.dict()
)
if len(chunk["choices"]) == 0:
continue
choice = chunk["choices"][0]
Expand Down