PHPackages                             drsoft28/ollama-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. drsoft28/ollama-laravel

ActiveLibrary[API Development](/categories/api)

drsoft28/ollama-laravel
=======================

A Laravel package to interact with the Ollama API for building chat AI.

1.0.0(1y ago)03MITPHPPHP ^8.3

Since Feb 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/drsoft28/ollama-laravel)[ Packagist](https://packagist.org/packages/drsoft28/ollama-laravel)[ RSS](/packages/drsoft28-ollama-laravel/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Ollama Laravel
==============

[](#ollama-laravel)

Drsoft28/ollama-laravel is a Laravel package that provides a fluent and expressive API for interacting with the Ollama API. With this package, you can generate text, engage in chat sessions, manage models, retrieve embeddings, and much more through a convenient facade.

---

Features
--------

[](#features)

- **Generate Text:** Create responses based on a given prompt.
- **Chat:** Send and receive chat messages.
- **Model Management:** Show, copy, delete, and pull models.
- **Embeddings:** Retrieve embeddings for models.
- **Streaming Support:** Process streamed API responses using callbacks.
- **Local &amp; Running Models:** Easily list models available locally or running.
- **Custom API Calls:** Utilize the `ask` function to extend API functionality.

---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require drsoft28/ollama-laravel
```

Laravel's package auto-discovery will automatically register the service provider and facade. If you need to register them manually, add the following to the `providers` array in your `config/app.php`:

```
Drsoft28\OllamaLaravel\OllamaServiceProvider::class,
```

And add the alias for the facade to the `aliases` array:

```
'Ollama' => Drsoft28\OllamaLaravel\Facades\Ollama::class,
```

---

Configuration
-------------

[](#configuration)

Publish the configuration file with Artisan:

```
php artisan vendor:publish --provider="Drsoft28\OllamaLaravel\OllamaServiceProvider"
```

This will create a configuration file named `ollama.php` in your `config` directory. You can update the following options as needed:

- **`base_url`**: The base URL for your Ollama API (e.g., `http://localhost:11434`).
- **`model`**: The default model identifier to use.
- *Additional options* can also be configured if necessary.

---

Usage
-----

[](#usage)

This package exposes a facade that allows you to interact with the Ollama API easily.

### Using the Facade

[](#using-the-facade)

Import the facade and call methods directly on it:

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

// Generating a text response based on a prompt
$response = Ollama::prompt("Your prompt text here")
                  ->generate();

print_r($response);
```

### Overriding the Default Model

[](#overriding-the-default-model)

If you don't want to use the default model set in your configuration, you can override it by calling the `model` method on the facade. This allows you to specify a custom model for a particular call:

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

$response = Ollama::model('custom_model')
                  ->prompt("Your prompt text here")
                  ->generate();

print_r($response);
```

In this example, the `custom_model` will be used instead of the default model defined in your configuration file.

### Chat

[](#chat)

Send chat messages to the API:

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

$messages = [
    ['role' => 'user', 'content' => 'Hello, how are you?']
];

$response = Ollama::chat($messages);

print_r($response);
```

### Model Management

[](#model-management)

#### Show a Model

[](#show-a-model)

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

$response = Ollama::show('model_name', true);
print_r($response);
```

#### Copy a Model

[](#copy-a-model)

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

$response = Ollama::copy('new_model_name', 'existing_model_name');
print_r($response);
```

#### Delete a Model

[](#delete-a-model)

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

$response = Ollama::delete('model_name');
print_r($response);
```

#### Pull a Model

[](#pull-a-model)

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

$response = Ollama::pull('model_name', true);
print_r($response);
```

### Retrieve Embeddings

[](#retrieve-embeddings)

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

$response = Ollama::embeddings('model_name');
print_r($response);
```

### Listing Models

[](#listing-models)

#### Local Models

[](#local-models)

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

$localModels = Ollama::getLocalModels();
print_r($localModels);
```

#### Running Models

[](#running-models)

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

$runningModels = Ollama::getRunningModels();
print_r($runningModels);
```

### Handling Streaming Responses

[](#handling-streaming-responses)

If you need to process responses as they stream in, you can register a callback:

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

Ollama::callback(function($data, $rawJson) {
    // Process each chunk of data as it arrives
    echo "Received chunk: " . print_r($data, true) . "\n";
});

$response = Ollama::prompt("Streaming prompt")
                  ->generate();
```

---

Custom API Calls with the `ask` Function
----------------------------------------

[](#custom-api-calls-with-the-ask-function)

The `ask` function is a standard internal method that underlies all API interactions within the package. It handles sending HTTP requests to specified endpoints using a provided HTTP method and body data from the options. This function is flexible enough to allow you to extend the package's functionality by calling additional API endpoints that are not explicitly defined in the package.

You can pass custom body data via the `options` method and then invoke the `ask` function to target any API endpoint. For example, if you have an endpoint `/api/custom` that requires additional parameters, you can make a custom call like this:

```
use Drsoft28\OllamaLaravel\Facades\Ollama;

$response = Ollama::options([
    'custom_data' => 'Your custom data here',
])
->ask('POST', '/api/custom');

print_r($response);
```

This approach allows you to fill in the necessary data for any custom API call while leveraging the built-in functionality for handling requests and responses. The `ask` function merges your provided options with the required API parameters and sends a JSON request to the target endpoint. It supports both synchronous and streaming responses, with optional callback handling if streaming is enabled.

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please fork the repository and submit pull requests. For major changes, open an issue first to discuss your ideas.

---

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

---

Support
-------

[](#support)

If you encounter any issues or have feature requests, please open an issue in the repository.

Enjoy using Drsoft28/Ollama Laravel, and happy coding!

###  Health Score

27

—

LowBetter than 46% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

561d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b3b320ca3b9d89ad96eeb5595814dbf547e3316f7779113c959a311f69fd3694?d=identicon)[drsoft](/maintainers/drsoft)

---

Top Contributors

[![drsoft28](https://avatars.githubusercontent.com/u/11458383?v=4)](https://github.com/drsoft28 "drsoft28 (4 commits)")

### Embed Badge

![Health badge](/badges/drsoft28-ollama-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/drsoft28-ollama-laravel/health.svg)](https://phpackages.com/packages/drsoft28-ollama-laravel)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.3M49](/packages/tencentcloud-tencentcloud-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

353.6k](/packages/eslazarev-wildberries-sdk)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k832.6k55](/packages/neuron-core-neuron-ai)[files.com/files-php-sdk

Files.com PHP SDK

2482.9k](/packages/filescom-files-php-sdk)[volcengine/volcengine-php-sdk

119.5k](/packages/volcengine-volcengine-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
