refactor: Move post generation to SocialMediaService
This commit is contained in:
parent
9c070e0f5c
commit
b538bf8fee
@ -74,4 +74,3 @@ public function tools(): iterable
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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.";
|
||||
}
|
||||
|
||||
|
||||
11
backend/app/Data/SocialMediaPostResponseDto.php
Normal file
11
backend/app/Data/SocialMediaPostResponseDto.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
class SocialMediaPostResponseDto
|
||||
{
|
||||
public function __construct(
|
||||
public string $post,
|
||||
public string $image,
|
||||
) {}
|
||||
}
|
||||
@ -2,9 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Ai\Agents\CreativeDirectorAgent;
|
||||
use App\Ai\Agents\ContentWriterAgent;
|
||||
use App\Http\Requests\SocialMediaPostRequest;
|
||||
use App\Services\SocialMediaService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class SocialMediaPostController extends Controller
|
||||
@ -14,18 +13,13 @@ class SocialMediaPostController extends Controller
|
||||
*/
|
||||
public function generate(
|
||||
SocialMediaPostRequest $request,
|
||||
ContentWriterAgent $socialMediaAgent,
|
||||
CreativeDirectorAgent $creativeDirectorAgent
|
||||
SocialMediaService $socialMediaService,
|
||||
): JsonResponse {
|
||||
$socialMediaResponse = $socialMediaAgent->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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
26
backend/app/Services/SocialMediaService.php
Normal file
26
backend/app/Services/SocialMediaService.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Ai\Agents\ContentWriterAgent;
|
||||
use App\Ai\Agents\CreativeDirectorAgent;
|
||||
use App\Data\SocialMediaPostResponseDto;
|
||||
|
||||
class SocialMediaService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ContentWriterAgent $contentWriterAgent,
|
||||
private readonly CreativeDirectorAgent $creativeDirectorAgent,
|
||||
) {}
|
||||
|
||||
public function generatePostWithImage(string $prompt): SocialMediaPostResponseDto
|
||||
{
|
||||
$socialMediaResponse = $this->contentWriterAgent->prompt($prompt);
|
||||
$postText = $socialMediaResponse->text;
|
||||
|
||||
$imagePromptResponse = $this->creativeDirectorAgent->prompt($postText);
|
||||
$imagePrompt = $imagePromptResponse->text;
|
||||
|
||||
return new SocialMediaPostResponseDto($postText, $imagePrompt);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user