elliottlawson/converse-prism

Seamless integration between Laravel Converse and Prism PHP for AI conversations


README

Converse Prism Logo


Tests Latest Stable Version Total Downloads License


Converse Prism - Seamless AI Integration for Laravel Converse

Managing conversation context is hard. Managing AI provider APIs is harder. Doing both is a nightmare.

Converse Prism bridges Laravel Converse with Prism PHP to make AI conversations effortless. Write $conversation->toPrismText() and your entire conversation history flows to any AI providerโ€”OpenAI, Anthropic, Google, or beyond. No manual message formatting. No provider lock-in. Just conversations that work.

๐Ÿ“š Documentation

View the full documentation - Comprehensive guides, API reference, and examples.

The Magic

Without Converse Prism, you're juggling two complex systems:

// Extract messages from Converse ๐Ÿ˜“
$messages = [];
foreach ($conversation->messages as $message) {
    $messages[] = [
        'role' => $message->role,
        'content' => $message->content
    ];
}

// Manually configure Prism
$prism = Prism::text()
    ->using(Provider::OpenAI, 'gpt-4')
    ->withMessages($messages)
    ->withMaxTokens(500);

// Make the call
$response = $prism->generate();

// Figure out metadata storage...
$conversation->messages()->create([
    'role' => 'assistant',
    'content' => $response->text,
    // What about tokens? Model info? ๐Ÿคท
]);

With Converse Prism, it's seamless:

// Everything flows automatically โœจ
$response = $conversation
    ->toPrismText()
    ->using(Provider::OpenAI, 'gpt-4')
    ->withMaxTokens(500)
    ->asText();

// Store response with all metadata
$conversation->addPrismResponse($response->text);

That's it. Your conversation history becomes your AI context. Automatically.

Features

  • ๐Ÿ”„ Automatic Message Passing - Conversation history flows to AI providers without manual formatting
  • ๐ŸŽฏ Direct Prism Integration - First-class support for all Prism features and providers
  • ๐ŸŒŠ Elegant Streaming - Real-time responses with automatic chunk collection and storage
  • ๐Ÿ› ๏ธ Tool & Function Support - Handle complex AI workflows with automatic message type management
  • ๐Ÿ“Š Complete Metadata - Token counts, model info, and response metadata stored automatically
  • ๐Ÿš€ Drop-in Enhancement - Works with all existing Converse code, just adds Prism superpowers

Installation

composer require elliottlawson/converse-prism

The Prism package will be installed automatically. Run the migrations:

php artisan migrate

Quick Start

Update your User model to use the Converse Prism trait:

use ElliottLawson\ConversePrism\Concerns\HasAIConversations;

class User extends Authenticatable
{
    use HasAIConversations; // Replaces the base Converse trait
}

Start having AI conversations:

use Prism\Enums\Provider;

// Build the conversation context
$conversation = $user->startConversation(['title' => 'My Chat'])
    ->addSystemMessage('You are a helpful assistant')
    ->addUserMessage('Hello! What is Laravel?');

// Make your AI call with automatic message passing
$response = $conversation
    ->toPrismText()
    ->using(Provider::OpenAI, 'gpt-4')
    ->withMaxTokens(500)
    ->asText();

// Store the AI's response with metadata
$conversation->addPrismResponse($response->text);

Requirements

  • PHP 8.2+
  • Laravel 11.0+
  • Converse ^1.0
  • Prism ^0.6

License

The MIT License (MIT). Please see License File for more information.