Refactor(Refactoring): Refactor Services Folder#127
Merged
Mehak-Conrad merged 18 commits intomainfrom May 21, 2025
Merged
Conversation
- updated each client to use a APIKeyManager.py or LLMCallRetryHandler.py - updated each clinet to use its own respective chat_formatter - updated Deepseek and dashscope to use OpenAIClient instead of Client - optimized client_factory
- updated each client to use a APIKeyManager.py or LLMCallRetryHandler.py - updated each clinet to use its own respective chat_formatter - updated Deepseek and dashscope to use OpenAIClient instead of Client - optimized client_factory
- OpenAI, GoogleAI, Anthropic have thier own chat formatter for executing multiturn messages
…used functions from utility_functions.py
…_enum for PEP8 compliance
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Services folder to standardize LLM client interfaces, centralize utility functionality, and clean up unused code.
- Standardizes and restructures LLM clients (OpenAI, Anthropic, DeepSeek, Google AI, DashScope) with a unified interface.
- Introduces APIKeyManager and LLMCallRetryHandler for managing API key rotation and retry/backoff logic.
- Moves validation logic and consolidates chat formatters while removing redundant batch-related code.
Reviewed Changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| server/services/utils/call_retry_handler.py | Adds retry/backoff logic with API key rotation support. |
| server/services/utils/api_key_manager.py | Implements API key rotation functionality. |
| server/services/clients/* | Refactors client implementations for various LLM providers, standardizing the interface. |
| server/services/chat_formatter/* | Updates chat formatting modules for consistency with provider-specific formats. |
| server/services/clients/client_factory.py | Integrates client instantiation via a factory pattern. |
Comments suppressed due to low confidence (1)
server/services/chat_formatter/google_ai_chat_formatter.py:109
- [nitpick] The function '_should_include_chat_message' returns True when a message should be skipped, which conflicts with its name; consider renaming it to something like '_should_skip_chat_message' for clarity.
def _should_include_chat_message(self, role: ChatRole, message: str, last_user_msg: Optional[str]) -> bool:
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
AwaisKamran
reviewed
May 19, 2025
- updated model_validation logic to follow SRP - updated function and parameters name to follow conventions
… service folder structure
…atRoles for multi-turn improvement
…e to use the updated LLMConfig class
AwaisKamran
reviewed
May 20, 2025
AwaisKamran
reviewed
May 20, 2025
AwaisKamran
reviewed
May 20, 2025
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Services folder by standardizing the interfaces for various LLM clients, consolidating common utilities like APIKeyManager and LLMCallRetryHandler, and reorganizing module locations for improved clarity.
- Refactored individual LLM clients (Anthropic, OpenAI, Google AI, etc.) with a consistent interface
- Updated client factory and configuration handling to use a unified LLMConfig structure
- Adjusted import paths and removed unused code from legacy modules
Reviewed Changes
Copilot reviewed 50 out of 50 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| server/services/clients/anthropic_client.py | Implemented new AnthropicClient with standardized retry and formatting logic |
| server/services/client_factory.py | Removed old factory logic in favor of updated client instantiation using LLMConfig |
| server/services/chat_formatter/*.py | Introduced new chat formatter implementations for OpenAI, Anthropic, and Google AI using the common base formatter |
| server/scripts/* | Updated client instantiation and import paths to use the new LLMConfig |
| server/app/main.py | Updated API endpoints to validate and instantiate clients via LLMConfig |
fi5421
reviewed
May 20, 2025
fi5421
reviewed
May 20, 2025
# Conflicts: # server/app/main.py # server/scripts/generate_batch_file.py # server/utilities/batch_job.py # server/utilities/utility_functions.py
…ser message for google ai client
fi5421
approved these changes
May 21, 2025
AwaisKamran
approved these changes
May 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR corresponds to the following Refactor Services Folder
Key Changes
Radon Analysis after refactoring:
For Reviewers (Optional)