From c7921487ac0564d8741363085149d0b138f912aa Mon Sep 17 00:00:00 2001 From: Kerwin Date: Sun, 16 Apr 2023 21:26:02 +0800 Subject: [PATCH] fix: access token error --- service/src/index.ts | 5 ++++- src/views/chat/index.vue | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/service/src/index.ts b/service/src/index.ts index bd6ad1ac..67b01bcf 100644 --- a/service/src/index.ts +++ b/service/src/index.ts @@ -304,11 +304,14 @@ router.post('/chat-process', [auth, limiter], async (req, res) => { detail: { choices: [ { - finish_reason: chat.detail.choices[0].finish_reason, + finish_reason: undefined, }, ], }, } + if (chat.detail && chat.detail.choices.length > 0) + chuck.detail.choices[0].finish_reason = chat.detail.choices[0].finish_reason + res.write(firstChunk ? JSON.stringify(chuck) : `\n${JSON.stringify(chuck)}`) firstChunk = false }, diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index ebbcb0ae..e126d441 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -159,7 +159,7 @@ async function onConversation() { }, ) - if (openLongReply && data.detail.choices[0].finish_reason === 'length') { + if (openLongReply && data.detail && data.detail.choices.length > 0 && data.detail.choices[0].finish_reason === 'length') { options.parentMessageId = data.id lastText = data.text message = '' @@ -302,7 +302,7 @@ async function onRegenerate(index: number) { }, ) - if (openLongReply && data.detail.choices[0].finish_reason === 'length') { + if (openLongReply && data.detail && data.detail.choices.length > 0 && data.detail.choices[0].finish_reason === 'length') { options.parentMessageId = data.id lastText = data.text message = ''