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.
This commit is contained in:
HanishKVC 2024-05-18 00:02:56 +05:30
parent 3e5edbacd6
commit aef32d9cc0

View file

@ -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);