bibibi12345 commited on
Commit
311bcf7
·
verified ·
1 Parent(s): a5cc545

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +9 -5
app/main.py CHANGED
@@ -1175,7 +1175,7 @@ async def chat_completions(request: OpenAIRequest, api_key: str = Depends(get_ap
1175
  print("Prompt structure: Unknown format")
1176
 
1177
 
1178
- model_instance = client.get_model(f"models/{model_name}") # Get the model instance
1179
 
1180
  if request.stream:
1181
  # Streaming call (Async)
@@ -1369,12 +1369,16 @@ async def chat_completions(request: OpenAIRequest, api_key: str = Depends(get_ap
1369
  error_msg = f"Error processing model {request.model}: {str(e)}"
1370
  print(error_msg)
1371
  error_response = create_openai_error_response(500, error_msg, "server_error")
1372
- # Similar to auto-fail case, handle stream vs non-stream error return
 
 
1373
  if not request.stream:
1374
  return JSONResponse(status_code=500, content=error_response)
1375
- else:
1376
- # Let the StreamingResponse handle yielding the error
1377
- return result # Return the StreamingResponse object containing the failing generator
 
 
1378
 
1379
 
1380
  except Exception as e:
 
1175
  print("Prompt structure: Unknown format")
1176
 
1177
 
1178
+ model_instance = genai.GenerativeModel(model_name=model_name) # Use genai.GenerativeModel
1179
 
1180
  if request.stream:
1181
  # Streaming call (Async)
 
1369
  error_msg = f"Error processing model {request.model}: {str(e)}"
1370
  print(error_msg)
1371
  error_response = create_openai_error_response(500, error_msg, "server_error")
1372
+ # If it was NOT a streaming request, return the JSON error.
1373
+ # If it WAS a streaming request, the error is yielded within the
1374
+ # stream_generator_inner's own except block, so we don't return anything here.
1375
  if not request.stream:
1376
  return JSONResponse(status_code=500, content=error_response)
1377
+ # For streaming errors caught here (less likely now async calls are awaited directly),
1378
+ # the exception would propagate up. The stream generator handles its internal errors.
1379
+ # We raise the error to ensure the main try/except catches it if needed,
1380
+ # but primarily rely on the stream generator's error handling.
1381
+ raise e
1382
 
1383
 
1384
  except Exception as e: