- Moved chat-related controllers, resources, requests, and DTOs into their respective `Chats` namespaces. - Updated route imports to reflect new namespace structure.
36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Actions\Chats\StoreChatMessageAction;
|
|
use App\Ai\Agents\ContentWriterAgent;
|
|
use App\Ai\Agents\CreativeDirectorAgent;
|
|
use App\Data\Chats\SocialMediaPostResponseDto;
|
|
use App\Models\Chat;
|
|
|
|
readonly class SocialMediaService
|
|
{
|
|
public function __construct(
|
|
private ContentWriterAgent $contentWriterAgent,
|
|
private CreativeDirectorAgent $creativeDirectorAgent,
|
|
private StoreChatMessageAction $chatMessage,
|
|
) {}
|
|
|
|
/**
|
|
* Generate a social media post with an image.
|
|
* We are not using database transactions here because we do not want to delete the user prompt
|
|
* if any of the ai agents fails.
|
|
*/
|
|
public function generatePostWithImage(string $prompt, Chat $chat): SocialMediaPostResponseDto
|
|
{
|
|
$socialMediaResponse = $this->contentWriterAgent->forUser($chat->user)->prompt($prompt);
|
|
$postText = $socialMediaResponse->text;
|
|
|
|
// Generate image prompt via creative director agent
|
|
$imagePromptResponse = $this->creativeDirectorAgent->prompt($postText);
|
|
$imagePrompt = $imagePromptResponse->text;
|
|
|
|
return new SocialMediaPostResponseDto($socialMediaResponse->conversationId, $postText, $imagePrompt, now());
|
|
}
|
|
}
|