Spaces:
Paused
Paused
Mirrowel commited on
Commit ·
4ef7f43
1
Parent(s): b9309db
fix(providers): improve error handling in streaming and rate limit scenarios
Browse files- Add logging for final error message in client when no last exception exists
- Update tool calls structure in Gemini CLI provider to include type field
- Ensure response body is read before raising rate limit error for better error reporting
src/rotator_library/client.py
CHANGED
|
@@ -915,6 +915,8 @@ class RotatingClient:
|
|
| 915 |
if last_exception:
|
| 916 |
final_error_message = f"Failed to complete the streaming request. Last error: {str(last_exception)}"
|
| 917 |
lib_logger.error(f"Streaming request failed after trying all keys. Last error: {last_exception}")
|
|
|
|
|
|
|
| 918 |
|
| 919 |
error_data = {"error": {"message": final_error_message, "type": "proxy_error"}}
|
| 920 |
yield f"data: {json.dumps(error_data)}\n\n"
|
|
|
|
| 915 |
if last_exception:
|
| 916 |
final_error_message = f"Failed to complete the streaming request. Last error: {str(last_exception)}"
|
| 917 |
lib_logger.error(f"Streaming request failed after trying all keys. Last error: {last_exception}")
|
| 918 |
+
else:
|
| 919 |
+
lib_logger.error(final_error_message)
|
| 920 |
|
| 921 |
error_data = {"error": {"message": final_error_message, "type": "proxy_error"}}
|
| 922 |
yield f"data: {json.dumps(error_data)}\n\n"
|
src/rotator_library/providers/gemini_cli_provider.py
CHANGED
|
@@ -376,7 +376,7 @@ class GeminiCliProvider(GeminiAuthBase, ProviderInterface):
|
|
| 376 |
for tc_chunk in delta["tool_calls"]:
|
| 377 |
index = tc_chunk["index"]
|
| 378 |
if index not in aggregated_tool_calls:
|
| 379 |
-
aggregated_tool_calls[index] = {"function": {"name": "", "arguments": ""}}
|
| 380 |
if "id" in tc_chunk:
|
| 381 |
aggregated_tool_calls[index]["id"] = tc_chunk["id"]
|
| 382 |
if "function" in tc_chunk:
|
|
@@ -613,6 +613,7 @@ class GeminiCliProvider(GeminiAuthBase, ProviderInterface):
|
|
| 613 |
except httpx.HTTPStatusError as e:
|
| 614 |
file_logger.log_error(f"Stream handler HTTPStatusError: {str(e)}")
|
| 615 |
if e.response.status_code == 429:
|
|
|
|
| 616 |
raise RateLimitError(
|
| 617 |
message=f"Gemini CLI rate limit exceeded: {e.response.text}",
|
| 618 |
llm_provider="gemini_cli",
|
|
|
|
| 376 |
for tc_chunk in delta["tool_calls"]:
|
| 377 |
index = tc_chunk["index"]
|
| 378 |
if index not in aggregated_tool_calls:
|
| 379 |
+
aggregated_tool_calls[index] = {"type": "function", "function": {"name": "", "arguments": ""}}
|
| 380 |
if "id" in tc_chunk:
|
| 381 |
aggregated_tool_calls[index]["id"] = tc_chunk["id"]
|
| 382 |
if "function" in tc_chunk:
|
|
|
|
| 613 |
except httpx.HTTPStatusError as e:
|
| 614 |
file_logger.log_error(f"Stream handler HTTPStatusError: {str(e)}")
|
| 615 |
if e.response.status_code == 429:
|
| 616 |
+
await e.response.aread() # Read the response to access content
|
| 617 |
raise RateLimitError(
|
| 618 |
message=f"Gemini CLI rate limit exceeded: {e.response.text}",
|
| 619 |
llm_provider="gemini_cli",
|