From 5e04753d1c7edc9f776b924cc94a555cb43ab74e Mon Sep 17 00:00:00 2001
From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com>
Date: Fri, 26 Jul 2024 12:48:06 -0300
Subject: [PATCH] Add note about used context in the model selector (#15235)
When pressing control + enter, the AI-powered
inline transformation input displays an icon button and a token count,
which should show roughly the same numbers you'd see on your assistant
panel. At a first glance, though, the token count not being zero can be
confusing, where you'd wonder where that's coming from. That's because
the inline input uses whatever piece of context and/or information of
the currently selected assistant tab to suggest more accurate edits.
So, this PR introduces an informative piece of text to the
`ModelSelector` menu, on the inline transformation input, which delivers
exactly this bit of info, aimed at clarifying the connection between
these two methods of interacting with LLMs.
I've also took the opportunity to change the icon button's icon to one
that's a bit easier to see, still representing the affordance of "click
to configure something".
Release Notes:
- Add note about how inline edits consume context from the assistant
panel to clarify interaction with LLMs.
---------
Co-authored-by: Marshall Bowers
---
assets/icons/sliders-alt.svg | 6 +++
crates/assistant/src/inline_assistant.rs | 49 ++++++++++++++----------
crates/assistant/src/model_selector.rs | 20 ++++++++++
crates/ui/src/components/icon.rs | 2 +
4 files changed, 56 insertions(+), 21 deletions(-)
create mode 100644 assets/icons/sliders-alt.svg
diff --git a/assets/icons/sliders-alt.svg b/assets/icons/sliders-alt.svg
new file mode 100644
index 0000000000000000000000000000000000000000..36c3feccfede200b4d8192f58a4e3e14fcadc00a
--- /dev/null
+++ b/assets/icons/sliders-alt.svg
@@ -0,0 +1,6 @@
+
diff --git a/crates/assistant/src/inline_assistant.rs b/crates/assistant/src/inline_assistant.rs
index 55c89f40285da5ccbb5637e954b6424c42d7b3ef..307d2efe2c0993868f036e81e758e3136d167004 100644
--- a/crates/assistant/src/inline_assistant.rs
+++ b/crates/assistant/src/inline_assistant.rs
@@ -1420,27 +1420,34 @@ impl Render for PromptEditor {
.w(gutter_dimensions.full_width() + (gutter_dimensions.margin / 2.0))
.justify_center()
.gap_2()
- .child(ModelSelector::new(
- self.fs.clone(),
- IconButton::new("context", IconName::Settings)
- .shape(IconButtonShape::Square)
- .icon_size(IconSize::Small)
- .icon_color(Color::Muted)
- .tooltip(move |cx| {
- Tooltip::with_meta(
- format!(
- "Using {}",
- LanguageModelCompletionProvider::read_global(cx)
- .active_model()
- .map(|model| model.name().0)
- .unwrap_or_else(|| "No model selected".into()),
- ),
- None,
- "Change Model",
- cx,
- )
- }),
- ))
+ .child(
+ ModelSelector::new(
+ self.fs.clone(),
+ IconButton::new("context", IconName::SlidersAlt)
+ .shape(IconButtonShape::Square)
+ .icon_size(IconSize::Small)
+ .icon_color(Color::Muted)
+ .tooltip(move |cx| {
+ Tooltip::with_meta(
+ format!(
+ "Using {}",
+ LanguageModelCompletionProvider::read_global(cx)
+ .active_model()
+ .map(|model| model.name().0)
+ .unwrap_or_else(|| "No model selected".into()),
+ ),
+ None,
+ "Change Model",
+ cx,
+ )
+ }),
+ )
+ .with_info_text(
+ "Inline edits use context\n\
+ from the currently selected\n\
+ assistant panel tab.",
+ ),
+ )
.children(
if let CodegenStatus::Error(error) = &self.codegen.read(cx).status {
let error_message = SharedString::from(error.to_string());
diff --git a/crates/assistant/src/model_selector.rs b/crates/assistant/src/model_selector.rs
index 3847c7b29f5ed1c9fe3b2cc6c58caf665a6307ee..fbf4eb7bd1995b9fac7b26dad745a672b78ac0f3 100644
--- a/crates/assistant/src/model_selector.rs
+++ b/crates/assistant/src/model_selector.rs
@@ -2,6 +2,7 @@ use std::sync::Arc;
use crate::{assistant_settings::AssistantSettings, LanguageModelCompletionProvider};
use fs::Fs;
+use gpui::SharedString;
use language_model::LanguageModelRegistry;
use settings::update_settings_file;
use ui::{prelude::*, ContextMenu, PopoverMenu, PopoverMenuHandle, PopoverTrigger};
@@ -11,6 +12,7 @@ pub struct ModelSelector {
handle: Option>,
fs: Arc,
trigger: T,
+ info_text: Option,
}
impl ModelSelector {
@@ -19,6 +21,7 @@ impl ModelSelector {
handle: None,
fs,
trigger,
+ info_text: None,
}
}
@@ -26,6 +29,11 @@ impl ModelSelector {
self.handle = Some(handle);
self
}
+
+ pub fn with_info_text(mut self, text: impl Into) -> Self {
+ self.info_text = Some(text.into());
+ self
+ }
}
impl RenderOnce for ModelSelector {
@@ -35,8 +43,20 @@ impl RenderOnce for ModelSelector {
menu = menu.with_handle(handle);
}
+ let info_text = self.info_text.clone();
+
menu.menu(move |cx| {
ContextMenu::build(cx, |mut menu, cx| {
+ if let Some(info_text) = info_text.clone() {
+ menu = menu
+ .custom_row(move |_cx| {
+ Label::new(info_text.clone())
+ .color(Color::Muted)
+ .into_any_element()
+ })
+ .separator();
+ }
+
for (index, provider) in LanguageModelRegistry::global(cx)
.read(cx)
.providers()
diff --git a/crates/ui/src/components/icon.rs b/crates/ui/src/components/icon.rs
index dd3db7e6dbe30ce7e985f57c8af490994e8305ec..c56c0415573589b2470769bfa82de960fbd0a129 100644
--- a/crates/ui/src/components/icon.rs
+++ b/crates/ui/src/components/icon.rs
@@ -228,6 +228,7 @@ pub enum IconName {
Settings,
Shift,
Sliders,
+ SlidersAlt,
Snip,
Space,
Sparkle,
@@ -382,6 +383,7 @@ impl IconName {
IconName::Settings => "icons/file_icons/settings.svg",
IconName::Shift => "icons/shift.svg",
IconName::Sliders => "icons/sliders.svg",
+ IconName::SlidersAlt => "icons/sliders-alt.svg",
IconName::Snip => "icons/snip.svg",
IconName::Space => "icons/space.svg",
IconName::Sparkle => "icons/sparkle.svg",