-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate Configurations into a TOML File #10
Separate Configurations into a TOML File #10
Conversation
….toml, update .gitignore, and remove constants.py
Reviewer's Guide by SourceryThis pull request refactors the bot to load configurations from a TOML file instead of using environment variables and hardcoded values. This change improves maintainability and allows for easier configuration of the bot's behavior. Sequence diagram for configuration loading processsequenceDiagram
participant App
participant ConfigLoader
participant TOML
participant Pydantic
participant API
App->>ConfigLoader: Import config
ConfigLoader->>TOML: Read config.toml
TOML-->>ConfigLoader: Return config data
ConfigLoader->>Pydantic: Validate config data
Pydantic-->>ConfigLoader: Return validated Config instance
ConfigLoader->>API: Initialize models list
API-->>ConfigLoader: Return available models
ConfigLoader-->>App: Return complete config
Class diagram for the new configuration systemclassDiagram
class Config {
+bot: BotConfig
+api: APIConfig
+image_generation: ImageGenerationConfig
+commands: Dict[str, CommandConfig]
+ui: UIConfig
+resources: ResourcesConfig
+MODELS: List[str]
+validate_structure()
}
class BotConfig {
+command_prefix: str
+bot_id: str
+avatar_url: str
+commands: Dict[str, str]
+emojis: Dict[str, str]
}
class APIConfig {
+models_list_endpoint: str
+image_gen_endpoint: str
+models_refresh_interval_minutes: int
+max_timeout_seconds: int
}
class ImageGenerationConfig {
+referer: str
+fallback_model: str
+defaults: ImageGenerationDefaults
+validation: ImageGenerationValidation
}
Config --> BotConfig
Config --> APIConfig
Config --> ImageGenerationConfig
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Zingzy - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
start_time = None | ||
latencies: list = [] | ||
|
||
commands_: dict[str, str] = { | ||
"</pollinate:1223762317359976519> 🎨": """Generates AI Images based on your prompts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider using a command registry pattern to centralize command definitions and reduce string interpolation noise.
The command configuration can be simplified while maintaining flexibility. Consider using a command registry pattern:
# commands.py
class CommandRegistry:
def __init__(self, config):
self.commands = {
"pollinate": {
"id": config.bot.commands['pollinate_id'],
"emoji": "🎨",
"description": """Generates AI Images based on your prompts..."""
},
# ... other commands
}
def get_formatted_command(self, name):
cmd = self.commands[name]
return f"</{name}:{cmd['id']}> {cmd['emoji']}"
def get_description(self, name):
return self.commands[name]["description"]
# Usage in main code
cmd_registry = CommandRegistry(config)
commands_ = {
cmd_registry.get_formatted_command("pollinate"): cmd_registry.get_description("pollinate"),
# ... other commands
}
This approach:
- Reduces string interpolation noise
- Keeps configuration flexibility
- Makes command management more maintainable
- Centralizes command definitions
- Makes it easier to add new commands
This issue addresses Issue #9
Summary by Sourcery
Load bot configuration from a TOML file instead of environment variables and constants.
Build:
Chores: