From d401ab1efcb769b1ef21088c08c080e81bf50430 Mon Sep 17 00:00:00 2001 From: Peter Tripp Date: Fri, 30 Aug 2024 12:50:25 +0000 Subject: [PATCH] Make links in assistant configuration clickable (#17011) --- crates/language_model/src/provider/anthropic.rs | 17 +++++++++++++---- crates/language_model/src/provider/google.rs | 16 +++++++++++++--- crates/language_model/src/provider/open_ai.rs | 17 ++++++++++++++--- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/crates/language_model/src/provider/anthropic.rs b/crates/language_model/src/provider/anthropic.rs index c1e3b75341..6be9dc7413 100644 --- a/crates/language_model/src/provider/anthropic.rs +++ b/crates/language_model/src/provider/anthropic.rs @@ -538,13 +538,13 @@ impl ConfigurationView { impl Render for ConfigurationView { fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { + const ANTHROPIC_CONSOLE_URL: &str = "https://console.anthropic.com/settings/keys"; const INSTRUCTIONS: [&str; 4] = [ "To use the assistant panel or inline assistant, you need to add your Anthropic API key.", - "You can create an API key at: https://console.anthropic.com/settings/keys", + "You can create an API key at:", "", "Paste your Anthropic API key below and hit enter to use the assistant:", ]; - let env_var_set = self.state.read(cx).api_key_from_env; if self.load_credentials_task.is_some() { @@ -553,9 +553,18 @@ impl Render for ConfigurationView { v_flex() .size_full() .on_action(cx.listener(Self::save_api_key)) - .children( - INSTRUCTIONS.map(|instruction| Label::new(instruction)), + .child(Label::new(INSTRUCTIONS[0])) + .child(h_flex().child(Label::new(INSTRUCTIONS[1])).child( + Button::new("anthropic_console", ANTHROPIC_CONSOLE_URL) + .style(ButtonStyle::Subtle) + .icon(IconName::ExternalLink) + .icon_size(IconSize::XSmall) + .icon_color(Color::Muted) + .on_click(move |_, cx| cx.open_url(ANTHROPIC_CONSOLE_URL)) + ) ) + .child(Label::new(INSTRUCTIONS[2])) + .child(Label::new(INSTRUCTIONS[3])) .child( h_flex() .w_full() diff --git a/crates/language_model/src/provider/google.rs b/crates/language_model/src/provider/google.rs index 3f4bac4b46..8a9dc760a4 100644 --- a/crates/language_model/src/provider/google.rs +++ b/crates/language_model/src/provider/google.rs @@ -423,9 +423,10 @@ impl ConfigurationView { impl Render for ConfigurationView { fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { + const GOOGLE_CONSOLE_URL: &str = "https://aistudio.google.com/app/apikey"; const INSTRUCTIONS: [&str; 4] = [ "To use the Google AI assistant, you need to add your Google AI API key.", - "You can create an API key at: https://makersuite.google.com/app/apikey", + "You can create an API key at:", "", "Paste your Google AI API key below and hit enter to use the assistant:", ]; @@ -438,9 +439,18 @@ impl Render for ConfigurationView { v_flex() .size_full() .on_action(cx.listener(Self::save_api_key)) - .children( - INSTRUCTIONS.map(|instruction| Label::new(instruction)), + .child(Label::new(INSTRUCTIONS[0])) + .child(h_flex().child(Label::new(INSTRUCTIONS[1])).child( + Button::new("google_console", GOOGLE_CONSOLE_URL) + .style(ButtonStyle::Subtle) + .icon(IconName::ExternalLink) + .icon_size(IconSize::XSmall) + .icon_color(Color::Muted) + .on_click(move |_, cx| cx.open_url(GOOGLE_CONSOLE_URL)) + ) ) + .child(Label::new(INSTRUCTIONS[2])) + .child(Label::new(INSTRUCTIONS[3])) .child( h_flex() .w_full() diff --git a/crates/language_model/src/provider/open_ai.rs b/crates/language_model/src/provider/open_ai.rs index f7a98eb67c..9933c96b94 100644 --- a/crates/language_model/src/provider/open_ai.rs +++ b/crates/language_model/src/provider/open_ai.rs @@ -480,9 +480,10 @@ impl ConfigurationView { impl Render for ConfigurationView { fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { + const OPENAI_CONSOLE_URL: &str = "https://console.anthropic.com/settings/keys"; const INSTRUCTIONS: [&str; 6] = [ "To use the assistant panel or inline assistant, you need to add your OpenAI API key.", - " - You can create an API key at: platform.openai.com/api-keys", + " - You can create an API key at: ", " - Make sure your OpenAI account has credits", " - Having a subscription for another service like GitHub Copilot won't work.", "", @@ -497,9 +498,19 @@ impl Render for ConfigurationView { v_flex() .size_full() .on_action(cx.listener(Self::save_api_key)) - .children( - INSTRUCTIONS.map(|instruction| Label::new(instruction)), + .child(Label::new(INSTRUCTIONS[0])) + .child(h_flex().child(Label::new(INSTRUCTIONS[1])).child( + Button::new("openai_console", OPENAI_CONSOLE_URL) + .style(ButtonStyle::Subtle) + .icon(IconName::ExternalLink) + .icon_size(IconSize::XSmall) + .icon_color(Color::Muted) + .on_click(move |_, cx| cx.open_url(OPENAI_CONSOLE_URL)) + ) ) + .children( + (2..INSTRUCTIONS.len()).map(|n| + Label::new(INSTRUCTIONS[n])).collect::>()) .child( h_flex() .w_full()