Skip to content

Commit

Permalink
Fixes a problem where formatted tools would break
Browse files Browse the repository at this point in the history
It seems like the first time we are calling _format_tools everything works fine, but on a second run, the _snake_case_to_camel_case converts the input parameters to camelCase and breaks the tools.
  • Loading branch information
userlerueda committed Jun 17, 2024
1 parent c1eef52 commit f1dbef2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libs/aws/langchain_aws/chat_models/bedrock_converse.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ class Joke(BaseModel):
config: Any = None
"""An optional botocore.config.Config instance to pass to the client."""

formatted_tools: List[
Dict[Literal["toolSpec"], Dict[str, Union[Dict[str, Any], str]]]
] = Field(default_factory=list, exclude=True)
""""Formatted tools to be stored and used in the toolConfig parameter."""

class Config:
"""Configuration for this pydantic object."""

Expand Down Expand Up @@ -411,7 +416,8 @@ def bind_tools(
) -> Runnable[LanguageModelInput, BaseMessage]:
if tool_choice:
kwargs["tool_choice"] = _format_tool_choice(tool_choice)
return self.bind(tools=_format_tools(tools), **kwargs)
self.formatted_tools = _format_tools(tools)
return self.bind(tools=self.formatted_tools, **kwargs)

def with_structured_output(
self,
Expand Down Expand Up @@ -465,7 +471,7 @@ def _converse_params(
}
if not toolConfig and tools:
toolChoice = _format_tool_choice(toolChoice) if toolChoice else None
toolConfig = {"tools": _format_tools(tools), "toolChoice": toolChoice}
toolConfig = {"tools": self.formatted_tools, "toolChoice": toolChoice}
return _drop_none(
{
"modelId": modelId or self.model_id,
Expand Down

0 comments on commit f1dbef2

Please sign in to comment.