API reference
Complete API reference for the TYPO3 LLM extension.
LlmServiceManager
The central service for all LLM operations.
- class LlmServiceManager
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Llm Service Manager
Orchestrates LLM providers and provides unified API access.
- chat ( array $messages, array|ChatOptions $options = []) : CompletionResponse
-
Execute a chat completion request.
- param array $messages
-
Array of message objects with 'role' and 'content' keys
- param array|ChatOptions $options
-
Optional configuration
Message Format:
$messages = [ ['role' => 'system', 'content' => 'You are a helpful assistant.'], ['role' => 'user', 'content' => 'Hello!'], ['role' => 'assistant', 'content' => 'Hi there!'], ['role' => 'user', 'content' => 'How are you?'], ];Copied!- Returns
-
CompletionResponse
- complete ( string $prompt, array|ChatOptions $options = []) : CompletionResponse
-
Simple completion from a single prompt.
- param string $prompt
-
The prompt text
- param array|ChatOptions $options
-
Optional configuration
- Returns
-
CompletionResponse
- embed ( string|array $text, array $options = []) : EmbeddingResponse
-
Generate embeddings for text.
- param string|array $text
-
Single text or array of texts
- param array $options
-
Optional configuration
- Returns
-
EmbeddingResponse
- streamChat ( array $messages, array $options = []) : Generator
-
Stream a chat completion response.
- param array $messages
-
Array of message objects
- param array $options
-
Optional configuration
- Returns
-
Generator yielding string chunks
- chatWithTools ( array $messages, array $tools, array $options = []) : CompletionResponse
-
Chat with tool/function calling capability.
- param array $messages
-
Array of message objects
- param array $tools
-
Array of tool definitions
- param array $options
-
Optional configuration
- Returns
-
CompletionResponse with potential tool calls
Feature services
CompletionService
- class CompletionService
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Feature\ Completion Service
High-level text completion with format control.
- complete ( string $prompt, array $options = []) : CompletionResponse
-
Standard text completion.
- param string $prompt
-
The prompt text
- param array $options
-
Optional configuration
- Returns
-
CompletionResponse
- completeJson ( string $prompt, array $options = []) : array
-
Completion with JSON output parsing.
- param string $prompt
-
The prompt text
- param array $options
-
Optional configuration
- Returns
-
array Parsed JSON data
- completeMarkdown ( string $prompt, array $options = []) : string
-
Completion with markdown formatting.
- param string $prompt
-
The prompt text
- param array $options
-
Optional configuration
- Returns
-
string Markdown formatted text
EmbeddingService
- class EmbeddingService
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Feature\ Embedding Service
Text-to-vector conversion with caching and similarity operations.
- embed ( string $text) : array
-
Generate embedding vector for text (cached).
- param string $text
-
The text to embed
- Returns
-
array<float> Vector representation
- embedFull ( string $text) : EmbeddingResponse
-
Generate embedding with full response metadata.
- param string $text
-
The text to embed
- Returns
-
EmbeddingResponse
- embedBatch ( array $texts) : array
-
Generate embeddings for multiple texts.
- param array $texts
-
Array of texts
- Returns
-
array<array<float>> Array of vectors
- cosineSimilarity ( array $a, array $b) : float
-
Calculate cosine similarity between two vectors.
- param array $a
-
First vector
- param array $b
-
Second vector
- Returns
-
float Similarity score (-1 to 1)
- findMostSimilar ( array $queryVector, array $candidates, int $topK = 5) : array
-
Find most similar vectors from candidates.
- param array $queryVector
-
The query vector
- param array $candidates
-
Array of candidate vectors
- param int $topK
-
Number of results to return
- Returns
-
array Sorted by similarity (highest first)
VisionService
- class VisionService
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Feature\ Vision Service
Image analysis with specialized prompts.
- generateAltText ( string $imageUrl) : string
-
Generate WCAG-compliant alt text.
- param string $imageUrl
-
URL or local path to image
- Returns
-
string Accessibility-optimized alt text
- generateTitle ( string $imageUrl) : string
-
Generate SEO-optimized image title.
- param string $imageUrl
-
URL or local path to image
- Returns
-
string SEO-friendly title
TranslationService
- class TranslationService
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Feature\ Translation Service
Language translation with quality control.
- translate ( string $text, string $targetLanguage, ?string $sourceLanguage = null, array $options = []) : TranslationResult
-
Translate text to target language.
- param string $text
-
Text to translate
- param string $targetLanguage
-
Target language code (e.g., 'de', 'fr')
- param string|null $sourceLanguage
-
Source language code (auto-detected if null)
- param array $options
-
Translation options
Options:
formality: 'formal', 'informal', 'default'domain: 'technical', 'legal', 'medical', 'general'glossary: array of term translationspreserve_formatting: bool
- Returns
-
TranslationResult
- translateBatch ( array $texts, string $targetLanguage, array $options = []) : array
-
Translate multiple texts.
- param array $texts
-
Array of texts
- param string $targetLanguage
-
Target language code
- param array $options
-
Translation options
- Returns
-
array<TranslationResult>
Domain models
CompletionResponse
EmbeddingResponse
TranslationResult
UsageStatistics
Option classes
ChatOptions
Provider interface
- interface ProviderInterface
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Provider\ Contract\ Provider Interface
Contract for LLM providers.
- interface EmbeddingCapableInterface
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Provider\ Contract\ Embedding Capable Interface
Contract for providers supporting embeddings.
- interface VisionCapableInterface
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Provider\ Contract\ Vision Capable Interface
Contract for providers supporting vision/image analysis.
Exceptions
- class ProviderException
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Provider\ Exception\ Provider Exception
Base exception for provider errors.
- class AuthenticationException
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Provider\ Exception\ Authentication Exception
Thrown when API authentication fails.
Extends \Netresearch\NrLlm\Provider\Exception\ProviderException
- class RateLimitException
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Provider\ Exception\ Rate Limit Exception
Thrown when rate limits are exceeded.
Extends \Netresearch\NrLlm\Provider\Exception\ProviderException
Events
- class BeforeRequestEvent
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Event\ Before Request Event
Dispatched before sending request to provider.