{"id":22026982,"url":"https://github.com/clementcaton/ollamapy","last_synced_at":"2025-05-07T10:44:37.787Z","repository":{"id":207269540,"uuid":"718846942","full_name":"ClementCaton/OllamaPY","owner":"ClementCaton","description":"OllamaPY is a python library to use the ollama api.","archived":false,"fork":false,"pushed_at":"2023-11-20T21:21:52.000Z","size":13,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T09:11:19.670Z","etag":null,"topics":[],"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/ClementCaton.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":"2023-11-14T23:01:53.000Z","updated_at":"2024-02-29T05:01:07.000Z","dependencies_parsed_at":"2023-11-19T21:32:33.542Z","dependency_job_id":"80d98025-58bc-4fac-917a-f2a479901203","html_url":"https://github.com/ClementCaton/OllamaPY","commit_stats":null,"previous_names":["clementcaton/ollamapy"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClementCaton%2FOllamaPY","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClementCaton%2FOllamaPY/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClementCaton%2FOllamaPY/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClementCaton%2FOllamaPY/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ClementCaton","download_url":"https://codeload.github.com/ClementCaton/OllamaPY/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252862643,"owners_count":21815897,"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":[],"created_at":"2024-11-30T07:34:02.722Z","updated_at":"2025-05-07T10:44:37.759Z","avatar_url":"https://github.com/ClementCaton.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OllamaPY\n\nOllamaPY is a Python library I did to use the Ollama API for my own projects. Feedback is appreciated.\u003cbr\u003e\nIt's an interface, so it requires you to have Ollama running on a machine. You can download it [here](https://ollama.ai/download).\u003cbr\u003e\nIt works with Python 3.11.4 and Ollama 0.1.10.\n\n## Documentation\n\nI copied parts of the documentation from the [Ollama API documentation](https://github.com/jmorganca/ollama/blob/main/docs/api.md) to describe the functions.\n\n### Minimal examples\n- Install models\n```python\nimport ollama\n\nclient = ollama.Ollama()\n# Setting a model for your instance will pull it from the ollama model library if it is not already installed\nclient.setModel(\"llama2\")\n\n# You can check if a model is already installed\nprint(client.listLocalModels())\n```\n- Get generate text \n```python\n# This function will use the model you set for your instance\noutput = client.generate(\"Who are you ?\")\n# output is the JSON response string\nprint(output)\n\n# You can also specify another model\noutput = client.generate(\"Who are you ?\", \"mistral:7b\")\n# output is the JSON response string\nprint(output)\n```\n- Here is a way to extract the text from the JSON response\n```python\nimport json\n\ndef extract(generation:str)-\u003estr:\n    text = \"\"\n    generation = generation.split(\"\\n\")\n    for line in generation[:-1]:\n        text += json.loads(line)['response']\n    return text\n```\n\n### Fonctions\n- [generate(prompt, model)](https://github.com/jmorganca/ollama/blob/main/docs/api.md#generate-a-completion)\n    - `prompt` : String\n    - `model` (optional) : String\n    - return : String or None\n\n    Generate a response for a given prompt with a provided model.\u003cbr\u003e\n    Returns the JSON response from Ollama. If the model is not specified, it will use the model you set for your instance.\u003cbr\u003e\n    If the model specified or in your instance is invalid, or if the connection with Ollama fails, it will return None.\n\n- [createModel(modelname:str, modelfile:str)](https://github.com/jmorganca/ollama/blob/main/docs/api.md#create-a-model)\n    - `modelName` : String\n    - `modelfile` : String\n    - return : Boolean\n\n    Create a model from a [Modelfile](https://github.com/jmorganca/ollama/blob/main/docs/modelfile.md).\n    ## ! Not implemented yet !\n    Returns True if the model was created, False otherwise.\n\n- [listLocalModels()](https://github.com/jmorganca/ollama/blob/main/docs/api.md#list-local-models)\n    - return : String\n\n    It will return the JSON of the models that are available locally. If the connection with Ollama fails, it will return `None`.\u003cbr\u003e\n    You can use the extract function to get the list of models, but change `['response']` to `['models']`.\n\n- [showModelInfo(model:str=None)](https://github.com/jmorganca/ollama/blob/main/docs/api.md#show-model-information)\n    - `model` (optional) : String\n    - return : String or None\n\n    \n    Show details about a model including modelfile, template, parameters, license, and system prompt.\u003cbr\u003e\n    If the model is not specified, it will use the model you set for your instance.\u003cbr\u003e\n    If the model specified or in your instance is invalid, or if the connection with Ollama fails, it will return None.\n\n- [copyModel(modelInput:str, modelOutput:str)](https://github.com/jmorganca/ollama/blob/main/docs/api.md#copy-a-model)\n    ## ! Not implemented yet !\n\n- [deleteModel(model: str)](https://github.com/jmorganca/ollama/blob/main/docs/api.md#delete-a-model)\n    - `model` : String\n\n    Delete a model and its data.\u003cbr\u003e\n    Returns True if the model was deleted, False otherwise.\n\n- [setModel(model:str)](https://github.com/jmorganca/ollama/blob/main/docs/api.md#pull-a-model)\n    - `model` : String\n\n    Set the model for your instance. It will pull it from the ollama model library if it is not already installed.\u003cbr\u003e\n\n- [pushModel()](https://github.com/jmorganca/ollama/blob/main/docs/api.md#push-a-model)\n\n    ## ! Not implemented yet !\n\n- [embeddings(prompt:str, model:str=None, option:dict[str,any]=None)](https://github.com/jmorganca/ollama/blob/main/docs/api.md#generate-embeddings)\n    - `prompt` : String\n    - `model` (optional) : String\n    - `option` (optional) : dict[str,any]\n    - return : String or None\n\n## Installation\nCopy paste the ollama.py file in your project and import it.\u003cbr\u003e\n(don't forget to star the repo if you like it, maybe one day it'll have pip support)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclementcaton%2Follamapy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclementcaton%2Follamapy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclementcaton%2Follamapy/lists"}