[object Object]

← back to Exo

handle writing responses errors

b181f8aa823d744f6af8391ab35a753d13db277e · 2024-08-07 14:17:55 +0100 · Alex Cheema

Files touched

Diff

commit b181f8aa823d744f6af8391ab35a753d13db277e
Author: Alex Cheema <alexcheema123@gmail.com>
Date:   Wed Aug 7 14:17:55 2024 +0100

    handle writing responses errors
---
 exo/api/chatgpt_api.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/exo/api/chatgpt_api.py b/exo/api/chatgpt_api.py
index 000b865f..d11dfe04 100644
--- a/exo/api/chatgpt_api.py
+++ b/exo/api/chatgpt_api.py
@@ -345,7 +345,11 @@ class ChatGPTAPI:
             "chat.completion",
           )
           if DEBUG >= 2: print(f"Streaming completion: {completion}")
-          await response.write(f"data: {json.dumps(completion)}\n\n".encode())
+          try:
+            await response.write(f"data: {json.dumps(completion)}\n\n".encode())
+          except Exception as e:
+            if DEBUG >= 2: print(f"Error streaming completion: {e}")
+            if DEBUG >= 2: traceback.print_exc()
 
         def on_result(_request_id: str, tokens: List[int], is_finished: bool):
           self.stream_tasks[request_id] = asyncio.create_task(stream_result(request_id, tokens, is_finished))

← 7ec660bb fix shard download  ·  back to Exo  ·  upgrade mlx to 0.16.1 35b7042e →