This repo attempts at exploring function calls and paralell tool usage for the new gemini-2.0-flash-exp model as well as automate tool creation and schema convertion for other llm apis This repository demonstrates how to:
- Convert Python functions into schemas compatible with various AI APIs (e.g., OpenAI, Anthropic, and Gemini).
- Use these schemas to initialize a Gemini assistant that can handle function calls in a conversation.
- Showcase parallel function calling and schema transformations from a single list of Python functions.
Uses Google Gemini models to generate OpenAI-like schemas from Python functions.
Converts the OpenAI-like schemas generated by tool_converter.py
into Anthropic and Gemini formats.
Also provides a single generate_all_schemas(functions)
method that returns all formats at once:
{
"openai": [...],
"anthropic": [...],
"gemini": [...]
}
Demonstrates generating all schemas from a list of Python functions.
Prints Anthropic, Gemini, and OpenAI schemas.
Provides GeminiAssistant
, a class that:
- Accepts either a functions map, a list of functions, or a provided OpenAI schema.
- If given functions, it uses
ToolConverter
internally to create an OpenAI-like schema, then usesschema_converter
to convert to Gemini tools. - Initializes a Gemini model using the new Gemini 2.0 Flash experimental release.
- Handles parallel function calling automatically, making it simple to integrate and manage multiple tool invocations.
- Runs queries and automatically executes functions upon the model’s requests.
Example of using GeminiAssistant
with a list of Python functions.
Runs a user query that triggers function calls and prints the final answer.
- Python 3.9+
google-generativeai
Python package- Set the
GEMINI_API_KEY
environment variable to your Google Gemini API key.
-
Install dependencies:
pip install google-generativeai
-
Set your API key:
export GEMINI_API_KEY=your_api_key_here
-
Run
tool_generators.py
to see the generated schemas:python tool_generators.py
-
Run
main.py
to see the Gemini assistant in action:python main.py
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Google Generative AI team for the Gemini API
- Contributors and maintainers