Update mcp_hub/config.py
Browse filesUpdated the nebius model for code generation. The Qwen coder model did not follow instructions
- mcp_hub/config.py +120 -120
mcp_hub/config.py
CHANGED
|
@@ -1,120 +1,120 @@
|
|
| 1 |
-
"""Configuration management for the MCP Hub project."""
|
| 2 |
-
|
| 3 |
-
import os
|
| 4 |
-
from dataclasses import dataclass
|
| 5 |
-
from dotenv import load_dotenv
|
| 6 |
-
|
| 7 |
-
# Load environment variables
|
| 8 |
-
load_dotenv()
|
| 9 |
-
|
| 10 |
-
@dataclass
|
| 11 |
-
class APIConfig:
|
| 12 |
-
"""API configuration settings."""
|
| 13 |
-
# Provider selection
|
| 14 |
-
llm_provider: str = "nebius" # Options: "nebius", "openai", "anthropic", "huggingface"
|
| 15 |
-
|
| 16 |
-
# Provider API keys
|
| 17 |
-
nebius_api_key: str = ""
|
| 18 |
-
openai_api_key: str = ""
|
| 19 |
-
anthropic_api_key: str = ""
|
| 20 |
-
huggingface_api_key: str = ""
|
| 21 |
-
|
| 22 |
-
# Other APIs
|
| 23 |
-
tavily_api_key: str = ""
|
| 24 |
-
|
| 25 |
-
# Provider URLs
|
| 26 |
-
nebius_base_url: str = "https://api.studio.nebius.com/v1/"
|
| 27 |
-
huggingface_base_url: str = "https://api-inference.huggingface.co"
|
| 28 |
-
|
| 29 |
-
# Other settings
|
| 30 |
-
current_year: str = "2025"
|
| 31 |
-
|
| 32 |
-
def __post_init__(self):
|
| 33 |
-
"""Validate required API keys based on selected provider."""
|
| 34 |
-
# Always require Tavily for search functionality
|
| 35 |
-
if not self.tavily_api_key or not self.tavily_api_key.startswith("tvly-"):
|
| 36 |
-
raise RuntimeError("A valid TAVILY_API_KEY is required in your .env file.")
|
| 37 |
-
|
| 38 |
-
# Validate LLM provider selection
|
| 39 |
-
valid_providers = ["nebius", "openai", "anthropic", "huggingface"]
|
| 40 |
-
if self.llm_provider not in valid_providers:
|
| 41 |
-
raise RuntimeError(f"LLM_PROVIDER must be one of: {', '.join(valid_providers)}")
|
| 42 |
-
|
| 43 |
-
# Validate required API key for selected provider
|
| 44 |
-
if self.llm_provider == "nebius" and not self.nebius_api_key:
|
| 45 |
-
raise RuntimeError("NEBIUS_API_KEY is required when using nebius provider.")
|
| 46 |
-
elif self.llm_provider == "openai" and not self.openai_api_key:
|
| 47 |
-
raise RuntimeError("OPENAI_API_KEY is required when using openai provider.")
|
| 48 |
-
elif self.llm_provider == "anthropic" and not self.anthropic_api_key:
|
| 49 |
-
raise RuntimeError("ANTHROPIC_API_KEY is required when using anthropic provider.")
|
| 50 |
-
elif self.llm_provider == "huggingface" and not self.huggingface_api_key:
|
| 51 |
-
raise RuntimeError("HUGGINGFACE_API_KEY is required when using huggingface provider.")
|
| 52 |
-
|
| 53 |
-
@dataclass
|
| 54 |
-
class ModelConfig:
|
| 55 |
-
"""Model configuration settings."""
|
| 56 |
-
# Default models (Nebius/HuggingFace compatible)
|
| 57 |
-
question_enhancer_model: str = "Qwen/Qwen3-4B-fast"
|
| 58 |
-
llm_processor_model: str = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
| 59 |
-
code_generator_model: str = "Qwen/
|
| 60 |
-
orchestrator_model: str = "Qwen/Qwen3-32B-fast"
|
| 61 |
-
|
| 62 |
-
def get_model_for_provider(self, task: str, provider: str) -> str:
|
| 63 |
-
"""Get appropriate model for the given task and provider."""
|
| 64 |
-
|
| 65 |
-
# Model mappings by provider
|
| 66 |
-
provider_models = {
|
| 67 |
-
"nebius": {
|
| 68 |
-
"question_enhancer": self.question_enhancer_model,
|
| 69 |
-
"llm_processor": self.llm_processor_model,
|
| 70 |
-
"code_generator": self.code_generator_model,
|
| 71 |
-
"orchestrator": self.orchestrator_model,
|
| 72 |
-
},
|
| 73 |
-
"openai": {
|
| 74 |
-
"question_enhancer": "gpt-4.1-nano",
|
| 75 |
-
"llm_processor": "gpt-4.1-nano",
|
| 76 |
-
"code_generator": "gpt-4.1",
|
| 77 |
-
"orchestrator": "gpt-4.1",
|
| 78 |
-
},
|
| 79 |
-
"anthropic": {
|
| 80 |
-
"question_enhancer": "claude-3-5-haiku-latest",#
|
| 81 |
-
"llm_processor": "claude-3-5-sonnet-latest",
|
| 82 |
-
"code_generator": "claude-sonnet-4-0",
|
| 83 |
-
"orchestrator": "claude-sonnet-4-0",
|
| 84 |
-
},
|
| 85 |
-
"huggingface": {
|
| 86 |
-
"question_enhancer": "microsoft/phi-4",
|
| 87 |
-
"llm_processor": "microsoft/phi-4",
|
| 88 |
-
"code_generator": "Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 89 |
-
"orchestrator": "microsoft/phi-4",
|
| 90 |
-
}
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
if provider not in provider_models:
|
| 94 |
-
# Fall back to default models
|
| 95 |
-
return getattr(self, f"{task}_model", self.llm_processor_model)
|
| 96 |
-
|
| 97 |
-
return provider_models[provider].get(task, provider_models[provider]["llm_processor"])
|
| 98 |
-
|
| 99 |
-
@dataclass
|
| 100 |
-
class AppConfig:
|
| 101 |
-
"""Application configuration settings."""
|
| 102 |
-
modal_app_name: str = "my-sandbox-app"
|
| 103 |
-
max_search_results: int = 2
|
| 104 |
-
max_code_generation_attempts: int = 3
|
| 105 |
-
llm_temperature: float = 0.6
|
| 106 |
-
code_gen_temperature: float = 0.1
|
| 107 |
-
|
| 108 |
-
# Create global configuration instances
|
| 109 |
-
api_config = APIConfig(
|
| 110 |
-
llm_provider=os.environ.get("LLM_PROVIDER", "nebius"),
|
| 111 |
-
nebius_api_key=os.environ.get("NEBIUS_API_KEY", ""),
|
| 112 |
-
openai_api_key=os.environ.get("OPENAI_API_KEY", ""),
|
| 113 |
-
anthropic_api_key=os.environ.get("ANTHROPIC_API_KEY", ""),
|
| 114 |
-
huggingface_api_key=os.environ.get("HUGGINGFACE_API_KEY", ""),
|
| 115 |
-
tavily_api_key=os.environ.get("TAVILY_API_KEY", ""),
|
| 116 |
-
current_year=os.environ.get("CURRENT_YEAR", "2025")
|
| 117 |
-
)
|
| 118 |
-
|
| 119 |
-
model_config = ModelConfig()
|
| 120 |
-
app_config = AppConfig()
|
|
|
|
| 1 |
+
"""Configuration management for the MCP Hub project."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from dataclasses import dataclass
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
|
| 7 |
+
# Load environment variables
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
@dataclass
|
| 11 |
+
class APIConfig:
|
| 12 |
+
"""API configuration settings."""
|
| 13 |
+
# Provider selection
|
| 14 |
+
llm_provider: str = "nebius" # Options: "nebius", "openai", "anthropic", "huggingface"
|
| 15 |
+
|
| 16 |
+
# Provider API keys
|
| 17 |
+
nebius_api_key: str = ""
|
| 18 |
+
openai_api_key: str = ""
|
| 19 |
+
anthropic_api_key: str = ""
|
| 20 |
+
huggingface_api_key: str = ""
|
| 21 |
+
|
| 22 |
+
# Other APIs
|
| 23 |
+
tavily_api_key: str = ""
|
| 24 |
+
|
| 25 |
+
# Provider URLs
|
| 26 |
+
nebius_base_url: str = "https://api.studio.nebius.com/v1/"
|
| 27 |
+
huggingface_base_url: str = "https://api-inference.huggingface.co"
|
| 28 |
+
|
| 29 |
+
# Other settings
|
| 30 |
+
current_year: str = "2025"
|
| 31 |
+
|
| 32 |
+
def __post_init__(self):
|
| 33 |
+
"""Validate required API keys based on selected provider."""
|
| 34 |
+
# Always require Tavily for search functionality
|
| 35 |
+
if not self.tavily_api_key or not self.tavily_api_key.startswith("tvly-"):
|
| 36 |
+
raise RuntimeError("A valid TAVILY_API_KEY is required in your .env file.")
|
| 37 |
+
|
| 38 |
+
# Validate LLM provider selection
|
| 39 |
+
valid_providers = ["nebius", "openai", "anthropic", "huggingface"]
|
| 40 |
+
if self.llm_provider not in valid_providers:
|
| 41 |
+
raise RuntimeError(f"LLM_PROVIDER must be one of: {', '.join(valid_providers)}")
|
| 42 |
+
|
| 43 |
+
# Validate required API key for selected provider
|
| 44 |
+
if self.llm_provider == "nebius" and not self.nebius_api_key:
|
| 45 |
+
raise RuntimeError("NEBIUS_API_KEY is required when using nebius provider.")
|
| 46 |
+
elif self.llm_provider == "openai" and not self.openai_api_key:
|
| 47 |
+
raise RuntimeError("OPENAI_API_KEY is required when using openai provider.")
|
| 48 |
+
elif self.llm_provider == "anthropic" and not self.anthropic_api_key:
|
| 49 |
+
raise RuntimeError("ANTHROPIC_API_KEY is required when using anthropic provider.")
|
| 50 |
+
elif self.llm_provider == "huggingface" and not self.huggingface_api_key:
|
| 51 |
+
raise RuntimeError("HUGGINGFACE_API_KEY is required when using huggingface provider.")
|
| 52 |
+
|
| 53 |
+
@dataclass
|
| 54 |
+
class ModelConfig:
|
| 55 |
+
"""Model configuration settings."""
|
| 56 |
+
# Default models (Nebius/HuggingFace compatible)
|
| 57 |
+
question_enhancer_model: str = "Qwen/Qwen3-4B-fast"
|
| 58 |
+
llm_processor_model: str = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
| 59 |
+
code_generator_model: str = "Qwen/Qwen3-32B-fast"
|
| 60 |
+
orchestrator_model: str = "Qwen/Qwen3-32B-fast"
|
| 61 |
+
|
| 62 |
+
def get_model_for_provider(self, task: str, provider: str) -> str:
|
| 63 |
+
"""Get appropriate model for the given task and provider."""
|
| 64 |
+
|
| 65 |
+
# Model mappings by provider
|
| 66 |
+
provider_models = {
|
| 67 |
+
"nebius": {
|
| 68 |
+
"question_enhancer": self.question_enhancer_model,
|
| 69 |
+
"llm_processor": self.llm_processor_model,
|
| 70 |
+
"code_generator": self.code_generator_model,
|
| 71 |
+
"orchestrator": self.orchestrator_model,
|
| 72 |
+
},
|
| 73 |
+
"openai": {
|
| 74 |
+
"question_enhancer": "gpt-4.1-nano",
|
| 75 |
+
"llm_processor": "gpt-4.1-nano",
|
| 76 |
+
"code_generator": "gpt-4.1",
|
| 77 |
+
"orchestrator": "gpt-4.1",
|
| 78 |
+
},
|
| 79 |
+
"anthropic": {
|
| 80 |
+
"question_enhancer": "claude-3-5-haiku-latest",#
|
| 81 |
+
"llm_processor": "claude-3-5-sonnet-latest",
|
| 82 |
+
"code_generator": "claude-sonnet-4-0",
|
| 83 |
+
"orchestrator": "claude-sonnet-4-0",
|
| 84 |
+
},
|
| 85 |
+
"huggingface": {
|
| 86 |
+
"question_enhancer": "microsoft/phi-4",
|
| 87 |
+
"llm_processor": "microsoft/phi-4",
|
| 88 |
+
"code_generator": "Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 89 |
+
"orchestrator": "microsoft/phi-4",
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
if provider not in provider_models:
|
| 94 |
+
# Fall back to default models
|
| 95 |
+
return getattr(self, f"{task}_model", self.llm_processor_model)
|
| 96 |
+
|
| 97 |
+
return provider_models[provider].get(task, provider_models[provider]["llm_processor"])
|
| 98 |
+
|
| 99 |
+
@dataclass
|
| 100 |
+
class AppConfig:
|
| 101 |
+
"""Application configuration settings."""
|
| 102 |
+
modal_app_name: str = "my-sandbox-app"
|
| 103 |
+
max_search_results: int = 2
|
| 104 |
+
max_code_generation_attempts: int = 3
|
| 105 |
+
llm_temperature: float = 0.6
|
| 106 |
+
code_gen_temperature: float = 0.1
|
| 107 |
+
|
| 108 |
+
# Create global configuration instances
|
| 109 |
+
api_config = APIConfig(
|
| 110 |
+
llm_provider=os.environ.get("LLM_PROVIDER", "nebius"),
|
| 111 |
+
nebius_api_key=os.environ.get("NEBIUS_API_KEY", ""),
|
| 112 |
+
openai_api_key=os.environ.get("OPENAI_API_KEY", ""),
|
| 113 |
+
anthropic_api_key=os.environ.get("ANTHROPIC_API_KEY", ""),
|
| 114 |
+
huggingface_api_key=os.environ.get("HUGGINGFACE_API_KEY", ""),
|
| 115 |
+
tavily_api_key=os.environ.get("TAVILY_API_KEY", ""),
|
| 116 |
+
current_year=os.environ.get("CURRENT_YEAR", "2025")
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
model_config = ModelConfig()
|
| 120 |
+
app_config = AppConfig()
|