stuff
This commit is contained in:
1 parent
e6db824792
commit
ed76261303
5 files changed
+170
-9
No files matched your search
@@ -741,6 +741,7 @@ class AIChatApp(App):
|
||||
await self._try_streaming(ai, history, bubble)
|
||||
except Exception as stream_error:
|
||||
self.update_status(f"Streaming failed ({self.describe_error(stream_error)}); trying non-streaming")
|
||||
bubble.set_content("")
|
||||
bubble.set_waiting(True)
|
||||
try:
|
||||
bubble.set_content(await self.call_ai(ai, history))
|
||||
@@ -870,11 +871,13 @@ class AIChatApp(App):
|
||||
error_body = await response.aread()
|
||||
raise Exception(f"API Error {response.status_code}: {error_body.decode(errors='replace')}")
|
||||
|
||||
done = False
|
||||
async for line in response.aiter_lines():
|
||||
if not line.startswith("data:"):
|
||||
continue
|
||||
data = line[5:].lstrip()
|
||||
if data == "[DONE]":
|
||||
done = True
|
||||
break
|
||||
if not data:
|
||||
continue
|
||||
@@ -890,6 +893,8 @@ class AIChatApp(App):
|
||||
if not isinstance(delta, str):
|
||||
raise ValueError("Invalid stream content")
|
||||
yield delta
|
||||
if not done:
|
||||
raise ValueError("Stream ended before [DONE]")
|
||||
|
||||
def update_status(self, text: str) -> None:
|
||||
self.status_bar.update(f"Status: {text}")
|
||||
|
||||
Reference in new issue
Block a user