<?php
require 'examples/boot.php';
use Cognesy\Config\Dsn;
use Cognesy\Config\Env;
use Cognesy\Messages\Messages;
use Cognesy\Polyglot\Inference\Config\LLMConfig;
use Cognesy\Polyglot\Inference\Inference;
use Cognesy\Utils\Str;
$xaiApiKey = (string) Env::get('XAI_API_KEY', '');
$dsn = "driver=xai,apiUrl=https://api.x.ai/v1,endpoint=/chat/completions,apiKey={$xaiApiKey},model=grok-3";
$answer = Inference::fromConfig(LLMConfig::fromArray(Dsn::fromString($dsn)->toArray()))
->with(
messages: Messages::fromString('What is the capital of France'),
options: ['max_tokens' => 64]
)
->get();
echo "USER: What is capital of France\n";
echo "ASSISTANT: $answer\n";
assert(Str::contains($answer, 'Paris'));
?>