-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Support composite arg type parsing in dspy.Tool
#8095
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
Conversation
@@ -159,3 +159,17 @@ def foo(x=100): | |||
tool = Tool(foo) | |||
assert tool.args["x"]["default"] == 100 | |||
assert not hasattr(tool.args["x"], "type") | |||
|
|||
|
|||
def test_tool_call_parses_args(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can we also add a unit test for the nested type like list[DummyModel]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call!
} | ||
} | ||
|
||
result = tool(**args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: What are the types we officially support as tool-callable for ReAct? Python primitives + Pydantic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, everything supported by typing + pydantic
LGTM, thank you @chenmoneygithub !! Thanks for the review @TomeHirata ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Currently our arg parsing cannot handle composite type like
list[MyPydanticModel]
, so we make this PR to resolve the issue.The solution is creating a pydantic wrapper with one single dummy field
value
of the arg type, and utilize pydanticmodel_validate()
to convert the LLM-generated args (json format) into the right type.