Ollama Python library 0.4 with function calling improvements
Summary
The Ollama Python library, in its 0.4 release on November 25, 2024, introduces significant enhancements, primarily enabling Python functions to be passed directly as tools to Ollama models. This update simplifies the process of integrating custom logic and external library functions, such as `requests.request`, into model interactions. The library now automatically generates JSON schema for functions by parsing Python type annotations and Google-style docstrings, eliminating the need for manual schema definition. Additionally, the 0.4 release includes full typing support across the library for improved developer experience and updated examples on its GitHub repository.
Key takeaway
For AI Engineers building applications with Ollama, this update streamlines the integration of custom logic and external APIs. You can now directly pass Python functions as tools, reducing boilerplate by eliminating manual JSON schema creation. This simplifies complex workflows, allowing your models to interact with external systems more fluidly and efficiently, enhancing the capabilities of your local LLM deployments.
Key insights
Ollama's 0.4 Python library simplifies tool integration by directly accepting Python functions and auto-generating JSON schemas.
Principles
- Automate schema generation from code.
- Integrate external functions as model tools.
Method
Define Python functions with type annotations and docstrings. Pass function references directly to `ollama.chat` via the `tools` field. Execute tool calls from the model's response.
In practice
- Use `pip install -U ollama` to upgrade.
- Annotate function parameters for schema generation.
- Pass `requests.request` for web interactions.
Topics
- Ollama Python Library
- Function Calling
- LLM Tool Use
- Python Type Hinting
- Tool Schema Generation
Code references
Best for: Machine Learning Engineer, AI Engineer, Software Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Ollama Blog.