Handle some more API errors

This commit is contained in:
Webifi 2023-06-26 20:11:00 -05:00
parent 67044b362c
commit ef74fd5e31
3 changed files with 9 additions and 5 deletions

View File

@ -11,9 +11,7 @@
getMessage,
currentChatMessages,
setCurrentChat,
currentChatId
} from './Storage.svelte'
import {
type Message,

View File

@ -90,7 +90,10 @@ export class ChatCompletionResponse {
updateFromSyncResponse (response: Response) {
this.setModel(response.model)
response.choices.forEach((choice, i) => {
if (!response.choices) {
return this.updateFromError(response?.error?.message || 'unexpected response from API')
}
response.choices?.forEach((choice, i) => {
const exitingMessage = this.messages[i]
const message = exitingMessage || choice.message
if (exitingMessage) {
@ -121,7 +124,10 @@ export class ChatCompletionResponse {
updateFromAsyncResponse (response: Response) {
let completionTokenCount = 0
this.setModel(response.model)
response.choices.forEach((choice, i) => {
if (!response.choices) {
return this.updateFromError(response?.error?.message || 'unexpected streaming response from API')
}
response.choices?.forEach((choice, i) => {
const message = this.messages[i] || {
role: 'assistant',
content: '',

View File

@ -451,7 +451,7 @@ export class ChatRequest {
...overrides
} as ChatSettings)
// Wait for the response to complete
if (!summary.hasFinished()) await summary.promiseToFinish()
if (!summary.hasError() && !summary.hasFinished()) await summary.promiseToFinish()
if (summary.hasError()) {
// Failed for some API issue. let the original caller handle it.
_this.updating = false