The Inference class is the primary interface for making requests to LLM providers in Polyglot. It provides methods for creating and sending requests, managing connections, and processing responses.

Creating an Inference Instance

<?php
use Cognesy\Polyglot\LLM\Inference;

// Create a basic inference instance with default settings
$inference = new Inference();

// Create an inference instance with a specific connection
$inference = new Inference()->withConnection('openai');

// Use the static method for simple, one-off requests
$response = Inference::text('What is the capital of France?');

Key Methods

The Inference class provides several key methods:

  • create(): Sends a request to the LLM provider
  • withConnection(): Specifies which connection to use
  • withConfig(): Sets a custom configuration
  • withHttpClient(): Specifies a custom HTTP client
  • withDebug(): Enables or disables debug mode
  • withCachedContext(): Sets cached context for improved performance