Skip to content

Commit

Permalink
Streaming for Prompt API is now 1 at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinBrett committed Jan 3, 2025
1 parent d00326d commit cdfea9c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions components/system/Taskbar/AI/ai.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,13 @@ globalThis.addEventListener(
for await (const chunk of response) {
if (cancel) break;

if (typeof chunk === "string") {
sendMessage(chunk, data.streamId);
} else {
reply +=
(chunk as ChatCompletionChunk).choices[0]?.delta.content ||
"";
sendMessage(reply, data.streamId);
}
reply +=
typeof chunk === "string"
? chunk
: (chunk as ChatCompletionChunk).choices[0]?.delta
.content || "";

sendMessage(reply, data.streamId);
}
} catch (error) {
console.error("Failed to stream prompt response.", error);
Expand Down

0 comments on commit cdfea9c

Please sign in to comment.