-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
213 lines (188 loc) · 8.73 KB
/
config.py
File metadata and controls
213 lines (188 loc) · 8.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import os
import re
from datetime import timedelta
from env_loader import load_runtime_env
load_runtime_env()
def load_numbered_env_values(base_name: str) -> list[str]:
"""Load BASE_NAME plus BASE_NAME_1, BASE_NAME_2, ... in numeric order."""
values = []
direct_value = os.environ.get(base_name)
if direct_value:
values.append(direct_value)
numbered_values = []
pattern = re.compile(rf"^{re.escape(base_name)}_(\d+)$")
for key, value in os.environ.items():
match = pattern.match(key)
if match and value:
numbered_values.append((int(match.group(1)), value))
values.extend(value for _, value in sorted(numbered_values))
return values
class Config:
PROJECT_ID = os.environ.get('PROJECT_ID')
GOOGLE_APPLICATION_CREDENTIALS = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS')
LOCATION = os.environ.get('LOCATION')
ENDPOINT = os.environ.get('GOOGLE_ENDPOINT')
DEFAULT_PORT = 1400
DEFAULT_HOST = '0.0.0.0' # Listen on all interfaces
REQUEST_TIMEOUT = 30
TOKEN_REFRESH_BUFFER = timedelta(minutes=5)
TOKEN_LIFETIME = timedelta(hours=1)
# Get host and port from environment or use defaults
SERVER_HOST = os.environ.get('SERVER_HOST', DEFAULT_HOST)
SERVER_PORT = int(os.environ.get('SERVER_PORT', DEFAULT_PORT))
# Construct the base URL
SERVER_BASE_URL = f"http://{SERVER_HOST}:{SERVER_PORT}"
API_BASE_URLS = {
'openai': 'https://api.openai.com',
'cerebras': 'https://api.cerebras.ai',
'googleai': f'https://{ENDPOINT}/v1/projects/{PROJECT_ID}/locations/{LOCATION}/endpoints/openapi',
'xai': 'https://api.x.ai',
'groq': 'https://api.groq.com',
'together': 'https://api.together.xyz',
'azure': 'https://models.inference.ai.azure.com',
'scaleway': 'https://api.scaleway.ai/672113a8-636a-4c18-8096-b0e7d4a4f6be/v1',
'hyperbolic': 'https://api.hyperbolic.xyz/v1',
'sambanova': 'https://api.sambanova.ai/v1',
'openrouter': 'https://openrouter.ai/api/v1',
'opencode': 'https://opencode.ai/zen/go/v1',
'mimo': 'https://token-plan-sgp.xiaomimimo.com/v1',
'nanogpt': 'https://nano-gpt.com/api',
'palm': 'https://generativelanguage.googleapis.com/v1beta',
'nineteen': 'https://api.nineteen.ai',
'chutes': 'https://llm.chutes.ai',
'gemini': 'https://generativelanguage.googleapis.com/v1beta',
'gemma': 'https://generativelanguage.googleapis.com/v1beta'
}
# Provider-specific timeouts (connect_timeout, read_timeout)
API_TIMEOUTS = {
'openai': (5, 60),
'cerebras': (5, 60),
'googleai': (10, 120), # Google AI can be slow to respond
'xai': (5, 60),
'groq': (5, 120),
'together': (5, 120), # Together AI can take longer for larger models
'azure': (10, 120),
'scaleway': (5, 60),
'hyperbolic': (5, 60),
'sambanova': (5, 120), # SambaNova can take longer for larger models
'openrouter': (5, 120), # OpenRouter can take longer as it routes to various providers
'opencode': (5, 120), # OpenCode routes to hosted models over an OpenAI-compatible endpoint
'mimo': (5, 300), # MiMo Token Plan supports long-context agent requests
'nanogpt': (5, 120), # NanoGPT routes to many providers and supports web/memory augmentation
'palm': (10, 120), # PaLM API can be slow to respond
'nineteen': (5, 120),
'chutes': (5, 120), # Chutes API can take longer for larger models
'gemini': (10, 120), # Gemini API can be slow to respond
'gemma': (10, 120), # Gemma API can be slow to respond
'default': (5, 60)
}
# Provider-specific request retry settings
API_RETRIES = {
'openai': {'max_retries': 3, 'backoff_factor': 1},
'cerebras': {'max_retries': 3, 'backoff_factor': 1},
'googleai': {'max_retries': 5, 'backoff_factor': 2}, # More retries for Google AI
'xai': {'max_retries': 3, 'backoff_factor': 1},
'groq': {'max_retries': 3, 'backoff_factor': 1},
'together': {'max_retries': 3, 'backoff_factor': 1},
'azure': {'max_retries': 3, 'backoff_factor': 1},
'scaleway': {'max_retries': 3, 'backoff_factor': 1},
'hyperbolic': {'max_retries': 3, 'backoff_factor': 1},
'sambanova': {'max_retries': 3, 'backoff_factor': 1},
'openrouter': {'max_retries': 3, 'backoff_factor': 1},
'opencode': {'max_retries': 3, 'backoff_factor': 1},
'mimo': {'max_retries': 3, 'backoff_factor': 1},
'nanogpt': {'max_retries': 3, 'backoff_factor': 1},
'palm': {'max_retries': 5, 'backoff_factor': 2}, # More retries for PaLM API
'nineteen': {'max_retries': 3, 'backoff_factor': 1},
'chutes': {'max_retries': 3, 'backoff_factor': 1},
'gemini': {'max_retries': 5, 'backoff_factor': 2}, # More retries for Gemini API
'gemma': {'max_retries': 5, 'backoff_factor': 2}, # More retries for Gemma API
'default': {'max_retries': 3, 'backoff_factor': 1}
}
UNSUPPORTED_PARAMS = {
'cerebras': ['frequency_penalty', 'presence_penalty', 'logit_bias'],
'groq': ['logit_bias', 'logprobs', 'top_logprobs'], # Parameters not supported by Groq
'together': ['logit_bias'], # Parameters not supported by Together AI
'azure': ['logit_bias'], # Parameters not supported by Azure
'scaleway': ['logit_bias', 'frequency_penalty', 'presence_penalty'], # Parameters not supported by Scaleway
'hyperbolic': ['logit_bias'], # Parameters not supported by Hyperbolic
'sambanova': ['logit_bias', 'frequency_penalty', 'presence_penalty'], # Parameters not supported by SambaNova
'openrouter': ['logit_bias'], # Parameters not supported by OpenRouter
'palm': ['logit_bias', 'frequency_penalty', 'presence_penalty'], # Parameters not supported by PaLM API
'chutes': ['logit_bias'], # Parameters not supported by Chutes
'gemini': ['logit_bias', 'frequency_penalty', 'presence_penalty'], # Parameters not supported by Gemini
'gemma': ['logit_bias', 'frequency_penalty', 'presence_penalty'] # Parameters not supported by Gemma
}
# Groq specific settings
GROQ_TOKEN_LIMIT = 6000 # Tokens per minute per API key
GROQ_API_KEYS = load_numbered_env_values('GROQ_API_KEY')
# Available Groq models
GROQ_MODELS = [
'llama3-groq-70b-8192-tool-use-preview',
'gemma2-9b-it',
'llama3-8b-8192',
'llama-3.2-90b-vision-preview',
'llama3-70b-8192',
'llama-3.2-11b-vision-preview',
'llama-3.2-11b-text-preview',
'whisper-large-v3-turbo',
'llava-v1.5-7b-4096-preview',
'llama-3.1-70b-versatile',
'llama-3.2-3b-preview',
'whisper-large-v3',
'llama-guard-3-8b',
'mixtral-8x7b-32768',
'gemma-7b-it',
'distil-whisper-large-v3-en',
'llama-3.2-1b-preview',
'llama-3.2-90b-text-preview',
'llama3-groq-8b-8192-tool-use-preview',
'llama-3.1-8b-instant'
]
# Together AI models
TOGETHER_MODELS = [
'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo',
'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo',
'mistralai/Mixtral-8x7B-Instruct-v0.1',
'mistralai/Mistral-7B-Instruct-v0.2',
'NousResearch/Nous-Hermes-2-Yi-34B',
'openchat/openchat-3.5-1210'
]
# Chutes AI models
CHUTES_MODELS = [
'deepseek-ai/DeepSeek-V3'
]
# Gemini models
GEMINI_MODELS = [
'gemini-3.1-pro-preview',
'gemini-3.1-pro-preview-customtools',
'gemini-3-flash-preview',
'gemini-3.1-flash-lite-preview',
'gemini-2.5-pro',
'gemini-2.5-flash',
'gemini-2.5-flash-lite'
]
# Gemma models
GEMMA_MODELS = [
'gemma-3-8b',
'gemma-3-27b',
'gemma-2-9b',
'gemma-2-27b',
'gemma-1.1-2b-it',
'gemma-1.1-7b-it'
]
# Groq supported parameters and their defaults
GROQ_PARAMS = {
'frequency_penalty': {'type': 'number', 'default': 0, 'min': -2.0, 'max': 2.0},
'presence_penalty': {'type': 'number', 'default': 0, 'min': -2.0, 'max': 2.0},
'max_tokens': {'type': 'integer', 'default': None},
'n': {'type': 'integer', 'default': 1, 'max': 1}, # Only n=1 is supported
'temperature': {'type': 'number', 'default': 1, 'min': 0, 'max': 2},
'top_p': {'type': 'number', 'default': 1, 'min': 0, 'max': 1},
'stream': {'type': 'boolean', 'default': False},
'stop': {'type': ['string', 'array'], 'default': None, 'max_sequences': 4}
}
class DevelopmentConfig(Config):
DEBUG = True
class ProductionConfig(Config):
DEBUG = False