feat: Add notifyerrors configuration to rotations.json

- Add 'notifyerrors' field to rotation configuration (default: false)
- When enabled, return errors as normal messages instead of HTTP 503
- Allows clients to consume error messages normally without HTTP errors
- Update handlers.py to check notifyerrors setting and return appropriate response
parent 56d1b65e
......@@ -817,6 +817,9 @@ class RotationHandler:
logger.error(f"Rotation {rotation_id} not found")
raise HTTPException(status_code=400, detail=f"Rotation {rotation_id} not found")
# Check if notifyerrors is enabled for this rotation
notify_errors = rotation_config.get('notifyerrors', False)
logger.info(f"Rotation config loaded successfully")
providers = rotation_config.providers
logger.info(f"Number of providers in rotation: {len(providers)}")
......@@ -916,6 +919,34 @@ class RotationHandler:
else:
error_details.append(f" - {provider_id}: Not configured")
# Check if notifyerrors is enabled - if so, return error as normal message instead of HTTP 503
if notify_errors:
logger.info(f"notifyerrors is enabled for rotation '{rotation_id}', returning error as normal message")
# Return a normal response with error message instead of HTTP 503
error_message = f"All providers in rotation '{rotation_id}' failed. Details: {'; '.join(error_details)}"
return {
"id": f"error-{rotation_id}-{int(time.time())}",
"object": "chat.completion",
"created": int(time.time()),
"model": rotation_id,
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": error_message
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 0,
"completion_tokens": len(error_message),
"total_tokens": len(error_message)
},
"aisbf_error": True,
"rotation_id": rotation_id,
"error_details": error_details
}
else:
raise HTTPException(
status_code=503,
detail={
......@@ -1234,6 +1265,38 @@ class RotationHandler:
else:
error_details.append(f" - {provider_id}: Not configured")
# Check if notifyerrors is enabled - if so, return error as normal message instead of HTTP 503
if notify_errors:
logger.info(f"notifyerrors is enabled for rotation '{rotation_id}', returning error as normal message")
# Return a normal response with error message instead of HTTP 503
error_message = f"All providers in rotation '{rotation_id}' failed after {max_retries} attempts. Details: {'; '.join(error_details)}"
return {
"id": f"error-{rotation_id}-{int(time.time())}",
"object": "chat.completion",
"created": int(time.time()),
"model": rotation_id,
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": error_message
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 0,
"completion_tokens": len(error_message),
"total_tokens": len(error_message)
},
"aisbf_error": True,
"rotation_id": rotation_id,
"attempted_models": [m['name'] for m in tried_models],
"attempted_count": len(tried_models),
"max_retries": max_retries,
"last_error": last_error,
"error_details": error_details
}
else:
raise HTTPException(
status_code=503,
detail={
......
{
"notifyerrors": false,
"rotations": {
"coding": {
"model_name": "coding",
"notifyerrors": false,
"providers": [
{
"provider_id": "gemini",
......@@ -85,6 +87,7 @@
},
"general": {
"model_name": "general",
"notifyerrors": false,
"providers": [
{
"provider_id": "gemini",
......@@ -122,6 +125,7 @@
},
"googletest": {
"model_name": "googletest",
"notifyerrors": false,
"providers": [
{
"provider_id": "gemini",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment