Skip to content

Commit 6ad7f80

Browse files
committed
流式超时时间只计算没有响应时的时间
1 parent a222081 commit 6ad7f80

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ api.setApiBaseUrl( 'https://...your openai proxy address' );
5151
```js
5252
import 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 补全
5758
const ret = await api.completion({
@@ -80,6 +81,8 @@ console.log( ret );
8081

8182
api.setKey( 'newkey' ); // set key
8283
api.setApiBaseUrl( 'https://...your openai proxy address' );
84+
api.setTimeout( 1000*60*5 );
85+
api.abort(); // 主动取消请求
8386

8487
```
8588

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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",

0 commit comments

Comments
 (0)