From d72dad579716a9202cd6b23fe5fd7b88025ba949 Mon Sep 17 00:00:00 2001 From: JegernOUTT Date: Thu, 12 Dec 2024 23:03:45 +1030 Subject: [PATCH] Add `tool_description` method to integration modules Enhance the MySQL, PostgreSQL, GitHub, GitLab, and Docker integration modules by adding a `tool_description` method. This method provides metadata about the tool including name, description, parameters, and example commands, improving usability and documentation across integrations. --- src/integrations/docker/integr_docker.rs | 37 +++++++++++++++++++++--- src/integrations/integr_github.rs | 30 ++++++++++++++++++- src/integrations/integr_gitlab.rs | 30 ++++++++++++++++++- src/integrations/integr_mysql.rs | 27 ++++++++++++++++- src/integrations/integr_postgres.rs | 27 ++++++++++++++++- 5 files changed, 143 insertions(+), 8 deletions(-) diff --git a/src/integrations/docker/integr_docker.rs b/src/integrations/docker/integr_docker.rs index 6f35ebeaf..318706b82 100644 --- a/src/integrations/docker/integr_docker.rs +++ b/src/integrations/docker/integr_docker.rs @@ -10,7 +10,7 @@ use crate::at_commands::at_commands::AtCommandsContext; use crate::call_validation::{ChatContent, ChatMessage, ContextEnum}; use crate::global_context::GlobalContext; use crate::integrations::integr_abstract::{IntegrationTrait, IntegrationCommon, IntegrationConfirmation}; -use crate::tools::tools_description::Tool; +use crate::tools::tools_description::{Tool, ToolDesc, ToolParam}; use crate::integrations::docker::docker_ssh_tunnel_utils::{SshConfig, forward_remote_docker_if_needed}; use crate::integrations::utils::{serialize_num_to_str, deserialize_str_to_num}; @@ -182,14 +182,43 @@ impl Tool for ToolDocker { fn confirmation_info(&self) -> Option { Some(self.integr_common().confirmation) } + + fn tool_description(&self) -> ToolDesc { + let supported_commands = vec![ + "container list --all --no-trunc --format json", + "container inspect --format json ", + "container start ", + "container stop ", + "container remove --volumes ", + "container kill ", + "container create --name= --volume=: --publish=: --entrypoint -c ", + "image build -t ", + "network create ", + "volume create ", + "run -d --name ", + "..." + ]; + ToolDesc { + name: "docker".to_string(), + agentic: true, + experimental: false, + description: "Access to docker cli, in a non-interactive way, don't open a shell.".to_string(), + parameters: vec![ToolParam { + name: "command".to_string(), + param_type: "string".to_string(), + description: format!("A docker command. Example commands:\n{}", supported_commands.join("\n")) + }], + parameters_required: vec!["command".to_string()], + } + } } -fn parse_command(args: &HashMap) -> Result{ - return match args.get("command") { +fn parse_command(args: &HashMap) -> Result { + match args.get("command") { Some(Value::String(s)) => Ok(s.to_string()), Some(v) => Err(format!("argument `command` is not a string: {:?}", v)), None => Err("Missing argument `command`".to_string()) - }; + } } fn split_command(command: &str) -> Result, String> { diff --git a/src/integrations/integr_github.rs b/src/integrations/integr_github.rs index a0ab4e861..9a3fd495d 100644 --- a/src/integrations/integr_github.rs +++ b/src/integrations/integr_github.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use crate::at_commands::at_commands::AtCommandsContext; use crate::call_validation::{ContextEnum, ChatMessage, ChatContent, ChatUsage}; -use crate::tools::tools_description::Tool; +use crate::tools::tools_description::{Tool, ToolDesc, ToolParam}; use serde_json::Value; use crate::integrations::integr_abstract::{IntegrationCommon, IntegrationConfirmation, IntegrationTrait}; @@ -153,6 +153,34 @@ impl Tool for ToolGithub { fn confirmation_info(&self) -> Option { Some(self.integr_common().confirmation) } + + fn tool_description(&self) -> ToolDesc { + let supported_commands = vec![ + "issue create --title --body <body>", + "issue list --state open --label <label>", + "pr create --title <title> --body <body> --base <branch> --head <branch>", + "pr list --state open --label <label>", + "repo clone <repository>", + "repo create <name> --public", + "repo fork <repository>", + "repo list", + "workflow run <workflow_id>", + "workflow list", + "..." + ]; + ToolDesc { + name: "github".to_string(), + agentic: true, + experimental: false, + description: "Access to GitHub CLI for various GitHub operations such as creating issues, pull requests, and more.".to_string(), + parameters: vec![ToolParam { + name: "command".to_string(), + param_type: "string".to_string(), + description: format!("A GitHub CLI command. Example commands:\n{}", supported_commands.join("\n")) + }], + parameters_required: vec!["command".to_string()], + } + } } fn parse_command_args(args: &HashMap<String, Value>) -> Result<Vec<String>, String> { diff --git a/src/integrations/integr_gitlab.rs b/src/integrations/integr_gitlab.rs index 0b4c720f9..2059ecfaf 100644 --- a/src/integrations/integr_gitlab.rs +++ b/src/integrations/integr_gitlab.rs @@ -9,7 +9,7 @@ use serde_json::Value; use crate::at_commands::at_commands::AtCommandsContext; use crate::call_validation::{ContextEnum, ChatMessage, ChatContent, ChatUsage}; -use crate::tools::tools_description::Tool; +use crate::tools::tools_description::{Tool, ToolDesc, ToolParam}; use crate::integrations::integr_abstract::{IntegrationCommon, IntegrationConfirmation, IntegrationTrait}; #[derive(Clone, Serialize, Deserialize, Debug, Default)] @@ -151,6 +151,34 @@ impl Tool for ToolGitlab { fn confirmation_info(&self) -> Option<IntegrationConfirmation> { Some(self.integr_common().confirmation) } + + fn tool_description(&self) -> ToolDesc { + let supported_commands = vec![ + "issue create --title <title> --description <description>", + "issue list --state opened --label <label>", + "mr create --title <title> --description <description> --source-branch <branch> --target-branch <branch>", + "mr list --state opened --label <label>", + "repo clone <repository>", + "repo create <name> --visibility public", + "repo fork <repository>", + "repo list", + "pipeline run <pipeline_id>", + "pipeline list", + "..." + ]; + ToolDesc { + name: "gitlab".to_string(), + agentic: true, + experimental: false, + description: "Access to GitLab CLI for various GitLab operations such as creating issues, merge requests, and more.".to_string(), + parameters: vec![ToolParam { + name: "command".to_string(), + param_type: "string".to_string(), + description: format!("A GitLab CLI command. Example commands:\n{}", supported_commands.join("\n")) + }], + parameters_required: vec!["command".to_string()], + } + } } fn parse_command_args(args: &HashMap<String, Value>) -> Result<Vec<String>, String> { diff --git a/src/integrations/integr_mysql.rs b/src/integrations/integr_mysql.rs index 912e46328..6f67c970a 100644 --- a/src/integrations/integr_mysql.rs +++ b/src/integrations/integr_mysql.rs @@ -2,7 +2,7 @@ use crate::at_commands::at_commands::AtCommandsContext; use crate::call_validation::ContextEnum; use crate::call_validation::{ChatContent, ChatMessage, ChatUsage}; use crate::integrations::go_to_configuration_message; -use crate::tools::tools_description::Tool; +use crate::tools::tools_description::{Tool, ToolDesc, ToolParam}; use async_trait::async_trait; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -166,6 +166,31 @@ impl Tool for ToolMysql { fn confirmation_info(&self) -> Option<IntegrationConfirmation> { Some(self.integr_common().confirmation) } + + fn tool_description(&self) -> ToolDesc { + let supported_commands = vec![ + "SHOW DATABASES;", + "SHOW TABLES;", + "SELECT * FROM <table_name>;", + "INSERT INTO <table_name> (column1, column2) VALUES (value1, value2);", + "UPDATE <table_name> SET column1 = value1 WHERE condition;", + "DELETE FROM <table_name> WHERE condition;", + "CREATE TABLE <table_name> (column1 datatype, column2 datatype, ...);", + "..." + ]; + ToolDesc { + name: "mysql".to_string(), + agentic: true, + experimental: false, + description: "Access to MySQL database for various operations such as querying data, inserting, updating, and deleting records.".to_string(), + parameters: vec![ToolParam { + name: "query".to_string(), + param_type: "string".to_string(), + description: format!("A MySQL query. Example queries:\n{}", supported_commands.join("\n")) + }], + parameters_required: vec!["query".to_string()], + } + } } pub const MYSQL_INTEGRATION_SCHEMA: &str = r#" diff --git a/src/integrations/integr_postgres.rs b/src/integrations/integr_postgres.rs index d84e8700d..9ec81244e 100644 --- a/src/integrations/integr_postgres.rs +++ b/src/integrations/integr_postgres.rs @@ -2,7 +2,7 @@ use crate::at_commands::at_commands::AtCommandsContext; use crate::call_validation::ContextEnum; use crate::call_validation::{ChatContent, ChatMessage, ChatUsage}; use crate::integrations::go_to_configuration_message; -use crate::tools::tools_description::Tool; +use crate::tools::tools_description::{Tool, ToolDesc, ToolParam}; use async_trait::async_trait; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -165,6 +165,31 @@ impl Tool for ToolPostgres { fn confirmation_info(&self) -> Option<IntegrationConfirmation> { Some(self.integr_common().confirmation) } + + fn tool_description(&self) -> ToolDesc { + let supported_commands = vec![ + "SELECT * FROM <table_name>;", + "INSERT INTO <table_name> (column1, column2) VALUES (value1, value2);", + "UPDATE <table_name> SET column1 = value1 WHERE condition;", + "DELETE FROM <table_name> WHERE condition;", + "CREATE TABLE <table_name> (column1 datatype, column2 datatype, ...);", + "ALTER TABLE <table_name> ADD COLUMN <column_name> <datatype>;", + "ALTER TABLE <table_name> DROP COLUMN <column_name>;", + "..." + ]; + ToolDesc { + name: "postgres".to_string(), + agentic: true, + experimental: false, + description: "Access to PostgreSQL database for various operations such as querying data, inserting, updating, and deleting records.".to_string(), + parameters: vec![ToolParam { + name: "query".to_string(), + param_type: "string".to_string(), + description: format!("A PostgreSQL query. Example queries:\n{}", supported_commands.join("\n")) + }], + parameters_required: vec!["query".to_string()], + } + } } pub const POSTGRES_INTEGRATION_SCHEMA: &str = r#"