Text mode is the default and simplest output format, returning unstructured text from the model.
Basic Text Generation
<?php
use Cognesy\Polyglot\LLM\Inference;
use Cognesy\Polyglot\LLM\Enums\OutputMode;
$inference = new Inference();
// OutputMode::Text is the default, so you don't need to specify it
$response = $inference->create(
messages: 'What is the capital of France?',
mode: OutputMode::Text // Optional, this is the default
)->toText();
echo "Response: $response\n";
// Output: Response: The capital of France is Paris.
When to Use Text Mode
Text mode is ideal for:
- Simple question answering
- Creative content generation
- Conversational interactions
- Summaries and paraphrasing
- Any use case where structured data is not required
Text Mode Across Providers
Text mode works consistently across all providers, making it the most portable option:
<?php
use Cognesy\Polyglot\LLM\Inference;
$inference = new Inference();
// Using OpenAI
$openAIResponse = $inference->withConnection('openai')
->create(
messages: 'Write a short poem about the ocean.'
)->toText();
echo "OpenAI response:\n$openAIResponse\n\n";
// Using Anthropic
$anthropicResponse = $inference->withConnection('anthropic')
->create(
messages: 'Write a short poem about the ocean.'
)->toText();
echo "Anthropic response:\n$anthropicResponse\n\n";
// Using any other provider
// ...