Download the PHP package tivins/llm-php without Composer

On this page you can find all versions of the php package tivins/llm-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package llm-php

Language: English

llm-php (tivins/llm-php)

Version: 1.21.1 (see CHANGELOG.md).

PHP client library for an OpenAI-compatible HTTP API—typically llama.cpp llama-server—covering POST /v1/chat/completions (non-stream and SSE stream), plus /health, /tokenize, and model discovery via GET /v1/models.

In this README: Install


Installation

Package

Requires: ext-curl.

llama.cpp server

Models

Use a GGUF checkpoint sized for your GPU/RAM; exact limits depend on quantization and context. The library does not download models—it only talks to a running server.

If you have a GPU with 8–16GB of VRAM, you can try these models:


Quick start

Prerequisite: start llama-server and keep it running so the PHP client can reach its OpenAI-compatible HTTP API. Example (adjust the GGUF path and port):

The snippet below assumes the default listen address http://127.0.0.1:8080.

From the repository root after composer install:

Lama::fromServerUrl() picks the first model id from /v1/models. Check $lama->isHealthy() returns true before relying on the server.

Sampling and generation knobs (temperature, top_p, max_tokens, penalties, seed, stop, n, tools, tool_choice) go through Tivins\Llama\ChatCompletionOptions: only properties you set are merged into the JSON body; omitted keys leave server defaults.


API surface: chat() vs chatCompletions() vs chatStream()

Method Input → output Preserved Lost or narrowed
Tivins\Llama\Lama::chat() Conversation + optional ChatCompletionOptions → string Final assistant content from choices[0].message (empty string if missing) tool_calls, native reasoning_content, usage, additional choices, full wire JSON
Tivins\Llama\Lama::chatCompletions() Same → decoded JSON array (choices, usage, …) Everything the server returns in that response body Nothing by the library—you inspect the array
Tivins\Llama\Lama::chatStream() Same + stream callbacks + optional Tivins\Llama\SsePayloadCapture → Tivins\Llama\StreamResult Aggregated content, reasoning_content (when streamed), reconstructed tool_calls, finish_reason; usage, model, id when present on stream chunks (otherwise null) Per-chunk raw JSON unless you capture SSE payloads; shape of usage is backend-specific

Fidelity path: use chatCompletions() and/or chatStream(), then map results into your own structures or into Tivins\Llama\Dto\NormalizedTurnOutcome (fromChatCompletionArray() / fromStreamResult()) for a single aggregate shape across modes.

Shortcut: chat() is documented in code as a thin wrapper around chatCompletions(); it is fine for plain text, not for tools or native reasoning traces.


Module map (src/Tivins/Llama/)

Client

Conversation model

Request options

Tools

DTOs and audit

Streaming aggregation

Console rendering

Higher-level helpers (optional)


Examples

Location: examples/. Scripts use:

Run from the repository root (so vendor/ resolves), with llama-server listening where the script expects (many examples use http://127.0.0.1:8080):

Additional demos include chat_tools.php, mediation.php, moderation.php, exemples.php, etc. Prefer reading each file’s header comment for prerequisites (e.g. patch on PATH for workspace_tools_demo.php).

Shared helpers: examples/_helpers.php (print_output(), JSONL helpers, render env parsing). Optional defaults: examples/.env (loaded without overriding variables already in the process environment).


Environment variables

Values are read via getenv() / putenv() in library or example code as documented below. Do not enable logging if completions could contain secrets.

Examples / console (examples/_helpers.php, examples/.env)

Variable Effect
TIVINS_LLAMA_CONVERSATION_LOG Path to a JSONL file; TurnJsonlLogger appends one line per logical turn when examples wire logging (TurnRecord::toLogArray()). Use {session} in the path for a per-process segment (new file each CLI run).
TIVINS_LLAMA_NO_ANSI Truthy (1, true, yes, on): disable ANSI in HumanTurnRenderer / HumanTurnStreamDisplay.
TIVINS_LLAMA_REASONING_STDOUT Truthy: print reasoning on stdout instead of stderr.
TIVINS_LLAMA_COMPLETION_DUMP_RAW Truthy: print_output() uses legacy verbose debug instead of HumanTurnRenderer.

example_load_examples_env_file() reads examples/.env only for keys not already set in the environment.

HTTP/TLS for tool traffic (PredefinedTools, e.g. web_search / fetch_web_page)

Variable Effect
TIVINS_LLAMA_HTTP_SSL_VERIFY 0 / false / no / off disables TLS verification (insecure; dev only).

With verification enabled, PredefinedTools sets CURLSSLOPT_NATIVE_CA when PHP 8.2+ provides it (OS trust store). On older PHP, configure curl.cainfo in php.ini if HTTPS tool calls fail.

Programmatic override: PredefinedTools::setHttpSslVerifyPeer() (documented on the class).

LangSearch web search (langsearch_web_search)

Variable Effect
TIVINS_LLAMA_LANGSEARCH_API_KEY Bearer token for LangSearch Web Search API (https://api.langsearch.com/v1/web-search). Required to use langsearch_web_search; DuckDuckGo web_search needs no key.

Programmatic override: PredefinedTools::setLangSearchApiKey(). Per PHP process, LangSearchRateLimiter enforces QPS 1, QPM 60, QPD 1000; when a per-minute or per-day quota is exhausted, further LangSearch tool calls in that session return a structured error with fallback_tool: web_search.


Tests

PHPUnit 11 (composer install then):

Unit tests live under tests/Unit/ (no live LLM server). Integration tests under tests/Integration/ (filesystem tools, git, optional network for web_search / fetch_web_page — group network).

Fixtures: tests/fixtures/.

Interactive / diagnostic:


Conversation logging and modern message fields

Use this overview to wire audit logs, replay, and native reasoning without re-reading every subsection; details are in the linked sections.

Message and constructor compatibility

Tool-calling loops (behavior change)

JSONL audit and replay

Normalized view and console

Contributor-facing implementation history for these features lives in CHANGELOG.md (releases 1.14.0 through 1.20.x) and in the sections above.


JSONL audit logs (TurnJsonlLogger / TurnRecord)

Treat log files as sensitive if they can contain user data or downstream secrets.


Console output (HumanTurnRenderer / HumanTurnStreamDisplay)


Pitfalls and limits


License

MIT — see composer.json.


All versions of llm-php with dependencies

PHP Build Version
Package Version
Requires ext-curl Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tivins/llm-php contains the following files

Loading the files please wait ...