Download the PHP package halilcosdu/laravel-ollama without Composer
On this page you can find all versions of the php package halilcosdu/laravel-ollama. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download halilcosdu/laravel-ollama
More information about halilcosdu/laravel-ollama
Files in halilcosdu/laravel-ollama
Package laravel-ollama
Short Description Laravel Ollama API Wrapper - Interact with the Ollama API
License MIT
Homepage https://github.com/halilcosdu/laravel-ollama
Informations about the package laravel-ollama
Laravel Ollama
A fluent, Laravel-native client for running AI locally with Ollama. Generate text, build conversations, stream tokens without buffering, enforce JSON schemas, call tools, create embeddings, use vision models, and manage the models on your Ollama server.
Why Laravel Ollama?
- Fluent facade that feels natural in Laravel applications.
- First-class, memory-efficient NDJSON streaming through PHP generators.
- Structured outputs with JSON Schema for reliable application data.
- Generate, chat, vision, tool calling, embeddings, and model management.
- Hermetic test suite: normal tests never require a running Ollama instance.
- Tested across Laravel 11, 12, and 13, including PHP 8.5.
Requirements
| Package | Supported versions |
|---|---|
| PHP | 8.2–8.5 |
| Laravel | 11.x, 12.x, 13.x |
| Ollama | A reachable local or remote Ollama server |
Laravel 13 requires PHP 8.3 or newer.
Installation
Install the package:
Laravel discovers the service provider and Ollama facade automatically. Optionally publish the configuration:
Configure your application in .env:
Text generation
ask() returns the decoded Ollama response as an array when streaming is disabled:
Available generation controls include agent(), prompt(), model(), format(), options(), raw(), stream(), and keepAlive().
Token streaming
streamAsk() and streamChat() open an Ollama NDJSON stream and lazily yield each decoded chunk. The complete response is never buffered in memory, making this suitable for long answers, console commands, queues, and streamed HTTP responses.
Stream chat content:
The generator throws HalilCosdu\Ollama\Exceptions\OllamaStreamException for malformed chunks and for errors reported in the stream. Because generators are lazy, the HTTP request begins when iteration starts.
Stream directly from a Laravel route
Chat
For vision chat, place base64-encoded image data in the relevant message's images array. The image() convenience method applies to text generation through ask().
Structured outputs
Pass json or an entire JSON Schema to format(). Use stream(false) for a single, easily validated JSON response and a low temperature for consistency.
Tool calling
Your application remains responsible for validating arguments, executing approved tools, and returning tool results to the conversation.
Vision
image() validates the path and sends the file as base64 data.
Embeddings
embeddings() targets Ollama's deprecated /api/embeddings endpoint and remains available only for backward compatibility. Prefer embed().
Model management and server information
API reference
| Method | Ollama endpoint | Result |
|---|---|---|
ask() |
POST /api/generate |
Array, or raw Guzzle response with stream(true) |
streamAsk() |
POST /api/generate |
Generator yielding decoded chunks |
chat($messages) |
POST /api/chat |
Array, or raw Guzzle response with stream(true) |
streamChat($messages) |
POST /api/chat |
Generator yielding decoded chunks |
embed($input) |
POST /api/embed |
Embedding response array |
models() |
GET /api/tags |
Local models |
ps() |
GET /api/ps |
Running models |
version() |
GET /api/version |
Server version |
show() |
POST /api/show |
Model details |
pull() / push() |
POST /api/pull, /api/push |
Fluent instance |
create($modelfile) |
POST /api/create |
Fluent instance |
copy($destination) |
POST /api/copy |
Fluent instance |
delete() |
DELETE /api/delete |
Fluent instance |
Testing and quality
The default suite uses Laravel HTTP fakes and Guzzle mock streams, so it is deterministic and makes no network calls. To run the optional live smoke tests:
Changelog, contributing, and security
See security advisory page.
Credits
- Halil Cosdu
- Inspired by the original Ollama Laravel work from Cloud Studio
License
Laravel Ollama is open-source software licensed under the MIT license.
All versions of laravel-ollama with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.0