SimpleChatTC:MultiChatUI:ChatShow cleanup of Initial skeleton
Fix up the initial skeleton / logic as needed. Remember that we are working with potentially a subset of chat messages from the session, given the sliding window logic of context managing on client ui side, so fix up the logic to use the right subset of messages array and not the global xchat when deciding whether a message is the last or last but one, which need special handling wrt Assistant (with toolcall) and Tool (ie response) messages. Moving tool call ui setup as well as tool call response got ui setup into ChatShow of MultiChatUI ensures that switching between chat sessions handle the ui wrt tool call triggering ui and tool call response submission related ui as needed properly. Rather even loading a previously auto saved chat session if it had tool call or tool call response to be handled, the chat ui will be setup as needed to continue that session properly.
This commit is contained in:
parent
2cc10f6705
commit
937aa57528
|
|
@ -353,11 +353,11 @@ class SimpleChat {
|
|||
|
||||
/**
|
||||
* Recent chat messages.
|
||||
* If iRecentUserMsgCnt < 0
|
||||
* Then return the full chat history
|
||||
* Else
|
||||
* Return chat messages from latest going back till the last/latest system prompt.
|
||||
* While keeping track that the number of user queries/messages doesnt exceed iRecentUserMsgCnt.
|
||||
*
|
||||
* If iRecentUserMsgCnt < 0, Then return the full chat history
|
||||
*
|
||||
* Else Return chat messages from latest going back till the last/latest system prompt.
|
||||
* While keeping track that the number of user queries/messages doesnt exceed iRecentUserMsgCnt.
|
||||
* @param {number} iRecentUserMsgCnt
|
||||
*/
|
||||
recent_chat(iRecentUserMsgCnt) {
|
||||
|
|
@ -890,9 +890,10 @@ class MultiChatUI {
|
|||
this.ui_reset_toolcall_as_needed(new ChatMessageEx());
|
||||
}
|
||||
let last = undefined;
|
||||
for(const [i, x] of chat.recent_chat(gMe.chatProps.iRecentUserMsgCnt).entries()) {
|
||||
let chatToShow = chat.recent_chat(gMe.chatProps.iRecentUserMsgCnt);
|
||||
for(const [i, x] of chatToShow.entries()) {
|
||||
if (x.ns.role === Roles.ToolTemp) {
|
||||
if (i == (chat.xchat.length - 1)) {
|
||||
if (i == (chatToShow.length - 1)) {
|
||||
this.elInUser.value = x.ns.content;
|
||||
}
|
||||
continue
|
||||
|
|
@ -900,8 +901,19 @@ class MultiChatUI {
|
|||
let entry = ui.el_create_append_p(`${x.ns.role}: ${x.content_equiv()}`, this.elDivChat);
|
||||
entry.className = `role-${x.ns.role}`;
|
||||
last = entry;
|
||||
if (x.ns.role === Roles.Tool) {
|
||||
this.ui_reset_toolcall_as_needed(x);
|
||||
if (x.ns.role === Roles.Assistant) {
|
||||
let bTC = false
|
||||
if (i == (chatToShow.length-1)) {
|
||||
bTC = true
|
||||
}
|
||||
if (i == (chatToShow.length-2)) {
|
||||
if (chatToShow[i+1].ns.role == Roles.ToolTemp) {
|
||||
bTC = true
|
||||
}
|
||||
}
|
||||
if (bTC) {
|
||||
this.ui_reset_toolcall_as_needed(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (last !== undefined) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue