switon / llm
OpenAI-compatible LLM chat client for Switon Framework
v1.0.0
2026-08-22 14:34 UTC
Requires
- php: >=8.3
- ext-curl: *
- psr/event-dispatcher: ^1.0
- switon/ai: ^1.0
- switon/core: ^1.0
- switon/di: ^1.0
- switon/event: ^1.0
- switon/yaml: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Switon's chat client for application services that want a named model catalog, an OpenAI-compatible request, and one injected LlmInterface.
Highlights
- Named models: each entry in
~/.switon/llm.ymlis a model you can call by name. - Aliases: a short name such as
mainorfastpoints at one model. The first declaration wins. - Default model: an empty name uses the first model in the catalog.
- Chat protocols: OpenAI-compatible chat by default, and Anthropic Messages when a connection asks for it.
- Inspect and ping: list the catalog, show one model, or send a one-shot reply from the command line.
Installation
composer require switon/llm
Quick Start
use Switon\Ai\Charter; use Switon\Ai\Completion; use Switon\Ai\LlmInterface; use Switon\Ai\Message\UserMessage; use Switon\Ai\Thread; use Switon\Ai\Turn; use Switon\Ai\TurnStatus; use Switon\Core\Attribute\Autowired; class ChatService { #[Autowired] protected LlmInterface $llm; public function ask(string $text): ?string { $slot = Completion::of(UserMessage::of($text)); $thread = Thread::of('chat'); $thread->turns[] = Turn::of('ask', [$slot], TurnStatus::Running, $this->llm->model()->id); return $this->llm->complete($thread, Charter::of())->output?->text(); } }
Docs: https://github.com/switon-php/llm/blob/main/docs/README.md
License
MIT.