File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 12
12
"@fortawesome/fontawesome-svg-core" : " ^6.2.0" ,
13
13
"@fortawesome/free-solid-svg-icons" : " ^6.2.0" ,
14
14
"@fortawesome/react-fontawesome" : " ^0.2.0" ,
15
+ "@microsoft/fetch-event-source" : " ^2.0.1" ,
15
16
"@sentry/react" : " ^7.16.0" ,
16
17
"ansi_up" : " ^5.0.0" ,
17
18
"axios" : " ^0.21.2" ,
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ import terms from "./terms.json"
59
59
import _ from "lodash" ;
60
60
import { otherVisibleLanguages } from "./languages" ;
61
61
import ReactMarkdown from "react-markdown" ;
62
+ import { fetchEventSource } from '@microsoft/fetch-event-source' ;
62
63
63
64
64
65
const EditorButtons = (
@@ -320,17 +321,29 @@ function AI({ chat }) {
320
321
assistant,
321
322
terms : terms . unparsed ,
322
323
} ;
323
- const res = await fetch (
324
+ let currentChat = "" ;
325
+ await fetchEventSource (
324
326
"http://127.0.0.1:5001/futurecoder-io/us-central1/chat" ,
325
327
{
326
328
method : "POST" ,
327
329
body : JSON . stringify ( data ) ,
328
330
headers : {
329
331
"Content-Type" : "application/json" ,
330
332
} ,
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
+ }
331
345
}
332
346
) ;
333
- bookSetState ( "assistant.chat" , await res . text ( ) ) ;
334
347
} } >
335
348
Send
336
349
</ button >
You can’t perform that action at this time.
0 commit comments