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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

openai[patch]: fix name param #19365

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
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
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