Porównaj commity

...

12 Commity

Autor SHA1 Wiadomość Data
Travis Fischer 600b35eaec chore: update ts docs 2023-04-02 14:54:23 -05:00
Travis Fischer bf66500730 5.2.2 2023-04-02 14:37:34 -05:00
Travis Fischer 8388017963 fix: apiOrg 2023-04-02 14:37:19 -05:00
Travis Fischer 3f5ddc7939 5.2.1 2023-04-02 12:19:52 -05:00
Travis Fischer a720b81699 chore: update deps 2023-04-02 12:19:39 -05:00
Travis Fischer a1749d0d0c 5.2.0 2023-04-02 12:16:01 -05:00
Travis Fischer 07dcc5df31 2023-04-02 11:51:21 -05:00
Travis Fischer c0c2e716ea
Merge pull request #431 from sighingnow/fix-error-handling 2023-04-02 11:47:40 -05:00
Travis Fischer 6c309ce365 🐁 2023-04-02 11:33:54 -05:00
Travis Fischer 8ad7ba9a1d
Merge pull request #505 from 189/feat/conversationId 2023-04-02 11:32:17 -05:00
wangshangwen fa53d8606d feat: support conversationID for ChatGPTAPI 2023-03-28 14:19:20 +08:00
Tao He 452a61eb1b Handle possible token expired errors
Signed-off-by: Tao He <sighingnow@gmail.com>
2023-03-04 21:27:37 +08:00
23 zmienionych plików z 960 dodań i 652 usunięć

Wyświetl plik

@ -11,6 +11,7 @@
### Accessors
- [apiKey](ChatGPTAPI.md#apikey)
- [apiOrg](ChatGPTAPI.md#apiorg)
### Methods
@ -32,7 +33,7 @@ Creates a new client wrapper around OpenAI's chat completion API, mimicing the o
#### Defined in
[src/chatgpt-api.ts:49](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/chatgpt-api.ts#L49)
[src/chatgpt-api.ts:51](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/chatgpt-api.ts#L51)
## Accessors
@ -46,7 +47,7 @@ Creates a new client wrapper around OpenAI's chat completion API, mimicing the o
#### Defined in
[src/chatgpt-api.ts:311](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/chatgpt-api.ts#L311)
[src/chatgpt-api.ts:345](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/chatgpt-api.ts#L345)
`set` **apiKey**(`apiKey`): `void`
@ -62,7 +63,37 @@ Creates a new client wrapper around OpenAI's chat completion API, mimicing the o
#### Defined in
[src/chatgpt-api.ts:315](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/chatgpt-api.ts#L315)
[src/chatgpt-api.ts:349](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/chatgpt-api.ts#L349)
___
### apiOrg
`get` **apiOrg**(): `string`
#### Returns
`string`
#### Defined in
[src/chatgpt-api.ts:353](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/chatgpt-api.ts#L353)
`set` **apiOrg**(`apiOrg`): `void`
#### Parameters
| Name | Type |
| :------ | :------ |
| `apiOrg` | `string` |
#### Returns
`void`
#### Defined in
[src/chatgpt-api.ts:357](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/chatgpt-api.ts#L357)
## Methods
@ -94,4 +125,4 @@ The response from ChatGPT
#### Defined in
[src/chatgpt-api.ts:132](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/chatgpt-api.ts#L132)
[src/chatgpt-api.ts:137](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/chatgpt-api.ts#L137)

Wyświetl plik

@ -39,7 +39,7 @@ Error.constructor
#### Defined in
node_modules/.pnpm/typescript@4.9.5/node_modules/typescript/lib/lib.es5.d.ts:1059
node_modules/.pnpm/typescript@5.0.3/node_modules/typescript/lib/lib.es5.d.ts:1060
**new ChatGPTError**(`message?`, `options?`)
@ -56,7 +56,7 @@ Error.constructor
#### Defined in
node_modules/.pnpm/typescript@4.9.5/node_modules/typescript/lib/lib.es2022.error.d.ts:30
node_modules/.pnpm/typescript@5.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:28
## Properties
@ -66,7 +66,7 @@ node_modules/.pnpm/typescript@4.9.5/node_modules/typescript/lib/lib.es2022.error
#### Defined in
[src/types.ts:80](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L80)
[src/types.ts:86](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L86)
___
@ -76,7 +76,7 @@ ___
#### Defined in
[src/types.ts:79](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L79)
[src/types.ts:85](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L85)
___
@ -86,7 +86,7 @@ ___
#### Defined in
[src/types.ts:77](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L77)
[src/types.ts:83](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L83)
___
@ -96,4 +96,4 @@ ___
#### Defined in
[src/types.ts:78](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L78)
[src/types.ts:84](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L84)

Wyświetl plik

@ -36,7 +36,7 @@
#### Defined in
[src/chatgpt-unofficial-proxy-api.ts:20](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/chatgpt-unofficial-proxy-api.ts#L20)
[src/chatgpt-unofficial-proxy-api.ts:20](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/chatgpt-unofficial-proxy-api.ts#L20)
## Accessors
@ -50,7 +50,7 @@
#### Defined in
[src/chatgpt-unofficial-proxy-api.ts:66](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/chatgpt-unofficial-proxy-api.ts#L66)
[src/chatgpt-unofficial-proxy-api.ts:66](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/chatgpt-unofficial-proxy-api.ts#L66)
`set` **accessToken**(`value`): `void`
@ -66,7 +66,7 @@
#### Defined in
[src/chatgpt-unofficial-proxy-api.ts:70](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/chatgpt-unofficial-proxy-api.ts#L70)
[src/chatgpt-unofficial-proxy-api.ts:70](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/chatgpt-unofficial-proxy-api.ts#L70)
## Methods
@ -101,4 +101,4 @@ The response from ChatGPT
#### Defined in
[src/chatgpt-unofficial-proxy-api.ts:97](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/chatgpt-unofficial-proxy-api.ts#L97)
[src/chatgpt-unofficial-proxy-api.ts:97](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/chatgpt-unofficial-proxy-api.ts#L97)

Wyświetl plik

@ -23,7 +23,7 @@
#### Defined in
[src/types.ts:73](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L73)
[src/types.ts:79](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L79)
___
@ -33,17 +33,17 @@ ___
#### Defined in
[src/types.ts:67](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L67)
[src/types.ts:70](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L70)
___
### detail
`Optional` **detail**: `any`
`Optional` **detail**: [`CreateChatCompletionResponse`](openai.CreateChatCompletionResponse.md) \| [`CreateChatCompletionStreamResponse`](CreateChatCompletionStreamResponse.md)
#### Defined in
[src/types.ts:68](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L68)
[src/types.ts:71](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L71)
___
@ -53,7 +53,7 @@ ___
#### Defined in
[src/types.ts:63](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L63)
[src/types.ts:66](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L66)
___
@ -63,7 +63,7 @@ ___
#### Defined in
[src/types.ts:66](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L66)
[src/types.ts:69](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L69)
___
@ -73,7 +73,7 @@ ___
#### Defined in
[src/types.ts:71](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L71)
[src/types.ts:76](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L76)
___
@ -83,7 +83,7 @@ ___
#### Defined in
[src/types.ts:65](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L65)
[src/types.ts:68](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L68)
___
@ -93,4 +93,4 @@ ___
#### Defined in
[src/types.ts:64](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L64)
[src/types.ts:67](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L67)

Wyświetl plik

@ -0,0 +1,100 @@
[chatgpt](../readme.md) / [Exports](../modules.md) / CreateChatCompletionStreamResponse
# Interface: CreateChatCompletionStreamResponse
## Hierarchy
- [`CreateChatCompletionDeltaResponse`](openai.CreateChatCompletionDeltaResponse.md)
**`CreateChatCompletionStreamResponse`**
## Table of contents
### Properties
- [choices](CreateChatCompletionStreamResponse.md#choices)
- [created](CreateChatCompletionStreamResponse.md#created)
- [id](CreateChatCompletionStreamResponse.md#id)
- [model](CreateChatCompletionStreamResponse.md#model)
- [object](CreateChatCompletionStreamResponse.md#object)
- [usage](CreateChatCompletionStreamResponse.md#usage)
## Properties
### choices
**choices**: [{ `delta`: { `content?`: `string` ; `role`: [`Role`](../modules.md#role) } ; `finish_reason`: `string` ; `index`: `number` }]
#### Inherited from
[CreateChatCompletionDeltaResponse](openai.CreateChatCompletionDeltaResponse.md).[choices](openai.CreateChatCompletionDeltaResponse.md#choices)
#### Defined in
[src/types.ts:198](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L198)
___
### created
**created**: `number`
#### Inherited from
[CreateChatCompletionDeltaResponse](openai.CreateChatCompletionDeltaResponse.md).[created](openai.CreateChatCompletionDeltaResponse.md#created)
#### Defined in
[src/types.ts:196](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L196)
___
### id
**id**: `string`
#### Inherited from
[CreateChatCompletionDeltaResponse](openai.CreateChatCompletionDeltaResponse.md).[id](openai.CreateChatCompletionDeltaResponse.md#id)
#### Defined in
[src/types.ts:194](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L194)
___
### model
**model**: `string`
#### Inherited from
[CreateChatCompletionDeltaResponse](openai.CreateChatCompletionDeltaResponse.md).[model](openai.CreateChatCompletionDeltaResponse.md#model)
#### Defined in
[src/types.ts:197](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L197)
___
### object
**object**: ``"chat.completion.chunk"``
#### Inherited from
[CreateChatCompletionDeltaResponse](openai.CreateChatCompletionDeltaResponse.md).[object](openai.CreateChatCompletionDeltaResponse.md#object)
#### Defined in
[src/types.ts:195](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L195)
___
### usage
**usage**: [`CreateCompletionStreamResponseUsage`](CreateCompletionStreamResponseUsage.md)
#### Defined in
[src/types.ts:97](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L97)

Wyświetl plik

@ -0,0 +1,88 @@
[chatgpt](../readme.md) / [Exports](../modules.md) / CreateCompletionStreamResponseUsage
# Interface: CreateCompletionStreamResponseUsage
**`Export`**
**`Interface`**
CreateCompletionResponseUsage
## Hierarchy
- [`CreateCompletionResponseUsage`](openai.CreateCompletionResponseUsage.md)
**`CreateCompletionStreamResponseUsage`**
## Table of contents
### Properties
- [completion\_tokens](CreateCompletionStreamResponseUsage.md#completion_tokens)
- [estimated](CreateCompletionStreamResponseUsage.md#estimated)
- [prompt\_tokens](CreateCompletionStreamResponseUsage.md#prompt_tokens)
- [total\_tokens](CreateCompletionStreamResponseUsage.md#total_tokens)
## Properties
### completion\_tokens
**completion\_tokens**: `number`
**`Memberof`**
CreateCompletionResponseUsage
#### Inherited from
[CreateCompletionResponseUsage](openai.CreateCompletionResponseUsage.md).[completion_tokens](openai.CreateCompletionResponseUsage.md#completion_tokens)
#### Defined in
[src/types.ts:438](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L438)
___
### estimated
**estimated**: ``true``
#### Defined in
[src/types.ts:102](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L102)
___
### prompt\_tokens
**prompt\_tokens**: `number`
**`Memberof`**
CreateCompletionResponseUsage
#### Inherited from
[CreateCompletionResponseUsage](openai.CreateCompletionResponseUsage.md).[prompt_tokens](openai.CreateCompletionResponseUsage.md#prompt_tokens)
#### Defined in
[src/types.ts:432](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L432)
___
### total\_tokens
**total\_tokens**: `number`
**`Memberof`**
CreateCompletionResponseUsage
#### Inherited from
[CreateCompletionResponseUsage](openai.CreateCompletionResponseUsage.md).[total_tokens](openai.CreateCompletionResponseUsage.md#total_tokens)
#### Defined in
[src/types.ts:444](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L444)

Wyświetl plik

@ -32,7 +32,7 @@ ChatCompletionRequestMessage
#### Defined in
[src/types.ts:211](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L211)
[src/types.ts:227](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L227)
___
@ -48,7 +48,7 @@ ChatCompletionRequestMessage
#### Defined in
[src/types.ts:217](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L217)
[src/types.ts:233](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L233)
___
@ -64,4 +64,4 @@ ChatCompletionRequestMessage
#### Defined in
[src/types.ts:205](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L205)
[src/types.ts:221](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L221)

Wyświetl plik

@ -31,7 +31,7 @@ ChatCompletionResponseMessage
#### Defined in
[src/types.ts:243](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L243)
[src/types.ts:259](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L259)
___
@ -47,4 +47,4 @@ ChatCompletionResponseMessage
#### Defined in
[src/types.ts:237](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L237)
[src/types.ts:253](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L253)

Wyświetl plik

@ -4,6 +4,12 @@
[openai](../modules/openai.md).CreateChatCompletionDeltaResponse
## Hierarchy
- **`CreateChatCompletionDeltaResponse`**
↳ [`CreateChatCompletionStreamResponse`](CreateChatCompletionStreamResponse.md)
## Table of contents
### Properties
@ -22,7 +28,7 @@
#### Defined in
[src/types.ts:182](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L182)
[src/types.ts:198](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L198)
___
@ -32,7 +38,7 @@ ___
#### Defined in
[src/types.ts:180](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L180)
[src/types.ts:196](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L196)
___
@ -42,7 +48,7 @@ ___
#### Defined in
[src/types.ts:178](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L178)
[src/types.ts:194](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L194)
___
@ -52,7 +58,7 @@ ___
#### Defined in
[src/types.ts:181](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L181)
[src/types.ts:197](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L197)
___
@ -62,4 +68,4 @@ ___
#### Defined in
[src/types.ts:179](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L179)
[src/types.ts:195](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L195)

Wyświetl plik

@ -41,7 +41,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:317](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L317)
[src/types.ts:333](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L333)
___
@ -57,7 +57,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:323](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L323)
[src/types.ts:339](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L339)
___
@ -73,7 +73,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:305](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L305)
[src/types.ts:321](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L321)
___
@ -89,7 +89,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:269](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L269)
[src/types.ts:285](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L285)
___
@ -105,7 +105,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:263](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L263)
[src/types.ts:279](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L279)
___
@ -121,7 +121,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:287](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L287)
[src/types.ts:303](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L303)
___
@ -137,7 +137,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:311](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L311)
[src/types.ts:327](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L327)
___
@ -151,7 +151,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:299](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L299)
[src/types.ts:315](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L315)
___
@ -167,7 +167,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:293](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L293)
[src/types.ts:309](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L309)
___
@ -183,7 +183,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:275](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L275)
[src/types.ts:291](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L291)
___
@ -199,7 +199,7 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:281](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L281)
[src/types.ts:297](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L297)
___
@ -215,4 +215,4 @@ CreateChatCompletionRequest
#### Defined in
[src/types.ts:329](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L329)
[src/types.ts:345](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L345)

Wyświetl plik

@ -33,7 +33,7 @@ CreateChatCompletionResponse
#### Defined in
[src/types.ts:372](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L372)
[src/types.ts:388](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L388)
___
@ -47,7 +47,7 @@ CreateChatCompletionResponse
#### Defined in
[src/types.ts:360](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L360)
[src/types.ts:376](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L376)
___
@ -61,7 +61,7 @@ CreateChatCompletionResponse
#### Defined in
[src/types.ts:348](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L348)
[src/types.ts:364](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L364)
___
@ -75,7 +75,7 @@ CreateChatCompletionResponse
#### Defined in
[src/types.ts:366](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L366)
[src/types.ts:382](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L382)
___
@ -89,7 +89,7 @@ CreateChatCompletionResponse
#### Defined in
[src/types.ts:354](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L354)
[src/types.ts:370](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L370)
___
@ -103,4 +103,4 @@ CreateChatCompletionResponse
#### Defined in
[src/types.ts:378](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L378)
[src/types.ts:394](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L394)

Wyświetl plik

@ -30,7 +30,7 @@ CreateChatCompletionResponseChoicesInner
#### Defined in
[src/types.ts:403](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L403)
[src/types.ts:419](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L419)
___
@ -44,7 +44,7 @@ CreateChatCompletionResponseChoicesInner
#### Defined in
[src/types.ts:391](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L391)
[src/types.ts:407](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L407)
___
@ -58,4 +58,4 @@ CreateChatCompletionResponseChoicesInner
#### Defined in
[src/types.ts:397](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L397)
[src/types.ts:413](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L413)

Wyświetl plik

@ -10,6 +10,12 @@
CreateCompletionResponseUsage
## Hierarchy
- **`CreateCompletionResponseUsage`**
↳ [`CreateCompletionStreamResponseUsage`](CreateCompletionStreamResponseUsage.md)
## Table of contents
### Properties
@ -30,7 +36,7 @@ CreateCompletionResponseUsage
#### Defined in
[src/types.ts:422](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L422)
[src/types.ts:438](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L438)
___
@ -44,7 +50,7 @@ CreateCompletionResponseUsage
#### Defined in
[src/types.ts:416](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L416)
[src/types.ts:432](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L432)
___
@ -58,4 +64,4 @@ CreateCompletionResponseUsage
#### Defined in
[src/types.ts:428](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L428)
[src/types.ts:444](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L444)

Wyświetl plik

@ -17,6 +17,8 @@
### Interfaces
- [ChatMessage](interfaces/ChatMessage.md)
- [CreateChatCompletionStreamResponse](interfaces/CreateChatCompletionStreamResponse.md)
- [CreateCompletionStreamResponseUsage](interfaces/CreateCompletionStreamResponseUsage.md)
### Type Aliases
@ -49,6 +51,7 @@
| :------ | :------ | :------ |
| `apiBaseUrl?` | `string` | **`Default Value`** `'https://api.openai.com'` * |
| `apiKey` | `string` | - |
| `apiOrg?` | `string` | - |
| `completionParams?` | `Partial`<`Omit`<[`CreateChatCompletionRequest`](interfaces/openai.CreateChatCompletionRequest.md), ``"messages"`` \| ``"n"`` \| ``"stream"``\>\> | - |
| `debug?` | `boolean` | **`Default Value`** `false` * |
| `fetch?` | [`FetchFn`](modules.md#fetchfn) | - |
@ -61,7 +64,7 @@
#### Defined in
[src/types.ts:7](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L7)
[src/types.ts:7](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L7)
___
@ -71,7 +74,7 @@ ___
#### Defined in
[src/types.ts:136](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L136)
[src/types.ts:152](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L152)
___
@ -93,7 +96,7 @@ https://chat.openapi.com/backend-api/conversation
#### Defined in
[src/types.ts:92](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L92)
[src/types.ts:108](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L108)
___
@ -111,7 +114,7 @@ ___
#### Defined in
[src/types.ts:150](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L150)
[src/types.ts:166](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L166)
___
@ -121,7 +124,7 @@ ___
#### Defined in
[src/types.ts:5](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L5)
[src/types.ts:5](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L5)
___
@ -147,7 +150,7 @@ Returns a chat message from a store by it's ID (or null if not found).
#### Defined in
[src/types.ts:84](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L84)
[src/types.ts:90](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L90)
___
@ -172,7 +175,7 @@ ___
#### Defined in
[src/types.ts:156](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L156)
[src/types.ts:172](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L172)
___
@ -182,7 +185,7 @@ ___
#### Defined in
[src/types.ts:50](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L50)
[src/types.ts:53](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L53)
___
@ -199,7 +202,7 @@ ___
#### Defined in
[src/types.ts:169](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L169)
[src/types.ts:185](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L185)
___
@ -209,7 +212,7 @@ ___
#### Defined in
[src/types.ts:174](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L174)
[src/types.ts:190](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L190)
___
@ -227,7 +230,7 @@ ___
#### Defined in
[src/types.ts:119](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L119)
[src/types.ts:135](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L135)
___
@ -244,7 +247,7 @@ ___
#### Defined in
[src/types.ts:138](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L138)
[src/types.ts:154](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L154)
___
@ -254,7 +257,7 @@ ___
#### Defined in
[src/types.ts:3](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L3)
[src/types.ts:3](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L3)
___
@ -276,7 +279,7 @@ ___
#### Defined in
[src/types.ts:52](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L52)
[src/types.ts:55](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L55)
___
@ -290,6 +293,7 @@ ___
| :------ | :------ | :------ |
| `abortSignal?` | `AbortSignal` | - |
| `completionParams?` | `Partial`<`Omit`<[`CreateChatCompletionRequest`](interfaces/openai.CreateChatCompletionRequest.md), ``"messages"`` \| ``"n"`` \| ``"stream"``\>\> | - |
| `conversationId?` | `string` | - |
| `messageId?` | `string` | - |
| `name?` | `string` | The name of a user in a multi-user chat. |
| `onProgress?` | (`partialResponse`: [`ChatMessage`](interfaces/ChatMessage.md)) => `void` | - |
@ -300,7 +304,7 @@ ___
#### Defined in
[src/types.ts:35](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L35)
[src/types.ts:37](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L37)
___
@ -326,4 +330,4 @@ Upserts a chat message to a store.
#### Defined in
[src/types.ts:87](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L87)
[src/types.ts:93](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L93)

Wyświetl plik

@ -33,9 +33,9 @@
#### Defined in
[src/types.ts:219](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L219)
[src/types.ts:235](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L235)
[src/types.ts:224](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L224)
[src/types.ts:240](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L240)
___
@ -45,9 +45,9 @@ ___
#### Defined in
[src/types.ts:245](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L245)
[src/types.ts:261](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L261)
[src/types.ts:250](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L250)
[src/types.ts:266](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L266)
___
@ -59,7 +59,7 @@ ___
#### Defined in
[src/types.ts:336](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L336)
[src/types.ts:352](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L352)
## Variables
@ -77,9 +77,9 @@ ___
#### Defined in
[src/types.ts:219](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L219)
[src/types.ts:235](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L235)
[src/types.ts:224](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L224)
[src/types.ts:240](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L240)
___
@ -97,6 +97,6 @@ ___
#### Defined in
[src/types.ts:245](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L245)
[src/types.ts:261](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L261)
[src/types.ts:250](https://github.com/transitive-bullshit/chatgpt-api/blob/9eac18f/src/types.ts#L250)
[src/types.ts:266](https://github.com/transitive-bullshit/chatgpt-api/blob/bf66500/src/types.ts#L266)

Wyświetl plik

@ -152,6 +152,7 @@ Options:
-s, --store Enables the local message cache (default: true)
-t, --timeout Timeout in milliseconds
-k, --apiKey OpenAI API key
-o, --apiOrg OpenAI API organization
-n, --conversationName Unique name for the conversation
-h, --help Display this message
-v, --version Display version number
@ -282,8 +283,11 @@ Note that we automatically handle appending the previous messages to the prompt
```js
async function example() {
// To use ESM in CommonJS, you can use a dynamic import
// To use ESM in CommonJS, you can use a dynamic import like this:
const { ChatGPTAPI } = await import('chatgpt')
// You can also try dynamic importing like this:
// const importDynamic = new Function('modulePath', 'return import(modulePath)')
// const { ChatGPTAPI } = await importDynamic('chatgpt')
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY })
@ -443,6 +447,7 @@ All of these awesome projects are built using the `chatgpt` package. 🤯
- [WeChat Bot #4](https://github.com/darknightlab/wechat-bot)
- [WeChat Bot #5](https://github.com/sunshanpeng/wechaty-chatgpt)
- [WeChat Bot #6](https://github.com/formulahendry/chatgpt-wechat-bot)
- [WeChat Bot #7](https://github.com/gfl94/Chatbot004)
- [QQ Bot (plugin for Yunzai-bot)](https://github.com/ikechan8370/chatgpt-plugin)
- [QQ Bot (plugin for KiviBot)](https://github.com/KiviBotLab/kivibot-plugin-chatgpt)
- [QQ Bot (oicq)](https://github.com/easydu2002/chat_gpt_oicq)
@ -470,6 +475,8 @@ All of these awesome projects are built using the `chatgpt` package. 🤯
- [Slack Bot #2](https://github.com/lokwkin/chatgpt-slackbot-node/) (with queueing mechanism)
- [Slack Bot #3](https://github.com/NessunKim/slack-chatgpt/)
- [Slack Bot #4](https://github.com/MarkusGalant/chatgpt-slackbot-serverless/) ( Serverless AWS Lambda )
- [Slack Bot #5](https://github.com/benjiJanssens/SlackGPT) (Hosted)
- [Add to Slack](https://slackgpt.benji.sh/slack/install)
- [Electron Bot](https://github.com/ShiranAbir/chaty)
- [Kodyfire CLI](https://github.com/nooqta/chatgpt-kodyfire)
- [Twitch Bot](https://github.com/BennyDeeDev/chatgpt-twitch-bot)
@ -489,7 +496,8 @@ All of these awesome projects are built using the `chatgpt` package. 🤯
- [ai-commit – GPT-3 Commit Message Generator](https://github.com/insulineru/ai-commit)
- [AItinerary – ChatGPT itinerary Generator](https://aitinerary.ai)
- [wechaty-chatgpt - A chatbot based on Wechaty & ChatGPT](https://github.com/zhengxs2018/wechaty-chatgpt)
- [Julius GPT](https://github.com/christophebe/julius-gpt) : Generate and publish your content from the command line with the help of AI (GPT).
- [Julius GPT](https://github.com/christophebe/julius-gpt) - Generate and publish your content from the CLI
- [OpenAI-API-Service](https://github.com/Jarvan-via/api-service) - Provides OpenAI related APIs for businesses
If you create a cool integration, feel free to open a PR and add it to the list.

4
package-lock.json wygenerowano
Wyświetl plik

@ -1,12 +1,12 @@
{
"name": "chatgpt",
"version": "5.1.4",
"version": "5.2.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "chatgpt",
"version": "5.1.4",
"version": "5.2.2",
"license": "MIT",
"dependencies": {
"@dqbd/tiktoken": "^0.4.0",

Wyświetl plik

@ -1,6 +1,6 @@
{
"name": "chatgpt",
"version": "5.1.4",
"version": "5.2.2",
"description": "Node.js client for the official ChatGPT API.",
"author": "Travis Fischer <travis@transitivebullsh.it>",
"repository": "transitive-bullshit/chatgpt-api",
@ -40,7 +40,7 @@
"@dqbd/tiktoken": "^1.0.2",
"cac": "^6.7.14",
"conf": "^11.0.1",
"eventsource-parser": "^0.0.5",
"eventsource-parser": "^1.0.0",
"keyv": "^4.5.2",
"p-timeout": "^6.1.1",
"quick-lru": "^6.1.1",
@ -50,7 +50,7 @@
"devDependencies": {
"@keyv/redis": "^2.5.6",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/node": "^18.15.10",
"@types/node": "^18.15.11",
"@types/uuid": "^9.0.1",
"del-cli": "^5.0.0",
"dotenv-safe": "^8.2.0",
@ -63,7 +63,7 @@
"tsx": "^3.12.6",
"typedoc": "^0.23.28",
"typedoc-plugin-markdown": "^3.14.0",
"typescript": "^4.9.5"
"typescript": "^5.0.3"
},
"lint-staged": {
"*.{ts,tsx}": [

Plik diff jest za duży Load Diff

Wyświetl plik

@ -37,7 +37,7 @@ export class ChatGPTAPI {
* Creates a new client wrapper around OpenAI's chat completion API, mimicing the official ChatGPT webapp's functionality as closely as possible.
*
* @param apiKey - OpenAI API key (required).
* @param apiOrg - OpenAI API organization (optional).
* @param apiOrg - Optional OpenAI API organization (optional).
* @param apiBaseUrl - Optional override for the OpenAI API base URL.
* @param debug - Optional enables logging debugging info to stdout.
* @param completionParams - Param overrides to send to the [OpenAI chat completion API](https://platform.openai.com/docs/api-reference/chat/create). Options like `temperature` and `presence_penalty` can be tweaked to change the personality of the assistant.
@ -124,6 +124,7 @@ export class ChatGPTAPI {
*
* @param message - The prompt message to send
* @param opts.parentMessageId - Optional ID of the previous message in the conversation (defaults to `undefined`)
* @param opts.conversationId - Optional ID of the conversation (defaults to `undefined`)
* @param opts.messageId - Optional ID of the message to send (defaults to a random UUID)
* @param opts.systemMessage - Optional override for the chat "system message" which acts as instructions to the model (defaults to the ChatGPT system message)
* @param opts.timeoutMs - Optional timeout in milliseconds (defaults to no timeout)
@ -143,7 +144,8 @@ export class ChatGPTAPI {
timeoutMs,
onProgress,
stream = onProgress ? true : false,
completionParams
completionParams,
conversationId
} = opts
let { abortSignal } = opts
@ -157,6 +159,7 @@ export class ChatGPTAPI {
const message: types.ChatMessage = {
role: 'user',
id: messageId,
conversationId,
parentMessageId,
text
}
@ -171,6 +174,7 @@ export class ChatGPTAPI {
const result: types.ChatMessage = {
role: 'assistant',
id: uuidv4(),
conversationId,
parentMessageId: messageId,
text: ''
}

Wyświetl plik

@ -218,9 +218,11 @@ export class ChatGPTUnofficialProxyAPI {
}
}
} catch (err) {
// ignore for now; there seem to be some non-json messages
// console.warn('fetchSSE onMessage unexpected error', err)
reject(err)
}
},
onError: (err) => {
reject(err)
}
},
this._fetch

Wyświetl plik

@ -6,10 +6,13 @@ import { streamAsyncIterable } from './stream-async-iterable'
export async function fetchSSE(
url: string,
options: Parameters<typeof fetch>[1] & { onMessage: (data: string) => void },
options: Parameters<typeof fetch>[1] & {
onMessage: (data: string) => void
onError?: (error: any) => void
},
fetch: types.FetchFn = globalFetch
) {
const { onMessage, ...fetchOptions } = options
const { onMessage, onError, ...fetchOptions } = options
const res = await fetch(url, fetchOptions)
if (!res.ok) {
let reason: string
@ -33,6 +36,35 @@ export async function fetchSSE(
}
})
// handle special response errors
const feed = (chunk: string) => {
let response = null
try {
response = JSON.parse(chunk)
} catch {
// ignore
}
if (response?.detail?.type === 'invalid_request_error') {
const msg = `ChatGPT error ${response.detail.message}: ${response.detail.code} (${response.detail.type})`
const error = new types.ChatGPTError(msg, { cause: response })
error.statusCode = response.detail.code
error.statusText = response.detail.message
if (onError) {
onError(error)
} else {
console.error(error)
}
// don't feed to the event parser
return
}
parser.feed(chunk)
}
if (!res.body.getReader) {
// Vercel polyfills `fetch` with `node-fetch`, which doesn't conform to
// web standards, so this is a workaround...
@ -45,13 +77,13 @@ export async function fetchSSE(
body.on('readable', () => {
let chunk: string | Buffer
while (null !== (chunk = body.read())) {
parser.feed(chunk.toString())
feed(chunk.toString())
}
})
} else {
for await (const chunk of streamAsyncIterable(res.body)) {
const str = new TextDecoder().decode(chunk)
parser.feed(str)
feed(str)
}
}
}

Wyświetl plik

@ -10,7 +10,7 @@ export type ChatGPTAPIOptions = {
/** @defaultValue `'https://api.openai.com'` **/
apiBaseUrl?: string
apiOrg: string
apiOrg?: string
/** @defaultValue `false` **/
debug?: boolean
@ -38,6 +38,7 @@ export type SendMessageOptions = {
/** The name of a user in a multi-user chat. */
name?: string
parentMessageId?: string
conversationId?: string
messageId?: string
stream?: boolean
systemMessage?: string
@ -73,7 +74,8 @@ export interface ChatMessage {
// relevant for both ChatGPTAPI and ChatGPTUnofficialProxyAPI
parentMessageId?: string
// only relevant for ChatGPTUnofficialProxyAPI
// only relevant for ChatGPTUnofficialProxyAPI (optional for ChatGPTAPI)
conversationId?: string
}