From 221e4dcf355bfe688e1f345b9d6058dba8bafefa Mon Sep 17 00:00:00 2001 From: tristandostaler Date: Tue, 24 Sep 2024 11:36:01 -0300 Subject: [PATCH] Fix for new models --- src/hooks/useSubmit.ts | 24 ++++++++++++++++-------- src/types/api.ts | 7 ++++++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/hooks/useSubmit.ts b/src/hooks/useSubmit.ts index 4a4466714..89547868a 100644 --- a/src/hooks/useSubmit.ts +++ b/src/hooks/useSubmit.ts @@ -327,17 +327,25 @@ const useSubmit = () => { if (typeof curr === 'string') { partial += curr; } else { - if (curr.choices[0].delta.function_call?.name) { - fnName += curr.choices[0].delta.function_call?.name; - if (!isFunctionCall) { - isFunctionCall = true; - output += " Plugin call requested. Loading..." + var content = undefined; + if(curr.choices[0].delta) { + if (curr.choices[0].delta.function_call?.name) { + fnName += curr.choices[0].delta.function_call?.name; + if (!isFunctionCall) { + isFunctionCall = true; + output += " Plugin call requested. Loading..." + } } + if (curr.choices[0].delta.function_call?.arguments) { + fnArgs += curr.choices[0].delta.function_call?.arguments; + } + + content = curr.choices[0].delta.content } - if (curr.choices[0].delta.function_call?.arguments) { - fnArgs += curr.choices[0].delta.function_call?.arguments; + if(curr.choices[0].message) { + content = curr.choices[0].message.content } - const content = curr.choices[0].delta.content; + if (content) output += content; } return output; diff --git a/src/types/api.ts b/src/types/api.ts index b7f4a79d4..632caece9 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -9,7 +9,7 @@ export interface EventSourceDataInterface { export type EventSourceData = EventSourceDataInterface | '[DONE]'; export interface EventSourceDataChoices { - delta: { + delta?: { content?: string; function_call?: { name: string; @@ -17,6 +17,11 @@ export interface EventSourceDataChoices { } role?: string; }; + message?: { + role: string; + content: string; + refusal?: {}; + } finish_reason?: string; index: number; }