{"id":31644537,"url":"https://github.com/kirillsaidov/ollama-function-calling","last_synced_at":"2026-05-09T16:02:36.609Z","repository":{"id":316541751,"uuid":"1063775842","full_name":"kirillsaidov/ollama-function-calling","owner":"kirillsaidov","description":"Ollama function calling example for dummies. ","archived":false,"fork":false,"pushed_at":"2025-09-25T07:10:47.000Z","size":6,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-07T04:57:40.742Z","etag":null,"topics":["function-calling","ollama"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kirillsaidov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-25T05:28:45.000Z","updated_at":"2025-10-04T10:39:05.000Z","dependencies_parsed_at":"2025-09-25T08:38:29.660Z","dependency_job_id":"a29b394c-9dfb-4ca1-a59d-a63117fe64eb","html_url":"https://github.com/kirillsaidov/ollama-function-calling","commit_stats":null,"previous_names":["kirillsaidov/ollama-function-calling"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kirillsaidov/ollama-function-calling","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirillsaidov%2Follama-function-calling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirillsaidov%2Follama-function-calling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirillsaidov%2Follama-function-calling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirillsaidov%2Follama-function-calling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kirillsaidov","download_url":"https://codeload.github.com/kirillsaidov/ollama-function-calling/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirillsaidov%2Follama-function-calling/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281544195,"owners_count":26519554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-29T02:00:06.901Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["function-calling","ollama"],"created_at":"2025-10-07T04:53:46.485Z","updated_at":"2025-10-29T02:12:13.571Z","avatar_url":"https://github.com/kirillsaidov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ollama Function Calling for Dummies\n\nThis is a simple, beginner-friendly example showing how to use function calling with Ollama.\n\n## What this example does\n\nThis project demonstrates the complete workflow for function calling with Ollama:\n\n1. **Create a custom function** (`get_stock_price`) that fetches real stock prices\n2. **Register the function** with Ollama so the LLM knows it exists\n3. **Handle tool calls** when the LLM decides it needs to use your function\n4. **Feed results back** to the LLM so it can generate a natural, coherent response\n5. **Avoid raw output** – the LLM explains the results instead of just dumping numbers\n\nInstead of getting a raw response like `175.42`, you get a helpful answer like *\"Apple's current stock price is $175.42 per share.\"*\n\n## Quick start\n\n### Prerequisites\n- Python 3.8+\n- Ollama installed and running\n- The `qwen3:4b-instruct` model (or modify the code for your preferred model)\n\n### Installation\n#### Clone repo\n```sh\ngit clone https://github.com/kirillsaidov/ollama-function-calling.git\ncd ollama-function-calling\n```\n#### Install dependencies\n```sh\npython3 -m venv venv\n./venv/bin/pip install -r requirements.txt\n```\n\n#### Run the example\n```sh\n./venv/bin/python main.py\n```\n\n### Try It Out\n```sh\n\u003e\u003e What's Apple's stock price?\nApple's current stock price is $252.13 per share.\n\n\u003e\u003e How much is Google trading for?\nAlphabet Inc. (GOOGL) is currently trading at 247.14 per share.\n```\n\n## How It Works\n### Step 1: First LLM Call\n- User asks a question\n- LLM analyzes if it needs external data\n- If yes, LLM returns a **tool call** instead of a final answer\n\n### Step 2: Execute Your Function\n- Your code receives the tool call\n- Executes your custom function (`get_stock_price`)\n- Captures the real-world result\n\n### Step 3: Second LLM Call\n- Tool result is added to the conversation history\n- LLM gets the complete context (original question + tool result)\n- LLM generates a natural, coherent response using the data\n\nThis ensures users get helpful explanations, not just raw data dumps!\n\n## This project structure\n\n```sh\nollama-function-calling/\n├── main.py             # Main example code\n├── README.md           # This file\n└── requirements.txt    # Dependencies\n```\n\n## Customizing for your own functions\n\nWant to add your own functions? Follow this procedure:\n\n1. **Create your function**:\n```py\ndef get_weather(city: str) -\u003e str:\n    # Your implementation here\n    return f\"Sunny, 75°F in {city}\"\n```\n\n2. **Add it to the TOOLS dictionary**:\n```py\nTOOLS_LIST = {\n    'get_stock_price': get_stock_price,\n    'get_weather': get_weather, # Add your function\n}\n```\n\n3. **Define the tool schema**:\n```py\nTOOL_SCHEMA = [\n    # ... existing stock price schema\n    {\n        'type': 'function',\n        'function': {\n            'name': 'get_weather',\n            'description': 'Get current weather for a city',\n            'parameters': {\n                'type': 'object',\n                'properties': {\n                    'city': {'type': 'string', 'description': 'City name'}\n                },\n                'required': ['city'],\n            },\n        },\n    }\n]\n```\n\nNow you can test it by running the script.\n\n## License\nUnlicense.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirillsaidov%2Follama-function-calling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkirillsaidov%2Follama-function-calling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirillsaidov%2Follama-function-calling/lists"}