Skip to content

Commit

Permalink
added error support for streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ardan-bkennedy committed Sep 27, 2024
1 parent dd137a0 commit 2e59f7a
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 128 deletions.
2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions docs/classes/Client.html

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions docs/interfaces/ChatSSE.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/interfaces/ChatVision.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/ChatVisionChoice.html

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions docs/interfaces/ChatVisionInput.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/ChatVisionMessage.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/interfaces/Completion.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/CompletionChoice.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions docs/interfaces/CompletionInput.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/interfaces/Embedding.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/interfaces/EmbeddingData.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/EmbeddingInput.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/interfaces/Factuality.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/FactualityCheck.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/interfaces/Injection.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/interfaces/InjectionCheck.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/interfaces/ReplacePII.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/interfaces/ReplacePIICheck.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/interfaces/Toxicity.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/ToxicityCheck.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions docs/interfaces/Translate.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/interfaces/Translation.html

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion examples/chat_sse.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ async function ChatSSE() {
if (err.error == 'EOF') {
return;
}
console.log(err);

console.log('ERROR 1:' + err.error);
return;
}

if (event.error != '') {
console.log('ERROR 2:' + event.error);
return;
}

for (const choice of event.choices) {
Expand Down
16 changes: 15 additions & 1 deletion src/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,14 @@ export class Client {
* if (err.error == 'EOF') {
* return;
* }
* console.log(err);
*
* console.log('ERROR 1:' + err.error);
* return;
* }
*
* if (event.error != '') {
* console.log('ERROR 2:' + err.error);
* return;
* }
*
* for (const choice of event.choices) {
Expand Down Expand Up @@ -340,6 +347,13 @@ export class Client {
return new Date(this.created * 1000);
};

// Bill: Earler versions of the API didn't set this field so it
// could be undefined. When V2 is 100% running, we can remove
// this code.
if (typeof chatSSE.error == 'undefined') {
chatSSE.error = '';
}

input.onMessage(chatSSE, err);
};

Expand Down
3 changes: 3 additions & 0 deletions src/api_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ export interface ChatSSE {
/** choices represents the collection of choices to choose from. */
choices: ChatSSEChoice[];

/** error provides error information from the stream. */
error: string;

/** createdDate converts the created unix timestamp into a JS Date. */
createdDate(): Date;
}
Expand Down

0 comments on commit 2e59f7a

Please sign in to comment.