Skip to content

Text

Generate text directly using Prism's text generation API without agents.

Prism Reference

Atlas text generation wraps Prism's text API. For detailed documentation including all options, see Prism Text Generation.

Basic Usage

php
use Atlasphp\Atlas\Atlas;

$response = Atlas::text()
    ->using('openai', 'gpt-4o')
    ->withSystemPrompt('You are a helpful assistant.')
    ->withPrompt('What is Laravel?')
    ->asText();

echo $response->text;

With Options

php
$response = Atlas::text()
    ->using('anthropic', 'claude-sonnet-4-20250514')
    ->withSystemPrompt('You are a technical writer.')
    ->withPrompt('Explain dependency injection in PHP.')
    ->withMaxTokens(1000)
    ->withTemperature(0.7)
    ->asText();

With Messages

php
$response = Atlas::text()
    ->using('openai', 'gpt-4o')
    ->withMessages([
        ['role' => 'user', 'content' => 'Hello!'],
        ['role' => 'assistant', 'content' => 'Hi there! How can I help?'],
        ['role' => 'user', 'content' => 'What is PHP?'],
    ])
    ->asText();

Pipeline Hooks

Text generation supports pipeline middleware for observability:

PipelineTrigger
text.before_textBefore text generation
text.after_textAfter text generation
php
use Atlasphp\Atlas\Contracts\PipelineContract;

class LogTextGeneration implements PipelineContract
{
    public function handle(mixed $data, Closure $next): mixed
    {
        $result = $next($data);

        Log::info('Text generated', [
            'user_id' => $data['metadata']['user_id'] ?? null,
        ]);

        return $result;
    }
}

$registry->register('text.after_text', LogTextGeneration::class);

Next Steps

Released under the MIT License.