-
Notifications
You must be signed in to change notification settings - Fork 67
Tool calls python #663
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
Merged
+1,094
−34
Merged
Tool calls python #663
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
385d11d
Refactoring
agolokoz a1c7af9
Merge branch 'main' into tool-calls-python
agolokoz 2c6de70
Refactoring
agolokoz 217888a
Add python tool calls implementation
agolokoz 389fb70
Resolve task locals when the callback runs
agolokoz ebea6ae
Fixed synchronous callback dispatch
agolokoz 31168cd
Preserve parameters that collide with BaseModel
agolokoz cc035c5
Fixed the unhashable return annotation issue
agolokoz b7d2024
Fixes
agolokoz 0bbce09
Merge branch 'main' into tool-calls-python
agolokoz 4d13e61
Serialize tool results with schema aliases
agolokoz 10a9a5d
Fixed discriminated-union description propagation.
agolokoz cedc677
Merge branch 'main' into tool-calls-python
agolokoz 9d3fae9
Add uv sync
agolokoz d81e4cb
Allow documenting fields/arguments by parsing docstrings
agolokoz 464faa8
Stop requesting the removed examples extra
agolokoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import asyncio | ||
| from typing import Annotated | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
| from uzu import ( | ||
| ChatConfig, | ||
| ChatMessage, | ||
| ChatReplyConfig, | ||
| Engine, | ||
| EngineConfig, | ||
| SamplingMethod, | ||
| SamplingPolicy, | ||
| uzu_tool_function, | ||
| ) | ||
|
|
||
|
|
||
| class Coordinate(BaseModel): | ||
| """A geographic coordinate. | ||
|
|
||
| Attributes: | ||
| latitude: Latitude in decimal degrees. | ||
| longitude: Longitude in decimal degrees. | ||
| """ | ||
|
|
||
| latitude: float | ||
| longitude: Annotated[float, "Longitude in decimal degrees."] | ||
|
|
||
|
|
||
| @uzu_tool_function(name="get_location", description="Return the current location in coordinates") | ||
| def get_current_location() -> Coordinate: | ||
| return Coordinate(latitude=51.5074, longitude=-0.1278) | ||
|
|
||
|
|
||
| @uzu_tool_function | ||
| def get_current_temperature( | ||
| latitude: float, | ||
| longitude: Annotated[float, "Longitude in decimal degrees."], | ||
| ) -> float: | ||
| """Return the temperature at the provided coordinates. | ||
|
|
||
| Args: | ||
| latitude: Latitude in decimal degrees. | ||
| longitude: This is overridden by the Annotated description. | ||
| """ | ||
| _ = latitude, longitude | ||
| return 25.0 | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| engine = await Engine.create(EngineConfig.create()) | ||
| model = await engine.model("mlx-community/Qwen3.5-9B-MLX-8bit") | ||
| if model is None: | ||
| raise RuntimeError("Model not found") | ||
|
|
||
| async for update in (await engine.download(model)).iterator(): | ||
| print(f"Download progress: {update.progress}") | ||
|
|
||
| session = await engine.chat(model, ChatConfig.create()) | ||
| await session.add_tool(get_current_location) | ||
| await session.add_tool(get_current_temperature) | ||
|
|
||
| messages = [ | ||
| ChatMessage.system().with_text("You are a helpful assistant"), | ||
| ChatMessage.user().with_text("What temperature is it now at my location?"), | ||
| ] | ||
| config = ChatReplyConfig.create().with_sampling_policy(SamplingPolicy.Custom(method=SamplingMethod.Greedy())) | ||
| replies = await session.reply(messages, config) | ||
| if replies: | ||
| message = replies[-1].message | ||
| print(f"Reasoning: {message.reasoning or ''}") | ||
| print(f"Text: {message.text or ''}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.