From b538bf8feee064dd3a829e47bc2b30cbf93f543a Mon Sep 17 00:00:00 2001 From: kushal-saha Date: Mon, 27 Apr 2026 05:04:04 +0000 Subject: [PATCH] refactor: Move post generation to SocialMediaService --- backend/app/Ai/Agents/ContentWriterAgent.php | 1 - .../app/Ai/Agents/CreativeDirectorAgent.php | 6 ++--- .../app/Data/SocialMediaPostResponseDto.php | 11 ++++++++ .../Controllers/SocialMediaPostController.php | 18 +++++-------- backend/app/Services/SocialMediaService.php | 26 +++++++++++++++++++ 5 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 backend/app/Data/SocialMediaPostResponseDto.php create mode 100644 backend/app/Services/SocialMediaService.php diff --git a/backend/app/Ai/Agents/ContentWriterAgent.php b/backend/app/Ai/Agents/ContentWriterAgent.php index 4df4c6e..9d2fa76 100644 --- a/backend/app/Ai/Agents/ContentWriterAgent.php +++ b/backend/app/Ai/Agents/ContentWriterAgent.php @@ -74,4 +74,3 @@ public function tools(): iterable return []; } } - diff --git a/backend/app/Ai/Agents/CreativeDirectorAgent.php b/backend/app/Ai/Agents/CreativeDirectorAgent.php index 8c3ede3..b01241e 100644 --- a/backend/app/Ai/Agents/CreativeDirectorAgent.php +++ b/backend/app/Ai/Agents/CreativeDirectorAgent.php @@ -22,9 +22,9 @@ class CreativeDirectorAgent implements Agent, Conversational, HasTools */ public function instructions(): Stringable|string { - return "You are a creative director. Read the following social media post and " . - "write a single, vivid, descriptive image prompt (max 30 words) for an " . - "AI image generator. The scene must be visually compelling and directly " . + return 'You are a creative director. Read the following social media post and '. + 'write a single, vivid, descriptive image prompt (max 30 words) for an '. + 'AI image generator. The scene must be visually compelling and directly '. "relevant to the post's topic. Return ONLY the image prompt — nothing else."; } diff --git a/backend/app/Data/SocialMediaPostResponseDto.php b/backend/app/Data/SocialMediaPostResponseDto.php new file mode 100644 index 0000000..952aaf2 --- /dev/null +++ b/backend/app/Data/SocialMediaPostResponseDto.php @@ -0,0 +1,11 @@ +prompt($request->input('prompt')); - $postText = $socialMediaResponse->text; - - $imagePromptResponse = $creativeDirectorAgent->prompt($postText); - $imagePrompt = $imagePromptResponse->text; - + $prompt = $request->input('prompt'); + $response = $socialMediaService->generatePostWithImage($prompt); return response()->json([ - 'post' => $postText, - 'image_prompt' => $imagePrompt, + 'post' => $response->post, + 'image_prompt' => $response->image, ]); } } diff --git a/backend/app/Services/SocialMediaService.php b/backend/app/Services/SocialMediaService.php new file mode 100644 index 0000000..3d01943 --- /dev/null +++ b/backend/app/Services/SocialMediaService.php @@ -0,0 +1,26 @@ +contentWriterAgent->prompt($prompt); + $postText = $socialMediaResponse->text; + + $imagePromptResponse = $this->creativeDirectorAgent->prompt($postText); + $imagePrompt = $imagePromptResponse->text; + + return new SocialMediaPostResponseDto($postText, $imagePrompt); + } +}