Add smooth streaming

This commit is contained in:
Cohee
2024-04-02 14:56:15 +03:00
parent c0fffde739
commit 51b3b8bfaa
7 changed files with 192 additions and 8 deletions

View File

@ -45,7 +45,7 @@ import {
import { getCustomStoppingStrings, persona_description_positions, power_user } from './power-user.js';
import { SECRET_KEYS, secret_state, writeSecret } from './secrets.js';
import EventSourceStream from './sse-stream.js';
import { getEventSourceStream } from './sse-stream.js';
import {
delay,
download,
@ -1772,7 +1772,7 @@ async function sendOpenAIRequest(type, messages, signal) {
throw new Error(`Got response status ${response.status}`);
}
if (stream) {
const eventStream = new EventSourceStream();
const eventStream = getEventSourceStream();
response.body.pipeThrough(eventStream);
const reader = eventStream.readable.getReader();
return async function* streamData() {