{"id":24251502,"url":"https://github.com/chintanboghara/ollama-python-client","last_synced_at":"2026-04-16T16:09:06.131Z","repository":{"id":272391823,"uuid":"916441074","full_name":"chintanboghara/Ollama-Python-Client","owner":"chintanboghara","description":"A Python client for interacting with the Ollama API.","archived":false,"fork":false,"pushed_at":"2025-02-22T07:10:31.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-22T08:20:45.368Z","etag":null,"topics":["client","ollama","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chintanboghara.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2025-01-14T05:13:53.000Z","updated_at":"2025-02-22T07:10:35.000Z","dependencies_parsed_at":"2025-01-14T06:35:04.631Z","dependency_job_id":null,"html_url":"https://github.com/chintanboghara/Ollama-Python-Client","commit_stats":null,"previous_names":["chintanboghara/ollama-python-client"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chintanboghara%2FOllama-Python-Client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chintanboghara%2FOllama-Python-Client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chintanboghara%2FOllama-Python-Client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chintanboghara%2FOllama-Python-Client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chintanboghara","download_url":"https://codeload.github.com/chintanboghara/Ollama-Python-Client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241896610,"owners_count":20038753,"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","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":["client","ollama","python"],"created_at":"2025-01-15T02:51:29.029Z","updated_at":"2026-04-16T16:09:06.126Z","avatar_url":"https://github.com/chintanboghara.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ollama Python Client\n\n[![Python Version](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/downloads/) \u003c!-- Optional: Add relevant badges --\u003e\n\nA simple Python client demonstrating interaction with a locally running Ollama API, specifically targeting a custom assistant model.\n\nThis project provides two basic scripts to send prompts to an Ollama model and retrieve responses. It's designed as a starting point for building more complex applications using Ollama.\n\n## Features\n\n*   Simple examples for querying the Ollama API.\n*   Demonstrates basic API calls (`ollama_client.py`).\n*   Includes a refined version with error handling (`ollama_client_refined.py`).\n*   Easily configurable model name and prompt.\n*   Requires minimal dependencies.\n\n## Prerequisites\n\nBefore running the client, ensure you have the following:\n\n1.  **Python:** Version 3.8 or higher recommended.\n2.  **Ollama:** Installed and running locally. You can download it from [ollama.com](https://ollama.com/).\n3.  **Custom Model:** The specific Ollama model you intend to query (default: `custom-assistant`) must be available in your running Ollama instance. You can pull or create models using the Ollama CLI (e.g., `ollama pull \u003cmodel_name\u003e` or by defining a `Modelfile`).\n4.  **Dependencies:** Python packages listed in `requirements.txt`.\n\n## Installation\n\n1.  **Clone the repository (if you haven't already):**\n    ```bash\n    git clone https://github.com/chintanboghara/Ollama-Python-Client.git\n    cd Ollama-Python-Client\n    ```\n\n2.  **Install the required Python dependencies:**\n    ```bash\n    pip install -r requirements.txt\n    ```\n    *This typically includes libraries like `requests` or the official `ollama` Python package, depending on your implementation.*\n\n## Running the Client\n\nEnsure your Ollama service is running in the background. You can then run the example scripts:\n\n### 1. Basic Client (`ollama_client.py`)\n\nThis script provides a straightforward example of sending a prompt to the specified Ollama model and printing the response. It lacks robust error handling.\n\n```bash\npython ollama_client.py\n```\n\n### 2. Refined Client (`ollama_client_refined.py`)\n\nThis script builds upon the basic example by incorporating error handling (e.g., for connection issues or model not found errors) and provides a slightly more structured approach.\n\n```bash\npython ollama_client_refined.py\n```\n\n## Usage and Customization\n\nBoth scripts are pre-configured to query the `custom-assistant` model with the prompt \"What is Python?\".\n\n**To change the model or prompt:**\n\nEdit the relevant variables directly within the Python script files:\n\n*   **In `ollama_client.py`:**\n    ```python\n    # --- Configuration ---\n    MODEL_NAME = \"custom-assistant\"  # Replace with your target Ollama model\n    PROMPT_TEXT = \"What is Python?\"  # Replace with your desired prompt\n    OLLAMA_API_URL = \"http://localhost:11434/api/generate\" # Default API endpoint\n    # -------------------\n    ```\n\n*   **In `ollama_client_refined.py`:**\n    ```python\n    # --- Configuration ---\n    MODEL_NAME = \"custom-assistant\"  # Replace with your target Ollama model\n    PROMPT_TEXT = \"What is Python?\"  # Replace with your desired prompt\n    OLLAMA_API_URL = \"http://localhost:11434/api/generate\" # Default API endpoint\n    # -------------------\n    ```\n\n**Important:** Ensure the `MODEL_NAME` you specify corresponds to a model that exists in your running Ollama instance.\n\n## Configuration\n\n*   **Ollama API Endpoint:** The scripts assume Ollama is running on the default address (`http://localhost:11434`). If your Ollama service is running on a different host or port, you'll need to update the `OLLAMA_API_URL` variable in the scripts accordingly. The example above shows where this might be defined. *Note: Adapt the variable name and location based on your actual script implementation.*\n\n## Troubleshooting\n\n*   **ConnectionError / Connection Refused:** Ensure the Ollama application or service is running locally. Check if it's accessible on `http://localhost:11434`.\n*   **Model Not Found Error (e.g., 404 Not Found):** Verify that the model specified in the `MODEL_NAME` variable (`custom-assistant` by default) has been pulled or created in your Ollama instance. Use `ollama list` in your terminal to see available models.\n*   **Dependency Errors:** Ensure you have installed the required packages using `pip install -r requirements.txt`. Consider using a virtual environment.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchintanboghara%2Follama-python-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchintanboghara%2Follama-python-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchintanboghara%2Follama-python-client/lists"}