<?php
use Cognesy\Http\Creation\HttpClientBuilder;
use Cognesy\Http\Config\HttpClientConfig;
use Cognesy\Messages\Messages;
use Cognesy\Polyglot\Inference\Config\LLMConfig;
use Cognesy\Polyglot\Inference\Inference;
use Cognesy\Polyglot\Inference\InferenceRuntime;
$httpClient = (new HttpClientBuilder())
->withConfig(new HttpClientConfig(
connectTimeout: 5,
requestTimeout: 60,
idleTimeout: 120,
failOnError: true,
))
->create();
$runtime = InferenceRuntime::fromConfig(
config: new LLMConfig(
driver: 'openai',
apiUrl: 'https://api.openai.com/v1',
apiKey: (string) getenv('OPENAI_API_KEY'),
endpoint: '/chat/completions',
model: 'gpt-4.1-nano',
),
httpClient: $httpClient,
);
$text = Inference::fromRuntime($runtime)
->withMessages(Messages::fromString('Say hello.'))
->get();
// @doctest id="1942"