SimpleChatTC:ChatMessageEx: add update_oneshot
response_extract logic moved directly into ChatMessageEx as update oneshot, with suitable adjustments. Inturn use the same directly.
This commit is contained in:
parent
361f6968d1
commit
abbf927557
|
|
@ -127,7 +127,15 @@ class ChatMessageEx {
|
||||||
* @param {string} apiEP
|
* @param {string} apiEP
|
||||||
*/
|
*/
|
||||||
update_oneshot(nwo, apiEP) {
|
update_oneshot(nwo, apiEP) {
|
||||||
|
if (apiEP == ApiEP.Type.Chat) {
|
||||||
|
this.ns.content = nwo["choices"][0]["message"]["content"];
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
this.ns.content = nwo["choices"][0]["text"];
|
||||||
|
} catch {
|
||||||
|
this.ns.content = nwo["content"];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
has_toolcall() {
|
has_toolcall() {
|
||||||
|
|
@ -389,25 +397,6 @@ class SimpleChat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract the ai-model/assistant's response from the http response got.
|
|
||||||
* Optionally trim the message wrt any garbage at the end.
|
|
||||||
* @param {any} respBody
|
|
||||||
* @param {string} apiEP
|
|
||||||
*/
|
|
||||||
response_extract(respBody, apiEP) {
|
|
||||||
let assistant = new AssistantResponse();
|
|
||||||
if (apiEP == ApiEP.Type.Chat) {
|
|
||||||
assistant.response.content = respBody["choices"][0]["message"]["content"];
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
assistant.response.content = respBody["choices"][0]["text"];
|
|
||||||
} catch {
|
|
||||||
assistant.response.content = respBody["content"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return assistant;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow setting of system prompt, but only at begining.
|
* Allow setting of system prompt, but only at begining.
|
||||||
|
|
@ -525,7 +514,9 @@ class SimpleChat {
|
||||||
async handle_response_oneshot(resp, apiEP) {
|
async handle_response_oneshot(resp, apiEP) {
|
||||||
let respBody = await resp.json();
|
let respBody = await resp.json();
|
||||||
console.debug(`DBUG:SimpleChat:SC:${this.chatId}:HandleUserSubmit:RespBody:${JSON.stringify(respBody)}`);
|
console.debug(`DBUG:SimpleChat:SC:${this.chatId}:HandleUserSubmit:RespBody:${JSON.stringify(respBody)}`);
|
||||||
return this.response_extract(respBody, apiEP);
|
let cm = new ChatMessageEx()
|
||||||
|
cm.update_oneshot(respBody, apiEP)
|
||||||
|
return cm
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -553,9 +544,9 @@ class SimpleChat {
|
||||||
theResp = await this.handle_response_oneshot(resp, apiEP);
|
theResp = await this.handle_response_oneshot(resp, apiEP);
|
||||||
}
|
}
|
||||||
if (gMe.bTrimGarbage) {
|
if (gMe.bTrimGarbage) {
|
||||||
let origMsg = theResp.response.content;
|
let origMsg = theResp.ns.content;
|
||||||
theResp.response.content = du.trim_garbage_at_end(origMsg);
|
theResp.ns.content = du.trim_garbage_at_end(origMsg);
|
||||||
theResp.response.trimmedContent = origMsg.substring(theResp.response.content.length);
|
theResp.trimmedContent = origMsg.substring(theResp.ns.content.length);
|
||||||
}
|
}
|
||||||
this.add(Roles.Assistant, theResp.content_equiv());
|
this.add(Roles.Assistant, theResp.content_equiv());
|
||||||
return theResp;
|
return theResp;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue