File tree Expand file tree Collapse file tree 3 files changed +9
-6
lines changed
Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,8 @@ api.setApiBaseUrl( 'https://...your openai proxy address' );
5151``` js
5252import Api2d from ' api2d' ;
5353
54- const api = new Api2d (key, apiBaseUrl);
54+ const timeout = 1000 * 60 ; // 60秒超时
55+ const api = new Api2d (key, apiBaseUrl, timeout);
5556
5657// chat 补全
5758const ret = await api .completion ({
@@ -80,6 +81,8 @@ console.log( ret );
8081
8182api .setKey ( ' newkey' ); // set key
8283api .setApiBaseUrl ( ' https://...your openai proxy address' );
84+ api .setTimeout ( 1000 * 60 * 5 );
85+ api .abort (); // 主动取消请求
8386
8487```
8588
Original file line number Diff line number Diff line change @@ -73,14 +73,14 @@ export default class Api2d
7373 }
7474 } ,
7575 onmessage : e => {
76+ if ( timeout_handle )
77+ {
78+ clearTimeout ( timeout_handle ) ;
79+ }
7680 if ( e . data == '[DONE]' )
7781 {
7882 // console.log( 'DONE' );
7983 if ( onEnd ) onEnd ( chars ) ;
80- if ( timeout_handle )
81- {
82- clearTimeout ( timeout_handle ) ;
83- }
8484 resolve ( chars ) ;
8585 } else
8686 {
Original file line number Diff line number Diff line change 11{
22 "name" : " api2d" ,
3- "version" : " 0.1.7 " ,
3+ "version" : " 0.1.8 " ,
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