Skip to content

Commit

Permalink
chore: adapt to pydanticai 0.21 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Jan 30, 2025
1 parent 04e0dd5 commit 4871fb7
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/llmling_agent_providers/pydanticai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from pydantic_ai import messages as _messages
from pydantic_ai.messages import (
ArgsDict,
ModelMessage,
ModelRequest,
ModelRequestPart,
Expand Down Expand Up @@ -52,10 +51,7 @@ def format_part( # noqa: PLR0911
case _messages.TextPart():
return response.content
case _messages.ToolCallPart():
if isinstance(response.args, _messages.ArgsJson):
args = response.args.args_json
else:
args = str(response.args.args_dict)
args = str(response.args)
return f"Tool call: {response.tool_name}\nArgs: {args}"
case _messages.ToolReturnPart():
return f"Tool {response.tool_name} returned: {response.content}"
Expand Down Expand Up @@ -110,9 +106,7 @@ def parts_to_tool_call_info(
) -> ToolCallInfo:
"""Convert matching tool call and return parts into a ToolCallInfo."""
args = (
call_part.args.args_dict
if isinstance(call_part.args, ArgsDict)
else json.loads(call_part.args.args_json)
call_part.args if isinstance(call_part.args, dict) else json.loads(call_part.args)
)

return ToolCallInfo(
Expand Down Expand Up @@ -174,9 +168,9 @@ def convert_model_message(

case ToolCallPart():
args = (
message.args.args_dict
if isinstance(message.args, ArgsDict)
else json.loads(message.args.args_json)
message.args
if isinstance(message.args, dict)
else json.loads(message.args)
)
info = ToolCallInfo(
tool_name=message.tool_name,
Expand Down

0 comments on commit 4871fb7

Please sign in to comment.