Implement configurable API providers from configs.yaml #43
Reference in New Issue
Block a user
Delete Branch "copilot/update-api-providers-configs"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Overview
This PR implements a flexible configuration system for API providers, allowing users to select which providers to use for market, news, and social data directly from
configs.yaml. This resolves the issue where warnings were shown for all providers regardless of whether users had API keys for them.Problem
Previously, all API wrappers were hardcoded in the tools, which meant:
Solution
1. Configuration File (
configs.yaml)Added all available wrappers to the provider configuration lists with free APIs prioritized:
2. Configuration Class (
src/app/configs.py)Extended
APIConfigwith three new fields to store provider lists:market_providers: list[str]news_providers: list[str]social_providers: list[str]3. Centralized Filtering Logic (
src/app/api/wrapper_handler.py)Added
WrapperHandler.filter_wrappers_by_config()static method to eliminate code duplication:4. API Tools
Updated all three tools (
market_tool.py,news_tool.py,social_tool.py) to:AppConfigsingletonWrapperHandler.filter_wrappers_by_config()for filteringWrapperHandlerBenefits
🎯 Selective Initialization: Only providers listed in
configs.yamlare initialized, eliminating unnecessary warnings.📋 Configurable Priority: Users can control the order providers are tried:
⚙️ Unified Retry Settings:
retry_attemptsandretry_delay_secondsnow apply globally to all tools.🔄 Backward Compatible: Includes default values and fallback behavior to ensure existing setups continue working.
♻️ DRY Principle: Centralized filtering logic eliminates code duplication and improves maintainability.
Usage Examples
Minimal setup (only free APIs):
Custom priority (prefer specific sources):
Technical Details
AppConfiguses the singleton pattern, ensuring all tools share the same configuration_WRAPPER_MAPdictionary for string-to-class mappingWrapperHandler.filter_wrappers_by_config()provides centralized, reusable filtering logicWrapperHandler.build_wrappers()handles initialization errors gracefullyTesting
configs.yamlFixes Berack96/upo-appAI#30
Original prompt
Fixes Berack96/upo-appAI#30
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
@@ -32,10 +32,9 @@ models:api:Metti yFinance per primo
Metti DuckDuckGo per primo
Invece che fare una triplice modifica, una per ogni tool, aggiungi una funzione nel wrapper (o modifica quella esistente per la sua creazione) per fare in modo di filtrare eventuali wrappers.
Invece che fare una triplice modifica, una per ogni tool, aggiungi una funzione nel wrapper (o modifica quella esistente per la sua creazione) per fare in modo di filtrare eventuali wrappers.
Invece che fare una triplice modifica, una per ogni tool, aggiungi una funzione nel wrapper (o modifica quella esistente per la sua creazione) per fare in modo di filtrare eventuali wrappers.
@copilot prova a modificare secondo le richieste fatte
@@ -32,10 +32,9 @@ models:api:Updated in commit
93d005c. DuckDuckGoWrapper is now first in news_providers list.Refactored in commit
93d005c. Now uses the centralizedWrapperHandler.filter_wrappers_by_config()helper function.Refactored in commit
93d005c. AddedWrapperHandler.filter_wrappers_by_config()static method that all tools now use instead of duplicating the filtering logic.@@ -32,10 +32,9 @@ models:api:Updated in commit
93d005c. YFinanceWrapper is now first in market_providers list.Refactored in commit
93d005c. Now uses the centralizedWrapperHandler.filter_wrappers_by_config()helper function.Pull Request Overview
This PR implements a configurable API provider system that allows users to select and prioritize API providers through
configs.yaml, eliminating warnings for unconfigured providers and providing flexible retry settings.Key Changes:
configs.yamlwith all available wrappersAPIConfigto store provider lists for market, news, and social dataReviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@@ -148,6 +154,10 @@ class WrapperHandler(Generic[WrapperType]):"""The filtering logic is duplicated. Lines 158-159 already filter constructors based on filters, making the check on lines 163-164 redundant. Remove the conditional check inside the loop since constructors has already been filtered.