openai, anthropic, ...: with_structured_output to pass in explicit tool choice (#23645)

...community, mistralai, groq, fireworks

part of #23644
This commit is contained in:
Bagatur
2024-06-28 16:39:53 -07:00
committed by GitHub
parent c5f35a72da
commit fc8fd49328
7 changed files with 22 additions and 16 deletions

View File

@@ -986,7 +986,9 @@ class ChatAnthropic(BaseChatModel):
# }
""" # noqa: E501
llm = self.bind_tools([schema], tool_choice="any")
tool_name = convert_to_anthropic_tool(schema)["name"]
llm = self.bind_tools([schema], tool_choice=tool_name)
if isinstance(schema, type) and issubclass(schema, BaseModel):
output_parser = ToolsOutputParser(
first_tool_only=True, pydantic_schemas=[schema]