mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Decorator to generate schemas for tools #120
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @animaldomestico on GitHub (Jul 26, 2024).
I would like to know if there is any intention to add some sort of basic decorator to automatically generate schemas for functions we provide to the model. Examples? Maybe something like langchain has.
As you see there in the doc we can easily generate the description in JSON with that feature:
foo.args_schema.schema()
I think this is a basic feature to ask. It is very practical and useful, think about that.
Thank you.
@antoninoLorenzo commented on GitHub (Jul 26, 2024):
Man before you opened that issue I didn't knew I could use tools 💀
Maybe I am the one skipping docs, however I would like to know where/how did you find out that.
Having an actual documentation would be really good 😭
@animaldomestico commented on GitHub (Jul 26, 2024):
Yesterday ollama maintainers announced a new release that provided support for tools. They gave one example available in this repository. That is why I came here to check if there are some new features related to it. The ollama release was the reason I asked for auto generated schemas for tools, so I don't have to manually write things like:
With the feature I asked you would just:
And you are good to go...
@antoninoLorenzo commented on GitHub (Jul 26, 2024):
Ok, however I wrote some code to see how it could be done, there are still some edge cases to handle and I wrote it kind of in a rush, here it is:
Output:
@animaldomestico commented on GitHub (Jul 26, 2024):
In open webui tools.py file they just write "object":
Maybe it is for OpenAI API compatibility.
@antoninoLorenzo commented on GitHub (Jul 26, 2024):
I misinterpreted its meaning.
As shown it is simple to implement, I would enjoy working on it myself, however there are no contribution guidelines; so I think that's on the maintainers now.
@animaldomestico commented on GitHub (Jul 26, 2024):
Yes, this is very simple to implement, and there are some implementations out there that the maintainer can look into if he has any doubts, like also lanchain implementation.
Lets see what those maintainers say about that feature, if it is good or not to include something like this in this library. For me, as they are already integrating some "tools" support in this library, would be good to step ahead and add something useful like that. In my opinion download a whole framework for something so basic like that (langchain) is not interesting.
@antoninoLorenzo commented on GitHub (Jul 26, 2024):
I agree, I rarely use langchain and I do not feel comfortable using It; however It objectively provides some nice to have features (under and absurd/buggy level of abstractions)
@animaldomestico commented on GitHub (Jul 27, 2024):
Seems like someone was also interested in something related to it and provided a PR here. But one user thinks that the best approach is a third-party library.
I think I will close this issue. Thanks for your contributions @antoninoLorenzo, @synacktraa.
@synacktraa commented on GitHub (Jul 28, 2024):
I've nearly completed converting the PR into a third-party library. The library will support the registration of functions—both synchronous and asynchronous—as well as pydantic models, TypedDicts, namedtuples, and dataclasses as tools. Additionally, there will be an
infermethod that leverages litellm to interact with LLM APIs. A key advantage is that pydantic and litellm won't be bundled with the package, keeping it lightweight. Users can choose to install those dependencies separately if they need those features.@synacktraa commented on GitHub (Jul 28, 2024):
That's correct; many people find this feature unnecessary because frameworks like Langchain already exist. However, the issue is that if someone only wants to use the tool-calling feature, these frameworks are too heavy for such a simple task.