2026-04-16 00:06:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Database\Factories;
|
|
|
|
|
|
feat: complete AI assistant with custom services and brand config
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
2026-04-16 12:25:08 +00:00
|
|
|
use App\Enums\Ai\UsageType;
|
2026-04-16 00:06:06 +00:00
|
|
|
use App\Models\Account;
|
|
|
|
|
use App\Models\AiUsageLog;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
|
|
|
|
|
|
/** @extends Factory<AiUsageLog> */
|
|
|
|
|
class AiUsageLogFactory extends Factory
|
|
|
|
|
{
|
|
|
|
|
public function definition(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'account_id' => Account::factory(),
|
|
|
|
|
'workspace_id' => Workspace::factory(),
|
feat: complete AI assistant with custom services and brand config
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
2026-04-16 12:25:08 +00:00
|
|
|
'type' => fake()->randomElement(UsageType::cases()),
|
2026-05-03 16:44:13 +00:00
|
|
|
'provider' => fake()->randomElement(['openai', 'gemini', 'internal']),
|
2026-05-03 22:36:26 +00:00
|
|
|
'prompt_tokens' => 0,
|
|
|
|
|
'completion_tokens' => 0,
|
|
|
|
|
'total_tokens' => 0,
|
|
|
|
|
'credits' => 0,
|
2026-04-16 00:06:06 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-03 22:36:26 +00:00
|
|
|
public function template(): static
|
2026-04-16 00:06:06 +00:00
|
|
|
{
|
|
|
|
|
return $this->state(fn () => [
|
2026-05-03 22:36:26 +00:00
|
|
|
'type' => UsageType::Template,
|
2026-05-03 16:44:13 +00:00
|
|
|
'provider' => 'internal',
|
2026-04-16 00:06:06 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-03 22:36:26 +00:00
|
|
|
public function text(int $credits = 10): static
|
2026-04-16 00:06:06 +00:00
|
|
|
{
|
2026-05-03 22:36:26 +00:00
|
|
|
$tokens = $credits * 150;
|
|
|
|
|
|
2026-04-16 00:06:06 +00:00
|
|
|
return $this->state(fn () => [
|
2026-05-03 16:44:13 +00:00
|
|
|
'type' => UsageType::Text,
|
|
|
|
|
'provider' => 'openai',
|
2026-05-03 22:36:26 +00:00
|
|
|
'model' => 'gpt-5.4',
|
|
|
|
|
'prompt_tokens' => intdiv($tokens, 2),
|
|
|
|
|
'completion_tokens' => intdiv($tokens, 2),
|
|
|
|
|
'total_tokens' => $tokens,
|
|
|
|
|
'credits' => $credits,
|
2026-04-16 00:06:06 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|