This repository contains a python application, that provides a local conversational interface to an Ollama model (gemma3:4b) with built-in tool-calling capabilities.
Gemma 3:4b, is a lightweight, open model built from the same research and technology that powers Gemini 2.0 models. These are Google's most advanced, portable and responsibly developed open models yet. They are designed to run fast, directly on devices — from phones and laptops to workstations.
Gemma3 uses pythonic function calling. https://www.philschmid.de/gemma-function-calling
This is quite different approach from the OpenAI-style function calling with json schema.
You can read about pythonic function calling here: https://huggingface.co/blog/andthattoo/dria-agent-a
The script:
- Starts an interactive chat loop.
- Sends user prompts to the local Ollama API.
- Detects and executes embedded
tool_codeblocks in the model's responses. - Returns tool execution output back into the conversation.
/
├── main.py # Chat client with tool-calling logic
└── README.md # Project documentation
└── requirements.txt # Python requirements
- Python 3.11+
- Create an .env file that contains the URL where to get exchange rates
EXCHANGE_RATE_SITE=....oanda.com - Download and run Ollama locally.
- Download Gemma3 Model. Run
ollama run gemma3:4bafter installing ollama.
-
Clone this repository:
git clone https://github.com/davidmuraya/gemma3.git cd gemma3 -
(Optional) Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # on Windows use `venv\\Scripts\\activate`
-
Install dependencies:
pip install -r requirements.txt
Run the chat client:
python main.pyYou will see a prompt:
Starting chat with local model. Type 'quit' to exit.
You:
- Type your question and hit Enter.
- If the model responds with a
tool_codeblock (e.g., to callget_exchange_rate(currency='TZS', new_currency='USD')), the script will execute the code and feed the output back to the model. - Type
quit,exit, orqto end the session.
-
Conversation Loop: The script collects messages in a
messageslist and streams responses from the Ollama API. -
Function Injection: An
instruction_prompttells the model when and how to wrap code calls in atool_codeblock. -
Tool Extraction: The
extract_tool_callfunction:- Searches for a
tool_codefenced block. - Eval()
s approved helper functions (e.g.,get_exchange_rate(currency='TZS', new_currency='USD')`). - Captures and returns execution output as a
tool_outputblock.
- Searches for a
-
Second Pass: If a tool call occurred, the script appends the output to the conversation and streams a final model response.
Contributions are welcome! Feel free to open issues or submit pull requests.
- Fork the repo.
- Create a feature branch:
git checkout -b feature/your-feature - Commit your changes and push:
git push origin feature/your-feature - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
