neoban/backend/app/Services/SocialMediaService.php
kushal-saha cde80dbf08 refactor(core): restructure namespaces for chat-related requests, resources, and responses
- Moved chat-related controllers, resources, requests, and DTOs into their respective `Chats` namespaces.
- Updated route imports to reflect new namespace structure.
2026-04-29 15:39:44 +00:00

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());
}
}