From 5d1695ed1d0a2fafac48b7409b71f9cdecb3c670 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 1 Apr 2025 16:13:06 -0400 Subject: [PATCH] assistant2: Add affordances for when the selected model does not support tools (#27870) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR adds some affordances for when the currently-selected model does not support tools. We disable the profile selector and put it into a "No Tools" state: Screenshot 2025-04-01 at 3 58 00 PM We will also only attach tools to the request to the model if the model supports it. Release Notes: - N/A --- crates/assistant2/src/profile_selector.rs | 25 +++++++++++++++++++---- crates/assistant2/src/thread.rs | 24 ++++++++++++---------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/crates/assistant2/src/profile_selector.rs b/crates/assistant2/src/profile_selector.rs index 477721b40f6260149887fae2d213460ce2a1130f..92a3e68a0dd6d7172bb7e442760863a28998c243 100644 --- a/crates/assistant2/src/profile_selector.rs +++ b/crates/assistant2/src/profile_selector.rs @@ -4,9 +4,10 @@ use assistant_settings::{AgentProfile, AssistantSettings}; use fs::Fs; use gpui::{Action, Entity, FocusHandle, Subscription, WeakEntity, prelude::*}; use indexmap::IndexMap; +use language_model::LanguageModelRegistry; use settings::{Settings as _, SettingsStore, update_settings_file}; use ui::{ - ButtonLike, ContextMenu, ContextMenuEntry, KeyBinding, PopoverMenu, PopoverMenuHandle, + ButtonLike, ContextMenu, ContextMenuEntry, KeyBinding, PopoverMenu, PopoverMenuHandle, Tooltip, prelude::*, }; use util::ResultExt as _; @@ -127,6 +128,11 @@ impl Render for ProfileSelector { .map(|profile| profile.name.clone()) .unwrap_or_else(|| "Unknown".into()); + let model_registry = LanguageModelRegistry::read_global(cx); + let supports_tools = model_registry + .active_model() + .map_or(false, |model| model.supports_tools()); + let icon = match profile_id.as_ref() { "write" => IconName::Pencil, "ask" => IconName::MessageBubbles, @@ -139,7 +145,7 @@ impl Render for ProfileSelector { .menu(move |window, cx| { Some(this.update(cx, |this, cx| this.build_context_menu(window, cx))) }) - .trigger( + .trigger(if supports_tools { ButtonLike::new("profile-selector-button").child( h_flex() .gap_1() @@ -164,8 +170,19 @@ impl Render for ProfileSelector { ) .map(|kb| kb.size(rems_from_px(10.))) })), - ), - ) + ) + } else { + ButtonLike::new("tools-not-supported-button") + .disabled(true) + .child( + h_flex().gap_1().child( + Label::new("No Tools") + .size(LabelSize::Small) + .color(Color::Muted), + ), + ) + .tooltip(Tooltip::text("The current model does not support tools.")) + }) .anchor(gpui::Corner::BottomLeft) .with_handle(self.menu_handle.clone()) } diff --git a/crates/assistant2/src/thread.rs b/crates/assistant2/src/thread.rs index 99d517b4af8bd337358f59ce80736c1f3861f675..9ea43dff936cfa9eb25c8fe002e15f42e5fa4374 100644 --- a/crates/assistant2/src/thread.rs +++ b/crates/assistant2/src/thread.rs @@ -780,18 +780,20 @@ impl Thread { cx: &mut Context, ) { let mut request = self.to_completion_request(request_kind, cx); - request.tools = { - let mut tools = Vec::new(); - tools.extend(self.tools().enabled_tools(cx).into_iter().map(|tool| { - LanguageModelRequestTool { - name: tool.name(), - description: tool.description(), - input_schema: tool.input_schema(model.tool_input_format()), - } - })); + if model.supports_tools() { + request.tools = { + let mut tools = Vec::new(); + tools.extend(self.tools().enabled_tools(cx).into_iter().map(|tool| { + LanguageModelRequestTool { + name: tool.name(), + description: tool.description(), + input_schema: tool.input_schema(model.tool_input_format()), + } + })); - tools - }; + tools + }; + } self.stream_completion(request, model, cx); }