Database-Backed AI Conversations
Conversations and AI responses are stored in your database, surviving page reloads and server restarts. Query your AI history with Eloquent.
AI SDKs are great at sending messages, but terrible at having conversations. Converse Prism makes AI conversations flow as naturally as Eloquent makes database queries.
Install the package via Composer:
composer require elliottlawson/converse-prism
Update your User model trait:
use ElliottLawson\ConversePrism\Concerns\HasAIConversations;
class User extends Model
{
use HasAIConversations;
}
Start a conversation with AI:
// 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
$conversation->addPrismResponse($response->text);