Download the PHP package php-graph/inference without Composer
On this page you can find all versions of the php package php-graph/inference. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package inference
Inference
This project is a PHP component designed to simplify the integration and usage of Large Language Models (LLMs) from various providers, including Ollama, OpenAI, Mistral, DeepSeek, and more. It offers a unified interface for:
- Interacting with chat models (standard completions, streaming, etc.)
- Generating vector embeddings
- Managing multi-provider compatibility without altering your application logic
The goal is to provide a simple, extensible, and developer-oriented abstraction for AI inference, enabling optimal performance and rapid integration into your PHP projects.
Get Started
First, install phpGraph Inference via the Composer package manager:
Usages
Ollama
Chat
The following example demonstrates how to use Ollama as a local LLM provider for a standard chat interaction. You instantiate a resource, build your message history, and get the assistant's response.
Chat Stream
To stream the response token-by-token (useful for chat UIs and progress feedback), instantiate the resource with
chatStreamed()
and provide a handler that processes each chunk as it arrives.
Embeddings
To generate vector embeddings with Ollama, simply use the
embed()
method on the resource and pass your text or batch of texts. The returned array contains the embedding vector(s).
OpenAI
Chat
For OpenAI's GPT models, the usage is nearly identical. After configuring your API key and provider, send your conversation history and extract the assistant's response from the returned structure.
Chat Stream
OpenAI also supports streaming chat completions. Use the streaming resource and provide a handler that is called for each streamed content delta.
Embeddings
To get high-quality embeddings from OpenAI, specify the embedding model and input texts. The response contains an array of embeddings matching the input order.
Mistral
Chat
Mistral provides OpenAI-compatible chat endpoints. Simply use your API key and the right model. The format and usage remain consistent with the other providers.
Chat Stream
Streaming responses are supported just like with OpenAI, making it easy to plug into chat UIs or progressive LLM pipelines.
Embeddings
For embeddings, use the appropriate Mistral model. The structure of the response is similar to OpenAI's, with each embedding in the
data
array.
DeepSeek
Chat
DeepSeek also exposes an OpenAI-compatible API. You can interact with it in the same way, making switching providers simple.
Chat Stream
Streaming works identically: use the streamed resource and process each chunk via your handler.
Embeddings
DeepSeek embeddings are retrieved with the same API contract. Specify the embedding model and input; parse the embeddings from the
data
array in the response.
Example :
Symfony Command
All versions of inference with dependencies
symfony/http-client-contracts Version ^3.6
symfony/http-client Version ^7.3
doctrine/collections Version ^2.3