fix: choices empty

This commit is contained in:
archer
2023-06-19 11:30:26 +08:00
parent e95f83ec8e
commit 3b515c3c2d
2 changed files with 2 additions and 2 deletions

View File

@@ -75,7 +75,7 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
})();
if (item.event === sseResponseEventEnum.answer && data !== '[DONE]') {
const answer: string = data?.choices[0].delta.content || '';
const answer: string = data?.choices?.[0].delta.content || '';
onMessage(answer);
responseText += answer;
} else if (item.event === sseResponseEventEnum.chatResponse) {

View File

@@ -57,7 +57,7 @@ export const chatResponse = async ({
}
);
const responseText = stream ? '' : response.data.choices[0].message?.content || '';
const responseText = stream ? '' : response.data.choices?.[0].message?.content || '';
const totalTokens = stream ? 0 : response.data.usage?.total_tokens || 0;
return {