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:
parent
fdc17c57d7
commit
8f1ec3d11b
1 changed files with 22 additions and 9 deletions
|
@ -1,10 +1,9 @@
|
||||||
use editor::{Editor, EditorElement, EditorStyle};
|
use editor::{Editor, EditorElement, EditorStyle};
|
||||||
use feature_flags::{FeatureFlagAppExt, ToolUseFeatureFlag};
|
|
||||||
use gpui::{AppContext, FocusableView, Model, TextStyle, View};
|
use gpui::{AppContext, FocusableView, Model, TextStyle, View};
|
||||||
use language_model::{LanguageModelRegistry, LanguageModelRequestTool};
|
use language_model::{LanguageModelRegistry, LanguageModelRequestTool};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use theme::ThemeSettings;
|
use theme::ThemeSettings;
|
||||||
use ui::{prelude::*, ButtonLike, ElevationIndex, KeyBinding};
|
use ui::{prelude::*, ButtonLike, CheckboxWithLabel, ElevationIndex, KeyBinding};
|
||||||
|
|
||||||
use crate::thread::{RequestKind, Thread};
|
use crate::thread::{RequestKind, Thread};
|
||||||
use crate::Chat;
|
use crate::Chat;
|
||||||
|
@ -12,6 +11,7 @@ use crate::Chat;
|
||||||
pub struct MessageEditor {
|
pub struct MessageEditor {
|
||||||
thread: Model<Thread>,
|
thread: Model<Thread>,
|
||||||
editor: View<Editor>,
|
editor: View<Editor>,
|
||||||
|
use_tools: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageEditor {
|
impl MessageEditor {
|
||||||
|
@ -24,6 +24,7 @@ impl MessageEditor {
|
||||||
|
|
||||||
editor
|
editor
|
||||||
}),
|
}),
|
||||||
|
use_tools: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ impl MessageEditor {
|
||||||
thread.insert_user_message(user_message);
|
thread.insert_user_message(user_message);
|
||||||
let mut request = thread.to_completion_request(request_kind, cx);
|
let mut request = thread.to_completion_request(request_kind, cx);
|
||||||
|
|
||||||
if cx.has_flag::<ToolUseFeatureFlag>() {
|
if self.use_tools {
|
||||||
request.tools = thread
|
request.tools = thread
|
||||||
.tools()
|
.tools()
|
||||||
.tools(cx)
|
.tools(cx)
|
||||||
|
@ -123,12 +124,24 @@ impl Render for MessageEditor {
|
||||||
h_flex()
|
h_flex()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.child(
|
.child(
|
||||||
h_flex().child(
|
h_flex()
|
||||||
Button::new("add-context", "Add Context")
|
.child(
|
||||||
.style(ButtonStyle::Filled)
|
Button::new("add-context", "Add Context")
|
||||||
.icon(IconName::Plus)
|
.style(ButtonStyle::Filled)
|
||||||
.icon_position(IconPosition::Start),
|
.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(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue