From aef32d9cc0933d4a1d18cc1db59a539f3607f352 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Sat, 18 May 2024 00:02:56 +0530 Subject: [PATCH] SimpleChat:JS: Handle difference in response Try read the assistance response from appropriate field in the response got. Also examples/server seems to return the response in a slightly different field, so try account for that also. --- examples/server/public_simplechat/simplechat.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index 97496097c..b14338274 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -124,7 +124,16 @@ async function handle_submit(inputUser, divChat, apiEP) { inputUser.disabled = false; let respBody = await resp.json(); console.debug("DBUG:HandleSubmit:RespBody:", respBody); - let assistantMsg = respBody["choices"][0]["message"]["content"]; + let assistantMsg; + if (apiEP == ApiEP.Chat) { + assistantMsg = respBody["choices"][0]["message"]["content"]; + } else { + try { + assistantMsg = respBody["choices"][0]["text"]; + } catch { + assistantMsg = respBody["content"]; + } + } gChat.add(Roles.Assistant, assistantMsg); gChat.show(divChat); inputUser.scrollIntoView(true);