Skip to content

Conversation

@theihasan
Copy link
Owner

@theihasan theihasan commented May 1, 2025

In this PR I have introduced template method pattern for ai service integration. The main purpose of this architectural change for future-proof. I will add multiple llm api soon for cover letter generation that's why I have decided to implement this pattern

theihasan added 3 commits May 1, 2025 19:54
Introduce `BaseAIService`, an abstract class handling daily limits, request preparation, and error logging, as a foundation for AI-related services. Implement `OpenAIService`, extending `BaseAIService`, to integrate with OpenAI's GPT-3.5 API for dynamic, personalized cover letter generation.
Moved OpenAI macro registration to a dedicated AIServiceProvider to improve modularity and separation of concerns. Updated the provider registration in the bootstrap file and removed related logic from AppServiceProvider.
Removed AIService and replaced it with BaseAIService for better modularization. Improved error handling by centralizing logic into a `handleError` method and logging detailed exception data for debugging. Streamlined the response streaming process with logging to better track partial AI responses.
@theihasan theihasan self-assigned this May 1, 2025
@theihasan theihasan changed the title Refactor AI services and improve modularity and error handling using a template method pattern Refactor AI services and improve modularity and error handling using template method pattern May 1, 2025
$isRegeneration ? $this->feedback : null,
$previousAnswer
);
$aiService = app(BaseAIService::class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't create services like this. better use dependency injection. It will be easy to test.

final public function getChatResponse(User $user, array $jobData, callable $callback, ?string $feedback = null, ?string $previousAnswer = null): string
{
try {
Log::info('BaseAIService: Starting getChatResponse');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't log unnecessary information too much as info. Better use these as debug logs if necessary. Otherwise, your log will get full of information that might not be needed generally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants