Browse Source

Merge pull request #306 from exo-explore/process_prompt_shield

shield process_prompt so downloads dont get cancelled when chatgpt api request times out fixes #305
Alex Cheema 8 months ago
parent
commit
48fe7b9130
1 changed files with 4 additions and 1 deletions
  1. 4 1
      exo/api/chatgpt_api.py

+ 4 - 1
exo/api/chatgpt_api.py

@@ -270,7 +270,10 @@ class ChatGPTAPI:
     if DEBUG >= 2: print(f"Sending prompt from ChatGPT api {request_id=} {shard=} {prompt=} {image_str=}")
 
     try:
-      await asyncio.wait_for(self.node.process_prompt(shard, prompt, image_str, request_id=request_id), timeout=self.response_timeout)
+      await asyncio.wait_for(
+        asyncio.shield(asyncio.create_task(self.node.process_prompt(shard, prompt, image_str, request_id=request_id))),
+        timeout=self.response_timeout
+      )
 
       if DEBUG >= 2: print(f"Waiting for response to finish. timeout={self.response_timeout}s")