Skip to content

Commit

Permalink
šŸ› Bug: Fix the bug where the error string was not recognized as a faiā€¦
Browse files Browse the repository at this point in the history
ā€¦led response.
  • Loading branch information
yym68686 committed Dec 3, 2024
1 parent db74559 commit 4bc2290
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/provider_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import json
import pytest
from fastapi.testclient import TestClient
import sys
Expand Down Expand Up @@ -81,7 +82,15 @@ def test_request_model(test_client, api_key, get_model):

response = test_client.post("/v1/chat/completions", json=request_data, headers=headers)
for line in response.iter_lines():
print(line.lstrip("data: "))
line = line.lstrip("data: ")
if line == "[DONE]":
print("DONE")
break
try:
data = json.loads(line)
print(data)
except json.JSONDecodeError:
print(line)
assert 200 <= response.status_code < 300

if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ async def error_handling_wrapper(generator, channel_id, engine, stream, error_tr
raise HTTPException(status_code=status_code, detail=f"{detail}"[:300])

if isinstance(first_item_str, dict) and engine not in ["tts", "embedding", "dalle", "moderation", "whisper"] and stream == False:
if any(x in str(first_item_str) for x in error_triggers):
logger.error(f"provider: {channel_id:<11} error const string: %s", first_item_str)
raise StopAsyncIteration
content = safe_get(first_item_str, "choices", 0, "message", "content", default=None)
if content == "" or content is None:
raise StopAsyncIteration
Expand Down

0 comments on commit 4bc2290

Please sign in to comment.