Download the PHP package tenqz/ollama without Composer
On this page you can find all versions of the php package tenqz/ollama. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package ollama
Ollama PHP Client Library
Documentation for version v0.6.0
About
Ollama PHP Client Library is a robust, well-designed PHP client for interacting with the Ollama API. This library allows PHP developers to easily integrate large language models (LLMs) into their applications using the Ollama server.
Features
- Clean, domain-driven architecture with clear separation of concerns
- Comprehensive Ollama API support including text generation and embeddings
- Type-safe request and response handling with full DTO support
- Text generation with advanced options (temperature, top-k, top-p, repetition penalty, and more)
- Text embeddings for semantic search, similarity, and vector operations
- Multimodal support for image inputs with base64-encoded images
- Streaming support for real-time text generation
- Flexible configuration with customizable timeouts and connection settings
- PSR standards compliance with proper interfaces and abstractions
- Comprehensive test coverage with 97+ unit tests for embeddings alone
Installation
You can install the package via composer:
Requirements
- PHP 7.2 or higher (supports PHP 8.0+ features)
- cURL extension for HTTP communication
- JSON extension for data serialization
- Ollama server running locally or remotely
Usage
Text Generation
Text Embeddings
Architecture
The library follows Domain-Driven Design principles with a clear separation of concerns across multiple layers:
Transport Layer
TransportClientInterface- Interface for HTTP clients with GET/POST methodsResponseInterface- Interface for API responses with status and data accessCurlTransportClient- cURL implementation with configurable timeouts and headersJsonResponse- JSON response implementation with data parsing
Generation Layer (Text Generation)
GenerationRequest- Request DTO with prompts, options, images, streaming, templatesGenerationOptions- Fine-grained control (temperature, top-k, top-p, repetition penalty, etc.)GenerationResponse- Response DTO with generated text and metadataGenerationClientInterface- Client interface for generation operationsOllamaGenerationClient- Implementation with error handling and response transformationGenerationException- Domain-specific exception for generation errors
Embedding Layer (Text Embeddings)
EmbeddingRequest- Request DTO with model and input textEmbeddingResponse- Response DTO with embedding vectors (supports batch processing)EmbeddingClientInterface- Client interface for embedding operationsOllamaEmbeddingClient- Implementation with error handling and vector processingEmbeddingException- Domain-specific exception for embedding errors
Shared Layer
OllamaServerConfig- Server configuration with host, port, and URL buildingOllamaApiEndpoints- API endpoint constants (/api/generate,/api/embed)- Cross-cutting concerns and utilities used across domains
Advanced Features
Generation Options
The library supports comprehensive generation options for fine-tuning model behavior:
Sampling Parameters:
temperature(0.0-1.0) - Controls randomness (higher = more creative)top_k(1-100) - Limits vocabulary diversitytop_p(0.0-1.0) - Nucleus sampling for focused responsesseed(integer) - Deterministic outputs for reproducible results
Generation Control:
num_predict(integer) - Maximum tokens to generaterepeat_penalty(float) - Penalty for repetitionstop(array) - Stop sequences to end generation
Advanced:
stream(boolean) - Real-time streaming responsesformat(string) - Output format (e.g., 'json')system(string) - System message for role definitionimages(array) - Base64-encoded images for multimodal modelskeep_alive(string/int) - Model persistence duration
Embedding Features
The Embedding layer supports:
Request Options:
model(string) - Embedding model name (e.g.,nomic-embed-text:latest)input(string) - Text to generate embeddings foroptions(array) - Additional model parameterskeep_alive(string/int) - Model persistence duration
Response Data:
embeddings(array) - Array of embedding vectors (supports batch processing)dimension(int) - Vector dimension (e.g., 768)model(string) - Model name used- Performance metrics:
total_duration,load_duration,prompt_eval_count
Methods:
getEmbedding()- Get first embedding vector (single text)getEmbeddings()- Get all embedding vectors (batch processing)getDimension()- Get vector dimensiongetCount()- Get number of embeddings
Development
The library includes comprehensive development tools:
License
The MIT License (MIT). Please see License File for more information.
All versions of ollama with dependencies
ext-curl Version *
ext-json Version *