{"id":14964484,"url":"https://github.com/ardagnsrn/ollama-php","last_synced_at":"2025-05-16T09:02:48.705Z","repository":{"id":253012239,"uuid":"842172402","full_name":"ArdaGnsrn/ollama-php","owner":"ArdaGnsrn","description":"This is a PHP library for Ollama. Ollama is an open-source project that serves as a powerful and user-friendly platform for running LLMs on your local machine. It acts as a bridge between the complexities of LLM technology and the desire for an accessible and customizable AI experience.","archived":false,"fork":false,"pushed_at":"2024-12-25T22:34:25.000Z","size":64,"stargazers_count":161,"open_issues_count":6,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-16T09:02:09.042Z","etag":null,"topics":["llama","llama3","llm","ollama","ollama-api","ollama-php","open-source-llm"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/ardagnsrn/ollama-php","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArdaGnsrn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2024-08-13T20:22:45.000Z","updated_at":"2025-05-13T05:17:16.000Z","dependencies_parsed_at":"2024-09-13T22:40:50.155Z","dependency_job_id":"3dd303e4-b8a2-4ccf-8986-253b6d4e8d29","html_url":"https://github.com/ArdaGnsrn/ollama-php","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"73fa7fe736b4a915010ced5f242ab1dc0d1bd885"},"previous_names":["ardagnsrn/ollama-php"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArdaGnsrn%2Follama-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArdaGnsrn%2Follama-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArdaGnsrn%2Follama-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArdaGnsrn%2Follama-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArdaGnsrn","download_url":"https://codeload.github.com/ArdaGnsrn/ollama-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254501555,"owners_count":22081528,"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":["llama","llama3","llm","ollama","ollama-api","ollama-php","open-source-llm"],"created_at":"2024-09-24T13:33:15.167Z","updated_at":"2025-05-16T09:02:48.677Z","avatar_url":"https://github.com/ArdaGnsrn.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/ardagnsrn"],"categories":[],"sub_categories":[],"readme":"Ollama PHP Library\n============\nThis is a PHP library for Ollama. Ollama is an open-source project that serves as a powerful and user-friendly platform\nfor running LLMs on your local\nmachine. It acts as a bridge between the complexities of LLM technology and the desire for an accessible and\ncustomizable AI experience.\n\u003cp align=\"left\"\u003e\n\u003ca href=\"https://packagist.org/packages/ardagnsrn/ollama-php\"\u003e\u003cimg alt=\"Total Downloads\" src=\"https://img.shields.io/packagist/dt/ardagnsrn/ollama-php\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/ardagnsrn/ollama-php\"\u003e\u003cimg alt=\"Latest Version\" src=\"https://img.shields.io/packagist/v/ardagnsrn/ollama-php\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/ardagnsrn/ollama-php\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/ardagnsrn/ollama-php\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## ☕️ Buy me a coffee\n\nWhether you use this project, have learned something from it, or just like it, please consider supporting it by buying\nme a coffee, so I can dedicate more time on open-source projects like this :)\n\n\u003ca href=\"https://www.buymeacoffee.com/ardagnsrn\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: auto !important;width: auto !important;\" \u003e\u003c/a\u003e\n\n## Table of Contents\n\n- [Get Started](#get-started)\n- [Usage](#usage)\n    - [Completions Resource](#completions-resource)\n        - [create()](#create)\n        - [createStreamed()](#createstreamed)\n    - [Chat Resource](#chat-resource)\n        - [create()](#create-1)\n        - [createStreamed()](#createstreamed-1)\n    - [Models Resource](#models-resource)\n        - [list()](#list)\n        - [show()](#show)\n        - [create()](#create-2)\n        - [createStreamed()](#createstreamed-2)\n        - [copy()](#copy)\n        - [delete()](#delete)\n        - [pull()](#pull)\n        - [pullStreamed()](#pullstreamed)\n        - [push()](#push)\n        - [pushStreamed()](#pushstreamed)\n        - [runningList()](#runninglist)\n    - [Blobs Resource](#blobs-resource)\n        - [exists()](#exists)\n        - [create()](#create-3)\n    - [Embed Resource](#embed-resource)\n        - [create()](#create-4)\n- [Testing](#testing)\n- [Changelog](#changelog)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Get Started\n\n\u003e **Requires [PHP 8.1+](https://php.net/releases/)**\\\n\u003e **Requires [Ollama](https://ollama.com/)**\n\n\u003e You can find Official Ollama documentation [here](https://github.com/ollama/ollama/blob/main/docs/api.md).\n\nFirst, install Ollama PHP via the [Composer](https://getcomposer.org/) package manager:\n\n```bash\ncomposer require ardagnsrn/ollama-php\n```\n\nThen, you can create a new Ollama client instance:\n\n```php\n// with default base URL\n$client = \\ArdaGnsrn\\Ollama\\Ollama::client();\n\n// or with custom base URL\n$client = \\ArdaGnsrn\\Ollama\\Ollama::client('http://localhost:11434');\n```\n\n## Usage\n\n### `Completions` Resource\n\n#### `create`\n\nGenerate a response for a given prompt with a provided model.\n\n```php\n$completions = $client-\u003ecompletions()-\u003ecreate([\n    'model' =\u003e 'llama3.1',\n    'prompt' =\u003e 'Once upon a time',\n]);\n\n$completions-\u003eresponse; // '...in a land far, far away...'\n\n$response-\u003etoArray(); // ['model' =\u003e 'llama3.1', 'response' =\u003e '...in a land far, far away...', ...]\n```\n\n#### `createStreamed`\n\nGenerate a response for a given prompt with a provided model and stream the response.\n\n```php\n$completions = $client-\u003ecompletions()-\u003ecreateStreamed([\n    'model' =\u003e 'llama3.1',\n    'prompt' =\u003e 'Once upon a time',\n]);\n\n\nforeach ($completions as $completion) {\n    echo $completion-\u003eresponse;\n}\n// 1. Iteration: '...in'\n// 2. Iteration: ' a'\n// 3. Iteration: ' land'\n// 4. Iteration: ' far,'\n// ...\n```\n\n### `Chat` Resource\n\n#### `create`\n\nGenerate a response for a given prompt with a provided model.\n\n```php\n$response = $client-\u003echat()-\u003ecreate([\n    'model' =\u003e 'llama3.1',\n    'messages' =\u003e [\n        ['role' =\u003e 'system', 'content' =\u003e 'You are a llama.'],\n        ['role' =\u003e 'user', 'content' =\u003e 'Hello!'],\n        ['role' =\u003e 'assistant', 'content' =\u003e 'Hi! How can I help you today?'],\n        ['role' =\u003e 'user', 'content' =\u003e 'I need help with my taxes.'],\n    ],\n]);\n\n$response-\u003emessage-\u003econtent; // 'Ah, taxes... *chew chew* Hmm, not really sure how to help with that.'\n\n$response-\u003etoArray(); // ['model' =\u003e 'llama3.1', 'message' =\u003e ['role' =\u003e 'assistant', 'content' =\u003e 'Ah, taxes...'], ...]\n```\n\nAlso, you can use the `tools` parameter to provide custom functions to the chat. **`tools` parameter can not be used\nwith `createStreamed` method.**\n\n```php\n$response = $client-\u003echat()-\u003ecreate([\n    'model' =\u003e 'llama3.1',\n    'messages' =\u003e [\n        ['role' =\u003e 'user', 'content' =\u003e 'What is the weather today in Paris?'],\n    ],\n    'tools' =\u003e [\n        [\n            'type' =\u003e 'function',\n            'function' =\u003e [\n                'name' =\u003e 'get_current_weather',\n                'description' =\u003e 'Get the current weather',\n                'parameters' =\u003e [\n                    'type' =\u003e 'object',\n                    'properties' =\u003e [\n                        'location' =\u003e [\n                            'type' =\u003e 'string',\n                            'description' =\u003e 'The location to get the weather for, e.g. San Francisco, CA',\n                        ],\n                        'format' =\u003e [\n                            'type' =\u003e 'string',\n                            'description' =\u003e 'The location to get the weather for, e.g. San Francisco, CA',\n                            'enum' =\u003e ['celsius', 'fahrenheit']\n                        ],\n                    ],\n                    'required' =\u003e ['location', 'format'],\n                ],\n            ],\n        ]\n    ]\n]);\n\n$toolCall = $response-\u003emessage-\u003etoolCalls[0];\n\n$toolCall-\u003efunction-\u003ename; // 'get_current_weather'\n$toolCall-\u003efunction-\u003earguments; // ['location' =\u003e 'Paris', 'format' =\u003e 'celsius']\n\n$response-\u003etoArray(); // ['model' =\u003e 'llama3.1', 'message' =\u003e ['role' =\u003e 'assistant', 'toolCalls' =\u003e [...]], ...]\n```\n\n#### `createStreamed`\n\nGenerate a response for a given prompt with a provided model and stream the response.\n\n```php\n$responses = $client-\u003echat()-\u003ecreateStreamed([\n    'model' =\u003e 'llama3.1',\n    'messages' =\u003e [\n        ['role' =\u003e 'system', 'content' =\u003e 'You are a llama.'],\n        ['role' =\u003e 'user', 'content' =\u003e 'Hello!'],\n        ['role' =\u003e 'assistant', 'content' =\u003e 'Hi! How can I help you today?'],\n        ['role' =\u003e 'user', 'content' =\u003e 'I need help with my taxes.'],\n    ],\n]);\n\n\nforeach ($responses as $response) {\n    echo $response-\u003emessage-\u003econtent;\n}\n// 1. Iteration: 'Ah,'\n// 2. Iteration: ' taxes'\n// 3. Iteration: '... '\n// 4. Iteration: ' *chew,'\n// ...\n```\n\n### `Models` Resource\n\n#### `list`\n\nList all available models.\n\n```php\n$response = $client-\u003emodels()-\u003elist();\n\n$response-\u003etoArray(); // ['models' =\u003e [['name' =\u003e 'llama3.1', ...], ['name' =\u003e 'llama3.1:80b', ...], ...]]\n```\n\n### `show`\n\nShow details of a specific model.\n\n```php\n$response = $client-\u003emodels()-\u003eshow('llama3.1');\n\n$response-\u003etoArray(); // ['modelfile' =\u003e '...', 'parameters' =\u003e '...', 'template' =\u003e '...']\n```\n\n### `create`\n\nCreate a new model.\n\n```php\n$response = $client-\u003emodels()-\u003ecreate([\n    'name' =\u003e 'mario',\n    'modelfile' =\u003e \"FROM llama3.1\\nSYSTEM You are mario from Super Mario Bros.\"\n]);\n\n$response-\u003estatus; // 'success'\n```\n\n### `createStreamed`\n\nCreate a new model and stream the response.\n\n```php\n$responses = $client-\u003emodels()-\u003ecreateStreamed([\n    'name' =\u003e 'mario',\n    'modelfile' =\u003e \"FROM llama3.1\\nSYSTEM You are mario from Super Mario Bros.\"\n]);\n\nforeach ($responses as $response) {\n    echo $response-\u003estatus;\n}\n```\n\n### `copy`\n\nCopy an existing model.\n\n```php\n$client-\u003emodels()-\u003ecopy('llama3.1', 'llama3.2'); // bool\n```\n\n### `delete`\n\nDelete a model.\n\n```php\n$client-\u003emodels()-\u003edelete('mario'); // bool\n```\n\n### `pull`\n\nPull a model from the Ollama server.\n\n```php\n$response = $client-\u003emodels()-\u003epull('llama3.1'); \n$response-\u003etoArray() // ['status' =\u003e 'downloading digestname', 'digest' =\u003e 'digestname', 'total' =\u003e 2142590208, 'completed' =\u003e 241970]\n```\n\n### `pullStreamed`\n\nPull a model from the Ollama server and stream the response.\n\n```php\n$responses = $client-\u003emodels()-\u003epullStreamed('llama3.1'); \n\nforeach ($responses as $response) {\n    echo $response-\u003estatus; \n}\n```\n\n### `push`\n\nPush a model to the Ollama server.\n\n```php\n$response = $client-\u003emodels()-\u003epush('llama3.1');\n$response-\u003etoArray() // ['status' =\u003e 'uploading digestname', 'digest' =\u003e 'digestname', 'total' =\u003e 2142590208]\n```\n\n### `pushStreamed`\n\nPush a model to the Ollama server and stream the response.\n\n```php\n$responses = $client-\u003emodels()-\u003epushStreamed('llama3.1');\n\nforeach ($responses as $response) {\n    echo $response-\u003estatus; \n}\n```\n\n### `runningList`\n\nList all running models.\n\n```php\n$response = $client-\u003emodels()-\u003erunningList();\n\n$response-\u003etoArray(); // ['models' =\u003e [['name' =\u003e 'llama3.1', ...], ['name' =\u003e 'llama3.1:80b', ...], ...]]\n```\n\n### `Blobs` Resource\n\n#### `exists`\n\nCheck if a blob exists.\n\n```php\n$client-\u003eblobs()-\u003eexists('blobname'); // bool\n```\n\n#### `create`\n\nCreate a new blob.\n\n```php\n$client-\u003eblobs()-\u003ecreate('blobname'); // bool\n```\n\n### `Embed` Resource\n\n#### `create`\n\nGenerate an embedding for a given text with a provided model.\n\n```php\n$response = $client-\u003eembed()-\u003ecreate([\n    'model' =\u003e 'llama3.1',\n    'input' =\u003e [\n        \"Why is the sky blue?\",\n    ]\n]);\n\n$response-\u003etoArray(); // ['model' =\u003e 'llama3.1', 'embedding' =\u003e [0.1, 0.2, ...], ...]\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Credits\n\n- [Arda GUNSUREN](https://github.com/ArdaGnsrn)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fardagnsrn%2Follama-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fardagnsrn%2Follama-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fardagnsrn%2Follama-php/lists"}