Baseline snapshot of custom AI implementation before Laravel AI SDK migration. Includes: - Custom services: GeminiTextGenerationService, TextGenerationService (OpenAI), ImageGenerationService, AudioGenerationService, VideoGenerationService - IntentDetector for content moderation via keyword matching - AI enums: Intent, Orientation, UsageType - Blade prompt templates: system.blade.php, image.blade.php, video.blade.php - AiMessage with content_html accessor (markdown rendering) - AiUsageLog for monthly quota tracking per account - PostAssistantController with regex-based [GENERATE_*] parsing - WritingAssistantTab with markdown rendering, add-to-post, attachments - Workspace brand fields (name, description, tone, voice_notes) in system prompt - Session state block injected into prompts (thread counts, quota remaining) - AttachmentCollector pattern will replace the regex approach in Phase 2 - Post comments with replies, emoji reactions, real-time via Echo - Assets page with Unsplash + Giphy integrations
59 lines
1.3 KiB
PHP
59 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\AiMessageFactory;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Str;
|
|
|
|
class AiMessage extends Model
|
|
{
|
|
/** @use HasFactory<AiMessageFactory> */
|
|
use HasFactory, HasUuids;
|
|
|
|
protected $fillable = [
|
|
'post_id',
|
|
'user_id',
|
|
'role',
|
|
'content',
|
|
'attachments',
|
|
'metadata',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'attachments' => 'array',
|
|
'metadata' => 'array',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
protected $appends = ['content_html'];
|
|
|
|
protected function contentHtml(): Attribute
|
|
{
|
|
return Attribute::get(fn () => $this->role === 'assistant' && $this->content
|
|
? Str::markdown($this->content)
|
|
: null
|
|
);
|
|
}
|
|
|
|
public function post(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Post::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
}
|