Skip to content

Commit

Permalink
Refactor tool output handling in SmartMessage and SmartThreads
Browse files Browse the repository at this point in the history
- Commented out the logic for sending tool output in user messages to simplify message processing.
- Updated SmartThreads to remove the configuration option for sending tool output in user messages, streamlining settings.
- Enhanced event handling in context.js to prevent unintended collapses of context lists during user interactions.

This commit improves code clarity and prepares for future enhancements in message handling.
  • Loading branch information
Brian Joseph Petro committed Nov 25, 2024
1 parent cdf3601 commit 51b7e2a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
22 changes: 14 additions & 8 deletions smart-chats/components/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ export async function post_process(message, frag, opts) {
header.setAttribute('aria-expanded', 'true');
}
});

}


if (review_context) {
// Handle "x" button clicks to remove context items
const remove_buttons = frag.querySelectorAll('.sc-context-remove-btn');
Expand All @@ -111,13 +109,21 @@ export async function post_process(message, frag, opts) {
// Handle submit button click
const submit_button = frag.querySelector('.sc-context-submit-btn');
if (submit_button) {
submit_button.addEventListener('click', async () => {
// remove the submit button
submit_button.remove();
// hide the remove buttons
frag.querySelectorAll('.sc-context-remove-btn').forEach(btn => btn.style.display = 'none');
// hide the list
submit_button.addEventListener('click', async (e) => {
e.stopPropagation(); // Prevent collapsing the list
const container = e.target.closest('.sc-context-container');
// Remove all remove buttons
container.querySelectorAll('.sc-context-remove-btn').forEach(btn => btn.remove());

// Remove the submit button and its container
const submit_container = submit_button.closest('.sc-context-submit');
if (submit_container) {
submit_container.remove();
}

// Collapse the list
header.setAttribute('aria-expanded', 'false');

// Proceed with processing the message after context review
await message.thread.complete();
});
Expand Down
28 changes: 14 additions & 14 deletions smart-chats/smart_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,20 @@ export class SmartMessage extends SmartBlock {
}
}

// skip tool_call and tool_call_output when sending tool output in user message
if(this.settings.send_tool_output_in_user_message){
console.log('send_tool_output_in_user_message', this.settings.send_tool_output_in_user_message);
if(this.is_last_message && this.role === 'tool'){
return [];
}
if(this.tool_calls && !this.is_last_message){
return [];
}
if(this.role === 'user' && this.next_message?.tool_calls?.length && !this.next_message.is_last_message && this.next_message.next_message.role === 'tool'){
const tool_output = await this.next_message.next_message.tool_call_output_to_request();
this_message.content += tool_output;
}
}
// // skip tool_call and tool_call_output when sending tool output in user message
// if(this.settings.send_tool_output_in_user_message){
// console.log('send_tool_output_in_user_message', this.settings.send_tool_output_in_user_message);
// if(this.is_last_message && this.role === 'tool'){
// return [];
// }
// if(this.tool_calls && !this.is_last_message){
// return [];
// }
// if(this.role === 'user' && this.next_message?.tool_calls?.length && !this.next_message.is_last_message && this.next_message.next_message.role === 'tool'){
// const tool_output = await this.next_message.next_message.tool_call_output_to_request();
// this_message.content += tool_output;
// }
// }

if(typeof this_message.content === 'string' && typeof this.data.content === 'string'){
if (this_message.content) {
Expand Down
12 changes: 6 additions & 6 deletions smart-chats/smart_threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ export class SmartThreads extends SmartSources {
default: 10,
description: "The maximum number of context items to retrieve via lookup.",
},
"send_tool_output_in_user_message": {
name: "Send Tool Output in User Message",
type: "toggle",
default: false,
description: "Whether to send tool output in the user message.",
}
// "send_tool_output_in_user_message": {
// name: "Send Tool Output in User Message",
// type: "toggle",
// default: false,
// description: "Whether to send tool output in the user message.",
// }
};
}

Expand Down

0 comments on commit 51b7e2a

Please sign in to comment.