assistant2: Add a checkbox to control tool use (#21215)

This PR adds a checkbox to the `assistant2` message editor to control
whether tools should be used for a given message.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-11-26 10:48:48 -05:00 committed by GitHub
parent fdc17c57d7
commit 8f1ec3d11b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,10 +1,9 @@
use editor::{Editor, EditorElement, EditorStyle};
use feature_flags::{FeatureFlagAppExt, ToolUseFeatureFlag};
use gpui::{AppContext, FocusableView, Model, TextStyle, View};
use language_model::{LanguageModelRegistry, LanguageModelRequestTool};
use settings::Settings;
use theme::ThemeSettings;
use ui::{prelude::*, ButtonLike, ElevationIndex, KeyBinding};
use ui::{prelude::*, ButtonLike, CheckboxWithLabel, ElevationIndex, KeyBinding};
use crate::thread::{RequestKind, Thread};
use crate::Chat;
@ -12,6 +11,7 @@ use crate::Chat;
pub struct MessageEditor {
thread: Model<Thread>,
editor: View<Editor>,
use_tools: bool,
}
impl MessageEditor {
@ -24,6 +24,7 @@ impl MessageEditor {
editor
}),
use_tools: false,
}
}
@ -58,7 +59,7 @@ impl MessageEditor {
thread.insert_user_message(user_message);
let mut request = thread.to_completion_request(request_kind, cx);
if cx.has_flag::<ToolUseFeatureFlag>() {
if self.use_tools {
request.tools = thread
.tools()
.tools(cx)
@ -123,12 +124,24 @@ impl Render for MessageEditor {
h_flex()
.justify_between()
.child(
h_flex().child(
Button::new("add-context", "Add Context")
.style(ButtonStyle::Filled)
.icon(IconName::Plus)
.icon_position(IconPosition::Start),
),
h_flex()
.child(
Button::new("add-context", "Add Context")
.style(ButtonStyle::Filled)
.icon(IconName::Plus)
.icon_position(IconPosition::Start),
)
.child(CheckboxWithLabel::new(
"use-tools",
Label::new("Tools"),
self.use_tools.into(),
cx.listener(|this, selection, _cx| {
this.use_tools = match selection {
Selection::Selected => true,
Selection::Unselected | Selection::Indeterminate => false,
};
}),
)),
)
.child(
h_flex()