From f6cc8363d114a680d08384d34c9b17577b089673 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Thu, 19 Sep 2024 13:39:52 +0300 Subject: [PATCH] Allow regular (unprivileged) users to see providers help and adapt it to them --- docs/providers.md | 13 +++++---- src/controller/agent/help/mod.rs | 5 +--- src/controller/help/mod.rs | 5 +--- src/controller/provider/mod.rs | 47 ++++++++++++++++---------------- src/strings/help/agent.rs | 13 ++------- src/strings/introduction.rs | 20 ++++++++++++-- src/strings/provider.rs | 22 +++++++++------ src/strings/usage.rs | 2 +- 8 files changed, 69 insertions(+), 58 deletions(-) diff --git a/docs/providers.md b/docs/providers.md index 740bdbe..3c87d4f 100644 --- a/docs/providers.md +++ b/docs/providers.md @@ -23,17 +23,20 @@ The list of supported providers is below. ### How to choose a provider -If you're not sure which provider to start with, we **recommend [OpenAI](#openai)** as it's the most popular and has the **widest range of capabilities**: [đŸ’Ŧ text-generation](./features.md#-text-generation), [đŸ–Œī¸ image-generation](./features.md#ī¸-image-generation), [đŸĻģ speech-to-text](./features.md#-speech-to-text), [đŸ—Ŗī¸ text-to-speech](./features.md#ī¸-text-to-speech). +If you're not sure which provider to start with, **we recommend [OpenAI](#openai)** as it's the most popular and has the **widest range of capabilities**: [đŸ’Ŧ text-generation](./features.md#-text-generation), [đŸ–Œī¸ image-generation](./features.md#ī¸-image-generation), [đŸĻģ speech-to-text](./features.md#-speech-to-text), [đŸ—Ŗī¸ text-to-speech](./features.md#ī¸-text-to-speech). You don't need to choose just one though. The bot supports [mixing & matching models](./features.md#-mixing--matching-models), so you can use multiple providers at the same time. ### How to use a provider -- sign up for it -- obtain an API key -- [create a new agent](./agents.md#creating-agents) -- set it as a handler for some types of messages (see [Mixing & matching models](./features.md#-mixing--matching-models)) for a specific room or globally +1. 📝 **Sign up for it** + +2. 🔑 **Obtain an API key** + +3. 🤖 **Create one or more agents** in a given room or globally. Next to each provider in the [list below](#supported-providers) you'll see **🗲 Quick start** commands, but you may also refer to the [agent creation guide](./agents.md#creating-agents). + +4. 🤝 **Set the new agent as a handler** for a given use-purpose like text-generation, image-generation, etc. The agent creation wizard will tell you how, but you may also refer to the [🤝 Handlers](./configuration/handlers.md) guide. ### Supported providers diff --git a/src/controller/agent/help/mod.rs b/src/controller/agent/help/mod.rs index 66032c7..80de04a 100644 --- a/src/controller/agent/help/mod.rs +++ b/src/controller/agent/help/mod.rs @@ -12,10 +12,7 @@ pub async fn handle(bot: &Bot, message_context: &MessageContext) -> anyhow::Resu message.push_str(&format!("## {}", strings::help::agent::heading())); message.push_str("\n\n"); - message.push_str(&strings::help::agent::intro( - bot.command_prefix(), - can_manage_agents, - )); + message.push_str(&strings::help::agent::intro(bot.command_prefix())); message.push('\n'); message.push_str(&strings::help::agent::intro_capabilities()); message.push_str("\n\n"); diff --git a/src/controller/help/mod.rs b/src/controller/help/mod.rs index 9db5e52..f07bd46 100644 --- a/src/controller/help/mod.rs +++ b/src/controller/help/mod.rs @@ -18,10 +18,7 @@ pub async fn handle(bot: &Bot, message_context: &MessageContext) -> anyhow::Resu // Agents message.push_str(&format!("## {}", strings::help::agent::heading())); message.push_str("\n\n"); - message.push_str(&strings::help::agent::intro( - bot.command_prefix(), - sender_can_manage_room_local_agents, - )); + message.push_str(&strings::help::agent::intro(bot.command_prefix())); message.push_str("\n\n"); message.push_str(&strings::help::agent::intro_handler_relation( bot.command_prefix(), diff --git a/src/controller/provider/mod.rs b/src/controller/provider/mod.rs index 528bf45..5a371d2 100644 --- a/src/controller/provider/mod.rs +++ b/src/controller/provider/mod.rs @@ -9,17 +9,8 @@ pub fn determine_controller(_text: &str) -> ControllerType { } pub async fn handle_help(message_context: &MessageContext, bot: &Bot) -> anyhow::Result<()> { - if !message_context.sender_can_manage_room_local_agents()? { - bot.messaging() - .send_error_markdown_no_fail( - message_context.room(), - &strings::provider::not_allowed(), - MessageResponseType::Reply(message_context.thread_info().root_event_id.clone()), - ) - .await; - - return Ok(()); - } + let can_create_global_agents = message_context.sender_can_manage_global_config(); + let can_create_room_local_agents = message_context.sender_can_manage_room_local_agents()?; let mut message = String::new(); message.push_str(&format!("## {}", strings::help::provider::heading())); @@ -69,18 +60,28 @@ pub async fn handle_help(message_context: &MessageContext, bot: &Bot) -> anyhow: &provider_info, )); - message.push_str("- 🗲 Quick start:\n"); - message.push_str(&format!( - "\t- create a room-local agent: `{command_prefix} agent create-room-local {provider_id} my-{provider_id}-agent`", - command_prefix = bot.command_prefix(), - provider_id = provider.to_static_str(), - )); - message.push('\n'); - message.push_str(&format!( - "\t- create a global agent: `{command_prefix} agent create-global {provider_id} my-{provider_id}-agent`", - command_prefix = bot.command_prefix(), - provider_id = provider.to_static_str(), - )); + // We always show a "Quick start" section (even to unprivileged users), + // because we're talking about it in a previous message. + message.push_str("- 🗲 Quick start:"); + if can_create_room_local_agents { + message.push_str(&format!( + "\n\t- create a room-local agent: `{command_prefix} agent create-room-local {provider_id} my-{provider_id}-agent`", + command_prefix = bot.command_prefix(), + provider_id = provider.to_static_str(), + )); + } + if can_create_global_agents { + message.push_str(&format!( + "\n\t- create a global agent: `{command_prefix} agent create-global {provider_id} my-{provider_id}-agent`", + command_prefix = bot.command_prefix(), + provider_id = provider.to_static_str(), + )); + } + if !can_create_room_local_agents && !can_create_global_agents { + message.push_str(&format!( + " ask an administrator to create an agent for you (you lack permissions to do so yourself)", + )); + } message.push_str("\n\n"); } diff --git a/src/strings/help/agent.rs b/src/strings/help/agent.rs index f39801d..b22a14e 100644 --- a/src/strings/help/agent.rs +++ b/src/strings/help/agent.rs @@ -2,15 +2,8 @@ pub fn heading() -> String { "🤖 Agents".to_owned() } -pub fn intro(command_prefix: &str, can_see_providers: bool) -> String { - format!( - "An agent is an instantiation and configuration of some **â˜ī¸ provider**{}.", - if can_see_providers { - format!(" (see `{command_prefix} provider`)") - } else { - "".to_owned() - } - ) +pub fn intro(command_prefix: &str) -> String { + format!("An agent is an instantiation and configuration of some **â˜ī¸ provider** (see `{command_prefix} provider`).") } pub fn intro_handler_relation(command_prefix: &str) -> String { @@ -24,7 +17,7 @@ pub fn intro_capabilities() -> String { } pub fn no_permission_to_create_agents() -> &'static str { - "You are neither an administrator, nor a room-local agent manager, so **you cannot create new agents by yourself**." + "âš ī¸ You are neither a bot administrator, nor a room-local agent manager, so **you cannot create new agents by yourself**." } pub fn list_agents(command_prefix: &str) -> String { diff --git a/src/strings/introduction.rs b/src/strings/introduction.rs index 56d82c7..06eef0c 100644 --- a/src/strings/introduction.rs +++ b/src/strings/introduction.rs @@ -144,8 +144,8 @@ fn make_use_of_me_agent_creation( let message = r#"**To make use of me**: 1. â˜ī¸ **Choose an agent provider** (e.g. OpenAI, Mistral, etc). Send a `%command_prefix% provider` command to see the list. -2. 🤖 **Create one or more agents** in this room or globally. The provider help message will show you **🗲 Quick start** commands, but you may also send a `%command_prefix% agent` command to see the guide. -3. 🤝 **Set the new agent as a handler** for a given use-purpose like text-generation, image-generation, etc. The agent-creation wizard will tell you how, but you may also send a `%command_prefix% config` command to see the guide (in the *🤖 Handler Agents* section). +2. 🤖 %create_one_or_more_agents% +3. 🤝 %set_new_agent_as_handler% 4. 👋 %send_a_message% 5. 📖 %learn_more% "#; @@ -160,6 +160,14 @@ fn make_use_of_me_agent_creation( "%learn_more%", &learn_more_from_usage_or_help(command_prefix), ) + .replace( + "%create_one_or_more_agents%", + &create_one_or_more_agents(command_prefix), + ) + .replace( + "%set_new_agent_as_handler%", + &set_new_agent_as_handler(command_prefix), + ) } fn send_a_text_message( @@ -181,3 +189,11 @@ fn learn_more_from_usage_or_help(command_prefix: &str) -> String { "**Learn more** by sending a `{command_prefix} usage` or `{command_prefix} help` command." ) } + +pub fn create_one_or_more_agents(command_prefix: &str) -> String { + format!("**Create one or more agents** in this room or globally. The provider help message will show you **🗲 Quick start** commands, but you may also send a `{command_prefix} agent` command to see the guide.") +} + +pub fn set_new_agent_as_handler(command_prefix: &str) -> String { + format!("**Set the new agent as a handler** for a given use-purpose like text-generation, image-generation, etc. The agent-creation wizard will tell you how, but you may also send a `{command_prefix} config` command to see the guide (in the 🤖 *Handler Agents* section).") +} diff --git a/src/strings/provider.rs b/src/strings/provider.rs index a550a1b..7706bbf 100644 --- a/src/strings/provider.rs +++ b/src/strings/provider.rs @@ -25,10 +25,6 @@ pub fn invalid_configuration_for_provider( ) } -pub fn not_allowed() -> String { - "You are not allowed to see the providers list.".to_owned() -} - pub fn providers_list_intro() -> String { "The list of supported providers is below.".to_owned() } @@ -39,7 +35,7 @@ pub fn help_how_to_choose_heading() -> String { pub fn help_how_to_choose_description(command_prefix: &str) -> String { let str = r#" -If you're not sure which provider to start with, we **recommend OpenAI** as it's the most popular and has the **widest range of capabilities**. +If you're not sure which provider to start with, **we recommend OpenAI** as it's the most popular and has the **widest range of capabilities**. You don't need to choose just one though. The bot supports **mixing & matching models** (by setting different handlers for different types of messages - see `%command_prefix% config`), so you can use multiple providers at the same time. "#; @@ -55,13 +51,21 @@ pub fn help_how_to_use_heading() -> String { pub fn help_how_to_use_description(command_prefix: &str) -> String { let str = r#" -- sign up for it -- obtain an API key -- create a new agent (see `%command_prefix% agent`) -- set the new agent as a handler for some types of messages (see `%command_prefix% config`) +1. 📝 **Sign up for it** +2. 🔑 **Obtain an API key** +3. 🤖 %create_one_or_more_agents% +4. 🤝 %set_new_agent_as_handler% "#; str.replace("%command_prefix%", command_prefix) + .replace( + "%create_one_or_more_agents%", + &super::introduction::create_one_or_more_agents(command_prefix), + ) + .replace( + "%set_new_agent_as_handler%", + &super::introduction::set_new_agent_as_handler(command_prefix), + ) .trim() .to_owned() } diff --git a/src/strings/usage.rs b/src/strings/usage.rs index 5d6f8ef..0115bb4 100644 --- a/src/strings/usage.rs +++ b/src/strings/usage.rs @@ -12,7 +12,7 @@ If there's a text-generation handler agent configured (see `%command_prefix% con Whether the bot responds depends on the **đŸ’Ŧ Text Generation / 🗟 Prefix Requirement** setting (see `%command_prefix% config status`). Sometimes, a prefix (e.g. `%command_prefix%`) is required in front of messages sent to the room for the bot to respond. -For multi-user rooms, this setting defaults to "required" +For multi-user rooms, this setting defaults to "required". Room messages start a threaded conversation where you can continue back-and-forth communication with the bot.