Overview

You can provide your own LLM configuration data to Inference object with DSN string. This is useful for inline configuration or for building configuration from admin UI, CLI arguments or environment variables.

Example

<?php
require 'examples/boot.php';

use Cognesy\Polyglot\LLM\Inference;
use Cognesy\Utils\Str;

$answer = Inference
    ::fromDSN('connection=xai,model=grok-2')
    ->create(
        messages: [['role' => 'user', 'content' => 'What is the capital of France']],
        options: ['max_tokens' => 64]
    )
    ->toText();

echo "USER: What is capital of France\n";
echo "ASSISTANT: $answer\n";

assert(Str::contains($answer, 'Paris'));
?>