Autogen Tool, ToolFunction, Parameters, Property schema when opt-in to using type-hinted function params #238
+373
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
😩 Problem
In the API docs for passing in
tools=
spec sequence to the chat model, the docs suggest developers hand-craft theTool
,ToolFunction
,Parameters
,Property
schema'ed docs to thetools=
arg. This is very repetitive.For example, building up this JSON is laborious, given we already have defined the tool calling function.
Improvement Proposal
I propose we can solve it by giving users an option to type hint their functions and get back an automatic schema.
The scope is:
type
typing
helpers.py
is the function name in the spec, no need to type it twicefunction
docstring is theFunction
description
, this should be a wide-spread developer habit, some possibility to inject prompts hereAnnotated
special typing formOptional
annotation or classic keyword args with default valuesbool
->"boolean"
float
->"number"
int
->"integer"
str
->"string"
Sequence
->"array"
The user expectation is:
Example
some_tool_function.tool_schema
would provide this, usable as an item intools=
listOut of Scope
Not attempting to scope creep to:
pydantic
so to not obligatepip install ollama
users to also installpydantic
(see comment in Add Tool Registry Feature #234 (comment))pip install
able library, I think the implementation is deeply coupled toollama
's_types.py
implementation. I am open to doing this implementation as a separate library if the maintainers believe this syntactic sugar is out of scope.Related