diff --git a/tools/server/public_simplechat/readme.md b/tools/server/public_simplechat/readme.md index a513397f06..2e884836e3 100644 --- a/tools/server/public_simplechat/readme.md +++ b/tools/server/public_simplechat/readme.md @@ -857,7 +857,8 @@ Cleanup in general * Allow user to load multiple images and submit to ai as part of a single user message. * Use popover ui to allow user to view larger versions of loaded images as well as remove before submitting to ai, if and when needed. -* add external_ai toolcall +* add external_ai toolcall, user can see the response being generated by the external ai tool call, + as it is getting generated and recieved. * maintain chat session specific DivStream elements, so that in future, if the logic is updated to allow switching in the middle of a pending tool call or pending ai server response, things dont mess up wrt ui, as they will be updating their respective DivStream and switching sessions will also take care of diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index 3138bae340..478929a793 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -14,7 +14,7 @@ const TEMP_MARKER = "-TEMP" const DB_NAME = "SimpleChatTCRV" const DB_STORE = "Sessions" -export const AI_TC_SESSIONNAME = `ExternalAI${TEMP_MARKER}` +export const AI_TC_SESSIONNAME = `TCExternalAI` const ROLES_TEMP_ENDSWITH = TEMP_MARKER @@ -924,7 +924,7 @@ class SimpleChat { throw Error("ERRR:SimpleChat:SC:HandleResponseMultiPart:No body..."); } let elDivStream = elDivStreams[this.chatId]; - elDivStream.divRole.innerText = `Ai:${this.chatId.slice(0,6)}` + elDivStream.divRole.innerText = `Ai:${this.chatId.slice(0,8)}` elDivStream.show() try { let tdUtf8 = new TextDecoder("utf-8"); @@ -1496,6 +1496,7 @@ class MultiChatUI { this.show_message(this.elDivChat, x, iFromLast, nextMsg) } this.elDivChat.appendChild(this.elDivStreams[chatId].div) + this.elDivChat.appendChild(this.elDivStreams[AI_TC_SESSIONNAME].div) if (this.elLastChatMessage != null) { this.scroll_el_into_view(this.elLastChatMessage) } else { @@ -1558,6 +1559,7 @@ class MultiChatUI { console.log(`DBUG:SimpleChat:MCUI:UiRefresh:${chatId}: DivStream ${this.elDivStreams[chatId].div.id} missing...`) } this.elDivChat.appendChild(this.elDivStreams[chatId].div) + this.elDivChat.appendChild(this.elDivStreams[AI_TC_SESSIONNAME].div) if (this.elLastChatMessage != null) { this.scroll_el_into_view(this.elLastChatMessage) } @@ -1726,6 +1728,7 @@ class MultiChatUI { new_chat_session(chatId, bSwitchSession=false) { this.simpleChats[chatId] = new SimpleChat(chatId, this.me); this.elDivStreams[chatId] = new ELDivStream(chatId); + this.elDivStreams[chatId].clear() if (bSwitchSession) { this.handle_session_switch(chatId); } diff --git a/tools/server/public_simplechat/toolai.mjs b/tools/server/public_simplechat/toolai.mjs index d1357924b9..300257b60e 100644 --- a/tools/server/public_simplechat/toolai.mjs +++ b/tools/server/public_simplechat/toolai.mjs @@ -91,7 +91,7 @@ let externalai_meta = { */ function externalai_run(chatid, toolcallid, toolname, obj) { let sc = gMe.multiChat.simpleChats[mChatMagic.AI_TC_SESSIONNAME]; - + sc.clear() sc.add_system_anytime(obj['system_prompt'], 'TC:ExternalAI') sc.add(new mChatMagic.ChatMessageEx(new mChatMagic.NSChatMessage(mChatMagic.Roles.User, obj['user_message']))) sc.handle_chat_hs(gMe.baseURL, mChatMagic.ApiEP.Type.Chat, { chatPropsStream: gMe.chatProps.stream, toolsEnabled: false }, gMe.multiChat.elDivStreams).then((resp)=>{