hzruo commited on
Commit
89a7126
·
verified ·
1 Parent(s): 102a6d4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +20 -3
main.py CHANGED
@@ -293,17 +293,32 @@ async def list_models(api_key: str = Depends(get_api_key)):
293
 
294
  akash_response = response.json()
295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  # 转换为标准 OpenAI 格式
297
  openai_models = {
298
  "object": "list",
299
  "data": [
300
  {
301
- "id": model["id"],
302
  "object": "model",
303
  "created": int(time.time()),
304
  "owned_by": "akash",
305
  "permission": [{
306
- "id": "modelperm-" + model["id"],
307
  "object": "model_permission",
308
  "created": int(time.time()),
309
  "allow_create_engine": False,
@@ -316,7 +331,7 @@ async def list_models(api_key: str = Depends(get_api_key)):
316
  "group": None,
317
  "is_blocking": False
318
  }]
319
- } for model in akash_response.get("models", [])
320
  ]
321
  }
322
 
@@ -324,6 +339,8 @@ async def list_models(api_key: str = Depends(get_api_key)):
324
 
325
  except Exception as e:
326
  print(f"Error in list_models: {e}")
 
 
327
  return {"error": str(e)}
328
 
329
  async def upload_to_xinyew(image_base64: str, job_id: str) -> Optional[str]:
 
293
 
294
  akash_response = response.json()
295
 
296
+ # 添加错误处理和调试信息
297
+ print(f"Akash API response: {akash_response}")
298
+
299
+ # 检查响应格式并适配
300
+ models_list = []
301
+ if isinstance(akash_response, list):
302
+ # 如果直接是列表
303
+ models_list = akash_response
304
+ elif isinstance(akash_response, dict):
305
+ # 如果是字典格式
306
+ models_list = akash_response.get("models", [])
307
+ else:
308
+ print(f"Unexpected response format: {type(akash_response)}")
309
+ models_list = []
310
+
311
  # 转换为标准 OpenAI 格式
312
  openai_models = {
313
  "object": "list",
314
  "data": [
315
  {
316
+ "id": model["id"] if isinstance(model, dict) else model,
317
  "object": "model",
318
  "created": int(time.time()),
319
  "owned_by": "akash",
320
  "permission": [{
321
+ "id": f"modelperm-{model['id'] if isinstance(model, dict) else model}",
322
  "object": "model_permission",
323
  "created": int(time.time()),
324
  "allow_create_engine": False,
 
331
  "group": None,
332
  "is_blocking": False
333
  }]
334
+ } for model in models_list
335
  ]
336
  }
337
 
 
339
 
340
  except Exception as e:
341
  print(f"Error in list_models: {e}")
342
+ import traceback
343
+ print(traceback.format_exc())
344
  return {"error": str(e)}
345
 
346
  async def upload_to_xinyew(image_base64: str, job_id: str) -> Optional[str]: