Skip to content

Commit 7a2c413

Browse files
committed
streaming wip
1 parent f3d26d9 commit 7a2c413

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

frontend/package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@fortawesome/fontawesome-svg-core": "^6.2.0",
1313
"@fortawesome/free-solid-svg-icons": "^6.2.0",
1414
"@fortawesome/react-fontawesome": "^0.2.0",
15+
"@microsoft/fetch-event-source": "^2.0.1",
1516
"@sentry/react": "^7.16.0",
1617
"ansi_up": "^5.0.0",
1718
"axios": "^0.21.2",

frontend/src/App.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import terms from "./terms.json"
5959
import _ from "lodash";
6060
import {otherVisibleLanguages} from "./languages";
6161
import ReactMarkdown from "react-markdown";
62+
import {fetchEventSource} from '@microsoft/fetch-event-source';
6263

6364

6465
const EditorButtons = (
@@ -320,17 +321,29 @@ function AI({ chat }) {
320321
assistant,
321322
terms: terms.unparsed,
322323
};
323-
const res = await fetch(
324+
let currentChat = "";
325+
await fetchEventSource(
324326
"http://127.0.0.1:5001/futurecoder-io/us-central1/chat",
325327
{
326328
method: "POST",
327329
body: JSON.stringify(data),
328330
headers: {
329331
"Content-Type": "application/json",
330332
},
333+
onmessage: (event) => {
334+
console.log(event);
335+
// currentChat += event.data;
336+
// bookSetState("assistant.chat", currentChat);
337+
},
338+
onclose() {
339+
console.log("closed");
340+
},
341+
onerror(error) {
342+
console.error(error);
343+
throw error;
344+
}
331345
}
332346
);
333-
bookSetState("assistant.chat", await res.text());
334347
}}>
335348
Send
336349
</button>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy