elliottlawson/converse-prism
最新稳定版本:v0.2.1
Composer 安装命令:
composer require elliottlawson/converse-prism
包简介
Seamless integration between Laravel Converse and Prism PHP for AI conversations
README 文档
README
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.
统计信息
- 总下载量: 243
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-13