bahi-bh commited on
Commit
840e133
·
verified ·
1 Parent(s): 04c4bf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -53
app.py CHANGED
@@ -31,7 +31,7 @@ API_KEY = "sk-your-secret-key"
31
 
32
  app = FastAPI(
33
  title="Universal AI Gateway",
34
- version="FINAL-5.1.0"
35
  )
36
 
37
  # =====================================================
@@ -70,7 +70,7 @@ def verify_api_key(req: Request):
70
 
71
  auth = req.headers.get("Authorization")
72
 
73
- # السماح بدون مفتاح للاختبار
74
  if not auth:
75
  return True
76
 
@@ -100,7 +100,7 @@ async def root():
100
  return {
101
  "status": "online",
102
  "service": "Universal AI Gateway",
103
- "version": "FINAL-5.1.0"
104
  }
105
 
106
  # =====================================================
@@ -115,11 +115,12 @@ async def get_models():
115
 
116
  try:
117
 
 
118
  if hasattr(g4f.models, "_all_models"):
119
 
120
  all_models = list(g4f.models._all_models)
121
 
122
- for model in all_models[:200]:
123
 
124
  model_name = str(model)
125
 
@@ -138,47 +139,6 @@ async def get_models():
138
 
139
  logger.error(f"Models error: {e}")
140
 
141
- # =================================================
142
- # IMPORTANT MODELS THAT ACTUALLY WORK
143
- # =================================================
144
-
145
- extra_models = [
146
-
147
- # Cohere
148
- "command-r",
149
- "command-r-plus",
150
- "command-r7b",
151
- "command-a",
152
-
153
- # DeepSeek
154
- "deepseek-chat",
155
- "deepseek-v3",
156
- "deepseek-r1",
157
-
158
- # Kimi
159
- "kimi-k2",
160
-
161
- # GPT
162
- "gpt-4",
163
- "gpt-4o",
164
-
165
- # Gemini
166
- "gemini-2.5-flash",
167
- ]
168
-
169
- for model in extra_models:
170
-
171
- if model not in existing_models:
172
-
173
- models_data.append({
174
- "id": model,
175
- "object": "model",
176
- "created": int(time.time()),
177
- "owned_by": "g4f"
178
- })
179
-
180
- existing_models.add(model)
181
-
182
  return {
183
  "object": "list",
184
  "data": models_data,
@@ -219,15 +179,15 @@ async def chat_completions(
219
 
220
  try:
221
 
222
- client = Client()
223
-
224
- # IMPORTANT:
225
- # لا timeout
226
- # لا retry wrappers
227
- # لا asyncio.to_thread
228
  # لا watchdog
 
229
  # نترك g4f يعمل بطبيعته
230
 
 
 
231
  response = client.chat.completions.create(
232
  model=body.model,
233
  messages=messages,
@@ -242,7 +202,7 @@ async def chat_completions(
242
 
243
  try:
244
 
245
- # تجاهل image models
246
  if hasattr(chunk, "images"):
247
  continue
248
 
@@ -251,6 +211,7 @@ async def chat_completions(
251
  if (
252
  hasattr(chunk, "choices")
253
  and chunk.choices
 
254
  and chunk.choices[0].delta
255
  and chunk.choices[0].delta.content
256
  ):
@@ -289,7 +250,6 @@ async def chat_completions(
289
  f"Chunk error: {chunk_error}"
290
  )
291
 
292
- # stream فارغ
293
  if not has_content:
294
 
295
  logger.warning(
 
31
 
32
  app = FastAPI(
33
  title="Universal AI Gateway",
34
+ version="6.0.0"
35
  )
36
 
37
  # =====================================================
 
70
 
71
  auth = req.headers.get("Authorization")
72
 
73
+ # السماح للاختبار
74
  if not auth:
75
  return True
76
 
 
100
  return {
101
  "status": "online",
102
  "service": "Universal AI Gateway",
103
+ "version": "6.0.0"
104
  }
105
 
106
  # =====================================================
 
115
 
116
  try:
117
 
118
+ # ترك g4f يسترد النماذج تلقائياً بدون تقييد
119
  if hasattr(g4f.models, "_all_models"):
120
 
121
  all_models = list(g4f.models._all_models)
122
 
123
+ for model in all_models:
124
 
125
  model_name = str(model)
126
 
 
139
 
140
  logger.error(f"Models error: {e}")
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  return {
143
  "object": "list",
144
  "data": models_data,
 
179
 
180
  try:
181
 
182
+ # لا forcing
183
+ # لا providers يدوية
184
+ # لا routing
 
 
 
185
  # لا watchdog
186
+ # لا timeout
187
  # نترك g4f يعمل بطبيعته
188
 
189
+ client = Client()
190
+
191
  response = client.chat.completions.create(
192
  model=body.model,
193
  messages=messages,
 
202
 
203
  try:
204
 
205
+ # تجاهل image responses
206
  if hasattr(chunk, "images"):
207
  continue
208
 
 
211
  if (
212
  hasattr(chunk, "choices")
213
  and chunk.choices
214
+ and len(chunk.choices) > 0
215
  and chunk.choices[0].delta
216
  and chunk.choices[0].delta.content
217
  ):
 
250
  f"Chunk error: {chunk_error}"
251
  )
252
 
 
253
  if not has_content:
254
 
255
  logger.warning(