Skip to content

Commit

Permalink
Add tool_description method to integration modules (#491)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JegernOUTT authored Dec 12, 2024
1 parent e837628 commit d327b1b
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 8 deletions.
37 changes: 33 additions & 4 deletions src/integrations/docker/integr_docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -182,14 +182,43 @@ impl Tool for ToolDocker {
fn confirmation_info(&self) -> Option<IntegrationConfirmation> {
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_id>",
"container start <container_id>",
"container stop <container_id>",
"container remove --volumes <container_id>",
"container kill <container_id>",
"container create --name=<name> --volume=<host_path>:<container_path> --publish=<host_port>:<container_port> --entrypoint <entrypoint> <image_id> -c <command>",
"image build -t <tag> <path>",
"network create <name>",
"volume create <name>",
"run -d --name <name> <image>",
"..."
];
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<String, Value>) -> Result<String, String>{
return match args.get("command") {
fn parse_command(args: &HashMap<String, Value>) -> Result<String, String> {
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<Vec<String>, String> {
Expand Down
30 changes: 29 additions & 1 deletion src/integrations/integr_github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -153,6 +153,34 @@ impl Tool for ToolGithub {
fn confirmation_info(&self) -> Option<IntegrationConfirmation> {
Some(self.integr_common().confirmation)
}

fn tool_description(&self) -> ToolDesc {
let supported_commands = vec![
"issue create --title <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> {
Expand Down
30 changes: 29 additions & 1 deletion src/integrations/integr_gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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> {
Expand Down
27 changes: 26 additions & 1 deletion src/integrations/integr_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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#"
Expand Down
27 changes: 26 additions & 1 deletion src/integrations/integr_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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#"
Expand Down

0 comments on commit d327b1b

Please sign in to comment.