SimpleChatTC:ChatMessageEx:cleanup, HasToolCalls, ContentEquiv

Update HasToolCalls and ContentEquiv to work with new structure
This commit is contained in:
hanishkvc 2025-10-14 18:28:49 +05:30
parent aa229a1f99
commit 32dd63ee1d
1 changed files with 11 additions and 8 deletions

View File

@ -77,7 +77,8 @@ class ChatMessageEx {
} }
/** /**
* Update based on the drip by drip data got from network in streaming mode * Update based on the drip by drip data got from network in streaming mode.
* Tries to support both Chat and Completion endpoints
* @param {any} nwo * @param {any} nwo
* @param {string} apiEP * @param {string} apiEP
*/ */
@ -88,12 +89,14 @@ class ChatMessageEx {
if (content !== undefined) { if (content !== undefined) {
if (content !== null) { if (content !== null) {
this.ns.content += content; this.ns.content += content;
} else {
this.ns.role = nwo["choices"][0]["delta"]["role"];
} }
} else { } else {
let toolCalls = nwo["choices"][0]["delta"]["tool_calls"]; let toolCalls = nwo["choices"][0]["delta"]["tool_calls"];
if ( toolCalls !== undefined) { if (toolCalls !== undefined) {
if (toolCalls[0]["function"]["name"] !== undefined) { if (toolCalls[0]["function"]["name"] !== undefined) {
this.ns.tool_calls.push(toolCalls[0]) this.ns.tool_calls.push(toolCalls[0]);
/* /*
this.ns.tool_calls[0].function.name = toolCalls[0]["function"]["name"]; this.ns.tool_calls[0].function.name = toolCalls[0]["function"]["name"];
this.ns.tool_calls[0].id = toolCalls[0]["id"]; this.ns.tool_calls[0].id = toolCalls[0]["id"];
@ -127,17 +130,17 @@ class ChatMessageEx {
} }
has_toolcall() { has_toolcall() {
if (this.ns.tool_calls.trim() == "") { if (this.ns.tool_calls.length == 0) {
return false return false
} }
return true return true
} }
content_equiv() { content_equiv() {
if (this.response.content !== "") { if (this.ns.content !== "") {
return this.response.content; return this.ns.content;
} else if (this.has_toolcall()) { } else if (this.has_toolcall()) {
return `<tool_call>\n<tool_name>${this.response.toolname}</tool_name>\n<tool_args>${this.response.toolargs}</tool_args>\n</tool_call>`; return `<tool_call>\n<tool_name>${this.ns.tool_calls[0].function.name}</tool_name>\n<tool_args>${this.ns.tool_calls[0].function.arguments}</tool_args>\n</tool_call>`;
} else { } else {
return "" return ""
} }
@ -184,7 +187,7 @@ class SimpleChat {
*/ */
this.xchat = []; this.xchat = [];
this.iLastSys = -1; this.iLastSys = -1;
this.latestResponse = new AssistantResponse(); this.latestResponse = new ChatMessageEx();
} }
clear() { clear() {