Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kristofferv98/gemini_paralell_tools
Universal tool schema generator and parallel function caller for Gemini 2.0 Flash experimental. Automatically converts Python functions into compatible schemas for OpenAI, Anthropic, and Google's Gemini API, with parallel function execution support.
https://github.com/kristofferv98/gemini_paralell_tools
ai-tools anthropic api-integration experimental function-calling gemini gemini-2-flash gemini-api llm-tools openai schema-generation tool-conversion
Last synced: 7 days ago
JSON representation
Universal tool schema generator and parallel function caller for Gemini 2.0 Flash experimental. Automatically converts Python functions into compatible schemas for OpenAI, Anthropic, and Google's Gemini API, with parallel function execution support.
- Host: GitHub
- URL: https://github.com/kristofferv98/gemini_paralell_tools
- Owner: kristofferv98
- License: mit
- Created: 2024-12-12T18:18:07.000Z (25 days ago)
- Default Branch: main
- Last Pushed: 2024-12-12T18:24:15.000Z (25 days ago)
- Last Synced: 2024-12-12T19:27:17.657Z (25 days ago)
- Topics: ai-tools, anthropic, api-integration, experimental, function-calling, gemini, gemini-2-flash, gemini-api, llm-tools, openai, schema-generation, tool-conversion
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Universal Tool Schema Generation and Gemini Assistant Example
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:1. Convert Python functions into schemas compatible with various AI APIs (e.g., OpenAI, Anthropic, and Gemini).
2. Use these schemas to initialize a Gemini assistant that can handle function calls in a conversation.
3. Showcase parallel function calling and schema transformations from a single list of Python functions.## Overview
### tool_converters/tool_converter.py
Uses Google Gemini models to generate OpenAI-like schemas from Python functions.### tool_converters/schema_converter.py
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:
```json
{
"openai": [...],
"anthropic": [...],
"gemini": [...]
}
```### tool_generators.py
Demonstrates generating all schemas from a list of Python functions.
Prints Anthropic, Gemini, and OpenAI schemas.### gemini_assistant.py
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 uses `schema_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.### main.py
Example of using `GeminiAssistant` with a list of Python functions.
Runs a user query that triggers function calls and prints the final answer.## Requirements
- Python 3.9+
- `google-generativeai` Python package
- Set the `GEMINI_API_KEY` environment variable to your Google Gemini API key.## Usage
1. **Install dependencies:**
```bash
pip install google-generativeai
```2. **Set your API key:**
```bash
export GEMINI_API_KEY=your_api_key_here
```3. **Run `tool_generators.py` to see the generated schemas:**
```bash
python tool_generators.py
```4. **Run `main.py` to see the Gemini assistant in action:**
```bash
python main.py
```## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
- Google Generative AI team for the Gemini API
- Contributors and maintainers