Fundamental_Analysis/backend/app/services/client_factory.py
xucheng a79efd8150 feat: Enhance configuration management with new LLM provider support and API integration
- Backend: Introduced new endpoints for LLM configuration retrieval and updates in `config.py`, allowing dynamic management of LLM provider settings.
- Updated schemas to include `AlphaEngineConfig` for better integration with the new provider.
- Frontend: Added state management for AlphaEngine API credentials in the configuration page, ensuring seamless user experience.
- Configuration files updated to reflect changes in LLM provider settings and API keys.

BREAKING CHANGE: The default LLM provider has been changed from `new_api` to `alpha_engine`, requiring updates to existing configurations.
2025-11-11 20:49:27 +08:00

61 lines
2.0 KiB
Python

"""
Unified Analysis Client Factory
Creates appropriate client based on provider type
"""
from typing import Dict, Optional
from app.services.analysis_client import AnalysisClient
from app.services.alpha_engine_client import AlphaEngineClient
def create_analysis_client(
provider: str,
config: Dict,
model: str = None
):
"""
Create an analysis client based on provider type
Args:
provider: Provider type ("openai", "gemini", "new_api", "alpha_engine")
config: Configuration dictionary containing provider-specific settings
model: Model name (optional, may be overridden by config)
Returns:
Client instance (AnalysisClient or AlphaEngineClient)
"""
if provider == "alpha_engine":
# AlphaEngine specific configuration
api_url = config.get("api_url", "")
api_key = config.get("api_key", "")
token = config.get("token", "")
user_id = config.get("user_id", 999041)
model_name = model or config.get("model", "deepseek-r1")
using_indicator = config.get("using_indicator", True)
start_time = config.get("start_time", "2024-01-01")
doc_show_type = config.get("doc_show_type", ["A001", "A002", "A003", "A004"])
simple_tracking = config.get("simple_tracking", True)
return AlphaEngineClient(
api_url=api_url,
api_key=api_key,
token=token,
user_id=user_id,
model=model_name,
using_indicator=using_indicator,
start_time=start_time,
doc_show_type=doc_show_type,
simple_tracking=simple_tracking
)
else:
# OpenAI-compatible API (openai, gemini, new_api)
api_key = config.get("api_key", "")
base_url = config.get("base_url", "")
model_name = model or config.get("model", "gemini-1.5-flash")
return AnalysisClient(
api_key=api_key,
base_url=base_url,
model=model_name
)