Allow regular (unprivileged) users to see providers help and adapt it to them

This commit is contained in:
Slavi Pantaleev
2024-09-19 13:39:52 +03:00
parent e3b07aa291
commit f6cc8363d1
8 changed files with 69 additions and 58 deletions

View File

@@ -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

View File

@@ -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");

View File

@@ -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(),

View File

@@ -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");
}

View File

@@ -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 {

View File

@@ -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).")
}

View File

@@ -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()
}

View File

@@ -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.