AI Integration

Laratic provides some usefull AI integrations to help you get started with implementing AI in your application. We are using Prism PHP to power our AI integrations.

Requirements

To use the AI integrations, ensure the following:

  • Prism PHP is installed, please refer to the Prism PHP documentation for installation instructions.
  • OpenAI API key is set in your .env file:
    OPENAI_API_KEY=your-openai-api-key
    

Queue Setup

AI operations are resource-intensive and run as background jobs in a queue to avoid blocking the web request. The AI chat and blog generation use the ai queue for streaming responses.

To start processing the queue, run:

php artisan queue:work --queue=ai

For more details on queue configuration for specific features, see the individual feature documentation.

Features

References

Category Path / Name Description
Routes GET /ai-simple (ai.simple) -
Routes GET /ai-chat (ai.chat) -
Controller AiController Returns AI pages. Entry point for AI routes.
Model Models\AiUsage Model for AI usage tracking and cost calculation.
Livewire Livewire\AiSimple Controls a simple AI request
Livewire Livewire\AiChat Controlls AI chat streaming
Helpers Helpers/ai_helpers.php Helper functions for AI usage tracking and cost calculation.
Jobs Jobs/StreamAiReply.php Job for streaming AI replies.
Migrations create_ai_usages_table Migration for AI usage tracking and cost calculation.
Views pages/ai-simple.blade.php Page used by /ai-simple route.
Views pages/ai-chat.blade.php Page used by /ai-chat route.
JavaScript js/chat.js Some frontend logic + highlight for the chat component.
Tests Feature/AiSimpleTest.php Tests for the AiSimple component.