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

(Core) tool_choice overiding for with_structured_output for BaseChatModel #29321

Closed
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libs/core/langchain_core/language_models/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ class AnswerWithJustification(BaseModel):

Added support for TypedDict class.
""" # noqa: E501
if kwargs:
if kwargs and "tool_choice" not in kwargs:
msg = f"Received unsupported arguments {kwargs}"
raise ValueError(msg)

Expand All @@ -1239,7 +1239,7 @@ class AnswerWithJustification(BaseModel):
if self.bind_tools is BaseChatModel.bind_tools:
msg = "with_structured_output is not implemented for this model."
raise NotImplementedError(msg)
llm = self.bind_tools([schema], tool_choice="any")
llm = self.bind_tools([schema], tool_choice=kwargs.get("tool_choice", "any"))
if isinstance(schema, type) and is_basemodel_subclass(schema):
output_parser: OutputParserLike = PydanticToolsParser(
tools=[cast(TypeBaseModel, schema)], first_tool_only=True
Expand Down
Loading