From 9f0f3c7e29c1c721ceaeb3466976829bd486ee46 Mon Sep 17 00:00:00 2001 From: andrewmjc <105458703+andrewmjc@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:42:36 -0600 Subject: [PATCH] partners[openai]: Add name field to tool message to match OpenAI spec (#23551) Discovered alongside @t968914 - **Description:** According to OpenAI docs, tool messages (response from calling tools) must have a 'name' field. https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models - **Issue:** N/A (as of right now) - **Dependencies:** N/A - **Twitter handle:** N/A Additional guidelines: - Make sure optional dependencies are imported within a function. - Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests. - Most PRs should not touch more than one package. - Changes should be backwards compatible. - If you are adding something to community, do not re-import it in langchain. If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17. --- libs/partners/openai/langchain_openai/chat_models/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/partners/openai/langchain_openai/chat_models/base.py b/libs/partners/openai/langchain_openai/chat_models/base.py index b9c758024ab..bd25249f8b8 100644 --- a/libs/partners/openai/langchain_openai/chat_models/base.py +++ b/libs/partners/openai/langchain_openai/chat_models/base.py @@ -219,7 +219,7 @@ def _convert_message_to_dict(message: BaseMessage) -> dict: message_dict["role"] = "tool" message_dict["tool_call_id"] = message.tool_call_id - supported_props = {"content", "role", "tool_call_id"} + supported_props = {"content", "role", "tool_call_id", "name"} message_dict = {k: v for k, v in message_dict.items() if k in supported_props} else: raise TypeError(f"Got unknown type {message}")