Skip to content

Commit

Permalink
openai[patch]: fix name param (#19365)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis committed Mar 20, 2024
1 parent f6c8700 commit 0b20c09
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions libs/partners/openai/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ all: help
# Define a variable for the test file path.
TEST_FILE ?= tests/unit_tests/

integration_tests: TEST_FILE=tests/integration_tests/
integration_test integration_tests: TEST_FILE=tests/integration_tests/

test tests integration_tests:
test tests integration_test integration_tests:
poetry run pytest $(TEST_FILE)


Expand Down
13 changes: 10 additions & 3 deletions libs/partners/openai/langchain_openai/chat_models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,17 @@ def _convert_message_to_dict(message: BaseMessage) -> dict:
"""
message_dict: Dict[str, Any] = {
"content": message.content,
"name": message.name,
}
if message.name is not None:
message_dict["name"] = message.name
elif (
"name" in message.additional_kwargs
and message.additional_kwargs["name"] is not None
):
# fall back on additional kwargs for backwards compatibility
message_dict["name"] = message.additional_kwargs["name"]

# populate role and additional message data
if isinstance(message, ChatMessage):
message_dict["role"] = message.role
elif isinstance(message, HumanMessage):
Expand Down Expand Up @@ -171,8 +180,6 @@ def _convert_message_to_dict(message: BaseMessage) -> dict:
del message_dict["name"]
else:
raise TypeError(f"Got unknown type {message}")
if "name" in message.additional_kwargs:
message_dict["name"] = message.additional_kwargs["name"]
return message_dict


Expand Down

0 comments on commit 0b20c09

Please sign in to comment.