File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -41,11 +41,18 @@ export default class Api2d
4141 return new Promise ( async ( resolve , reject ) => {
4242 try {
4343 let chars = "" ;
44- console . log ( "in stream" ) ;
44+ // console.log( "in stream" );
4545 const response = await fetchEventSource ( url , {
4646 method : "POST" ,
4747 headers : { ...headers , "Accept" : "text/event-stream" } ,
4848 body : JSON . stringify ( { ...restOptions , model :model || 'gpt-3.5-turbo' } ) ,
49+ async onopen ( response )
50+ {
51+ if ( response . status != 200 )
52+ {
53+ throw new Error ( response . statusText ) ;
54+ }
55+ } ,
4956 onmessage : e => {
5057 if ( e . data == '[DONE]' )
5158 {
@@ -61,9 +68,12 @@ export default class Api2d
6168 }
6269
6370 } ,
71+ onerror : error => {
72+ throw new Error ( error ) ;
73+ }
6474 } ) ;
6575 } catch ( error ) {
66- console . log ( error ) ;
76+ // console.log( error );
6777 reject ( error ) ;
6878 }
6979 } ) ;
Original file line number Diff line number Diff line change 11{
22 "name" : " api2d" ,
3- "version" : " 0.1.5 " ,
3+ "version" : " 0.1.6 " ,
44 "description" : " pure browser sdk for api2d and openai" ,
55 "main" : " index.js" ,
66 "repository" : " https://github.com/easychen/api2d-js" ,
You can’t perform that action at this time.
0 commit comments