Skip to content

Commit ac23168

Browse files
committed
SimpleChatTC:ShowMessage:Show any number of toolcalls
Also make reasoning easily identifiable in the chat
1 parent 39c7506 commit ac23168

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

tools/server/public_simplechat/simplechat.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
writing-mode: vertical-lr;
4444
padding-inline: 1vmin;
4545
}
46+
.chat-message-reasoning {
47+
border-block-style: dashed;
48+
}
4649
.chat-message-toolcall {
4750
border-style: solid;
4851
border-color: grey;

tools/server/public_simplechat/simplechat.js

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,27 @@ class MultiChatUI {
871871
this.elInUser.focus();
872872
}
873873

874+
/**
875+
* Show the passed function / tool call details in specified parent element.
876+
* @param {HTMLElement} elParent
877+
* @param {NSToolCalls} tc
878+
*/
879+
show_message_toolcall(elParent, tc) {
880+
let secTC = document.createElement('section')
881+
secTC.classList.add('chat-message-toolcall')
882+
elParent.append(secTC)
883+
let entry = ui.el_create_append_p(`name: ${tc.function.name}`, secTC);
884+
entry = ui.el_create_append_p(`id: ${tc.id}`, secTC);
885+
let oArgs = JSON.parse(tc.function.arguments)
886+
for (const k in oArgs) {
887+
entry = ui.el_create_append_p(`arg: ${k}`, secTC);
888+
let secArg = document.createElement('section')
889+
secArg.classList.add('chat-message-toolcall-arg')
890+
secTC.append(secArg)
891+
secArg.innerText = oArgs[k]
892+
}
893+
}
894+
874895
/**
875896
* Handles showing a chat message in UI.
876897
*
@@ -907,10 +928,16 @@ class MultiChatUI {
907928
secMain.append(secContents)
908929
// Add the content
909930
//entry = ui.el_create_append_p(`${msg.content_equiv()}`, secContents);
910-
for (const [name, content] of [['reasoning', msg.ns.reasoning_content], ['content', msg.ns.content]]) {
911-
let cTrimmed = content.trim()
912-
if (cTrimmed.length > 0) {
913-
entry = ui.el_create_append_p(`${cTrimmed}`, secContents);
931+
let showList = []
932+
if (msg.ns.reasoning_content.trim().length > 0) {
933+
showList.push(['reasoning', `!!!Reasoning: ${msg.ns.reasoning_content.trim()} !!!\n\n`])
934+
}
935+
if (msg.ns.content.trim().length > 0) {
936+
showList.push(['content', msg.ns.content.trim()])
937+
}
938+
for (const [name, content] of showList) {
939+
if (content.length > 0) {
940+
entry = ui.el_create_append_p(`${content}`, secContents);
914941
entry.classList.add(`chat-message-${name}`)
915942
}
916943
}
@@ -930,18 +957,8 @@ class MultiChatUI {
930957
}
931958
// Handle tool call non ui
932959
if (msg.has_toolcall() && !bTC) {
933-
let secTC = document.createElement('section')
934-
secTC.classList.add('chat-message-toolcall')
935-
secContents.append(secTC)
936-
entry = ui.el_create_append_p(`name: ${msg.ns.tool_calls[0].function.name}`, secTC);
937-
entry = ui.el_create_append_p(`id: ${msg.ns.tool_calls[0].id}`, secTC);
938-
let oArgs = JSON.parse(msg.ns.tool_calls[0].function.arguments)
939-
for (const k in oArgs) {
940-
entry = ui.el_create_append_p(`arg: ${k}`, secTC);
941-
let secArg = document.createElement('section')
942-
secArg.classList.add('chat-message-toolcall-arg')
943-
secTC.append(secArg)
944-
secArg.innerText = oArgs[k]
960+
for (const i in msg.ns.tool_calls) {
961+
this.show_message_toolcall(secContents, msg.ns.tool_calls[i])
945962
}
946963
}
947964
}

0 commit comments

Comments
 (0)