Skip to content
docsv0.1.0

LlmService

Dual-provider LLM client (OpenAI + Anthropic chat-completions), translating each provider's tool-call wire format to and from a single OpenAI-shaped message array.

LlmService::__construct()

public function __construct(string $apiKey, string $model = 'gpt-4o', string $provider = 'openai', ?Psr\Log\LoggerInterface $logger = null):

Parameters

Parameters of __construct()
NameTypeDescription
$apiKeystring
$modelstring
$providerstring
$logger?Psr\Log\LoggerInterface

LlmService::generateResponse()

public function generateResponse(string $prompt, array $tools = [], array $messages = [], int $maxTokens = 4096): array

Send a prompt (or a full message history) to the configured provider and return a single OpenAI-shaped assistant message, translating request and response tool-call formats to and from Anthropic's shape when needed.

Parameters

Parameters of generateResponse()
NameTypeDescription
$promptstring
$toolslist<array<string, mixed>>Tool summaries in MCP/OpenAI shape (`name`, `description`, `inputSchema`)
$messageslist<array<string, mixed>>Full conversation so far; when empty, a single `user` message is built from `$prompt`
$maxTokensint

Returns

An OpenAI-shaped assistant message (`role`, `content`, and optionally `tool_calls`)