Skip to content

Commit

Permalink
fix: make response to stream
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 1, 2023
1 parent bac87c4 commit fe3026f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions editor/src/components/editor/action/command-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ export const CommandFunctions = Extension.create({

switch (action.outputForm) {
case OutputForm.STREAMING:
const content = await fetch("/api/completion/yiyan", {
const response = await fetch("/api/completion/yiyan", {
method: "POST",
body: JSON.stringify({ prompt: prompt }),
}).then(it => it.text());
})

await response.body?.pipeThrough(new TextDecoderStream()).pipeTo(new WritableStream({
write: (chunk) => {
const pos = actionExecutor.position(editor.state.selection);
editor.chain().focus().insertContentAt(pos, chunk).run();
}
}));

const pos = actionExecutor.position(editor.state.selection);
editor.chain().focus().insertContentAt(pos, content).run();
break;
case OutputForm.NORMAL:
const msg = await fetch("/api/completion/yiyan", {
Expand Down

0 comments on commit fe3026f

Please sign in to comment.