From ea166f0b27ff3032e8b8b0825501754f64e8879d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 22 May 2024 18:17:28 -0700 Subject: [PATCH] Add a send button to the assistant (#12171) ![CleanShot 2024-05-22 at 18 20 45@2x](https://github.com/zed-industries/zed/assets/1789/dac9fcde-9fcb-4c40-b5da-ebdc847b3962) Include the keybinding to help people discover how to submit from the keyboard. I'm also shifting from the word "Conversation" to "Context". Release Notes: - Added a send button to the assistant panel. --- assets/settings/default.json | 2 +- crates/assistant/src/assistant_panel.rs | 52 ++++++++++++++++------ crates/assistant/src/assistant_settings.rs | 4 +- crates/assistant2/src/assistant2.rs | 2 +- docs/src/assistant-panel.md | 4 +- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 78c1475d61..ab10a3c517 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -316,7 +316,7 @@ // AI provider. "provider": { "name": "openai", - // The default model to use when starting new conversations. This + // The default model to use when creating new contexts. This // setting can take three values: // // 1. "gpt-3.5-turbo" diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 3e60affc95..32cc6995bb 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -61,7 +61,10 @@ use std::{ }; use telemetry_events::AssistantKind; use theme::ThemeSettings; -use ui::{popover_menu, prelude::*, ButtonLike, ContextMenu, Tab, TabBar, Tooltip}; +use ui::{ + popover_menu, prelude::*, ButtonLike, ContextMenu, ElevationIndex, KeyBinding, Tab, TabBar, + Tooltip, +}; use util::{paths::CONVERSATIONS_DIR, post_inc, ResultExt, TryFutureExt}; use uuid::Uuid; use workspace::{ @@ -1057,15 +1060,25 @@ impl AssistantPanel { }) } - fn render_assist_button(cx: &mut ViewContext) -> impl IntoElement { - IconButton::new("assist_button", IconName::MagicWand) - .on_click(cx.listener(|this, _event, cx| { - if let Some(active_editor) = this.active_conversation_editor() { - active_editor.update(cx, |editor, cx| editor.assist(&Default::default(), cx)); - } - })) - .icon_size(IconSize::Small) - .tooltip(|cx| Tooltip::for_action("Assist", &Assist, cx)) + fn render_send_button(&self, cx: &mut ViewContext) -> Option { + self.active_conversation_editor + .as_ref() + .map(|conversation| { + let focus_handle = conversation.editor.focus_handle(cx); + ButtonLike::new("send_button") + .style(ButtonStyle::Filled) + .layer(ElevationIndex::ModalSurface) + .children( + KeyBinding::for_action_in(&Assist, &focus_handle, cx) + .map(|binding| binding.into_any_element()), + ) + .child(Label::new("Send")) + .on_click(cx.listener(|this, _event, cx| { + if let Some(active_editor) = this.active_conversation_editor() { + active_editor.update(cx, |editor, cx| editor.assist(&Assist, cx)); + } + })) + }) } fn render_saved_conversation( @@ -1194,8 +1207,7 @@ impl AssistantPanel { this.show_prompt_manager(cx) })) .tooltip(|cx| Tooltip::text("Prompt Library…", cx)), - ) - .child(Self::render_assist_button(cx)), + ), ), ); @@ -1262,7 +1274,19 @@ impl AssistantPanel { .into_any_element() } else if let Some(editor) = self.active_conversation_editor() { let editor = editor.clone(); - div().size_full().child(editor.clone()).into_any_element() + div() + .size_full() + .child(editor.clone()) + .child( + h_flex() + .w_full() + .absolute() + .bottom_0() + .p_4() + .justify_end() + .children(self.render_send_button(cx)), + ) + .into_any_element() } else { div().into_any_element() }, @@ -3503,7 +3527,7 @@ impl ConversationEditor { .summary .as_ref() .map(|summary| summary.text.clone()) - .unwrap_or_else(|| "New Conversation".into()) + .unwrap_or_else(|| "New Context".into()) } } diff --git a/crates/assistant/src/assistant_settings.rs b/crates/assistant/src/assistant_settings.rs index 31e32a2893..d822db8f70 100644 --- a/crates/assistant/src/assistant_settings.rs +++ b/crates/assistant/src/assistant_settings.rs @@ -339,11 +339,11 @@ pub struct LegacyAssistantSettingsContent { /// /// Default: 320 pub default_height: Option, - /// The default OpenAI model to use when starting new conversations. + /// The default OpenAI model to use when creating new contexts. /// /// Default: gpt-4-1106-preview pub default_open_ai_model: Option, - /// OpenAI API base URL to use when starting new conversations. + /// OpenAI API base URL to use when creating new contexts. /// /// Default: https://api.openai.com/v1 pub openai_api_url: Option, diff --git a/crates/assistant2/src/assistant2.rs b/crates/assistant2/src/assistant2.rs index 9ad1b7b99b..72292c4d22 100644 --- a/crates/assistant2/src/assistant2.rs +++ b/crates/assistant2/src/assistant2.rs @@ -1108,7 +1108,7 @@ impl Render for AssistantChat { .on_click(cx.listener(move |this, _event, cx| { this.new_conversation(cx); })) - .tooltip(move |cx| Tooltip::text("New Conversation", cx)), + .tooltip(move |cx| Tooltip::text("New Context", cx)), ) .child( IconButton::new("assistant-menu", IconName::Menu) diff --git a/docs/src/assistant-panel.md b/docs/src/assistant-panel.md index 19a5cce9ab..444b851f92 100644 --- a/docs/src/assistant-panel.md +++ b/docs/src/assistant-panel.md @@ -46,7 +46,7 @@ After submitting a message, the assistant's response will be streamed below, in The stream can be canceled at any point with `escape`. This is useful if you realize early on that the response is not what you were looking for. -If you want to start a new conversation at any time, you can use the `New Conversation` button located at the top-right corner of the assistant panel. +If you want to start a new conversation at any time, you can hit `cmd-n` or use the `New Context` menu option in the hamburger menu at the top left of the panel. Simple back-and-forth conversations work well with the assistant. However, there may come a time when you want to modify the previous text in the conversation and steer it in a different direction. @@ -62,7 +62,7 @@ The assistant gives you the flexibility to have control over the conversation. Y 6. Add additional context to your original message 7. Submit the message with `cmd-enter` -Being able to edit previous messages gives you control over how tokens are used. You don't need to start up a new conversation to correct a mistake or to add additional context and you don't have to waste tokens by submitting follow-up corrections. +Being able to edit previous messages gives you control over how tokens are used. You don't need to start up a new context to correct a mistake or to add additional context and you don't have to waste tokens by submitting follow-up corrections. Some additional points to keep in mind: