diff --git a/api/src/utils/tools/create_files.rs b/api/src/utils/tools/create_files.rs deleted file mode 100644 index 321441a4f..000000000 --- a/api/src/utils/tools/create_files.rs +++ /dev/null @@ -1,50 +0,0 @@ -use anyhow::Result; -use async_trait::async_trait; -use serde_json::Value; -use serde::{Deserialize, Serialize}; - -use crate::utils::{clients::ai::litellm::ToolCall, tools::ToolExecutor}; - -#[derive(Debug, Serialize, Deserialize)] -struct CreateFilesParams { - names: Vec, - yml_content: String, -} - -pub struct CreateFilesTool; - -#[async_trait] -impl ToolExecutor for CreateFilesTool { - async fn execute(&self, tool_call: &ToolCall) -> Result { - let params: CreateFilesParams = serde_json::from_str(&tool_call.function.arguments.clone())?; - // TODO: Implement actual file creation logic - Ok(Value::Array(vec![])) - } - - fn get_schema(&self) -> Value { - serde_json::json!({ - "name": "create_files", - "strict": true, - "parameters": { - "type": "object", - "required": ["names", "yml_content"], - "properties": { - "names": { - "type": "array", - "items": { - "type": "string", - "description": "The name of a metric or dashboard file to be created" - }, - "description": "An array of names for the metric or dashboard files to be created" - }, - "yml_content": { - "type": "string", - "description": "The YAML content to be included in the created files" - } - }, - "additionalProperties": false - }, - "description": "Creates **new** metric or dashboard files by name. Use this if no existing file can fulfill the user's needs. This will automatically open the metric/dashboard for the user." - }) - } -} \ No newline at end of file diff --git a/api/src/utils/tools/bulk_modify_files.rs b/api/src/utils/tools/file_tools/bulk_modify_files.rs similarity index 97% rename from api/src/utils/tools/bulk_modify_files.rs rename to api/src/utils/tools/file_tools/bulk_modify_files.rs index 539dc8d33..be1cc9f2c 100644 --- a/api/src/utils/tools/bulk_modify_files.rs +++ b/api/src/utils/tools/file_tools/bulk_modify_files.rs @@ -26,6 +26,10 @@ pub struct BulkModifyFilesTool; #[async_trait] impl ToolExecutor for BulkModifyFilesTool { + fn get_name(&self) -> String { + "bulk_modify_files".to_string() + } + async fn execute(&self, tool_call: &ToolCall) -> Result { let params: BulkModifyFilesParams = serde_json::from_str(&tool_call.function.arguments.clone())?; // TODO: Implement actual file modification logic diff --git a/api/src/utils/tools/file_tools/create_files.rs b/api/src/utils/tools/file_tools/create_files.rs new file mode 100644 index 000000000..430fdf4f2 --- /dev/null +++ b/api/src/utils/tools/file_tools/create_files.rs @@ -0,0 +1,73 @@ +use anyhow::Result; +use async_trait::async_trait; +use serde::{Deserialize, Serialize}; +use serde_json::Value; + +use crate::utils::{clients::ai::litellm::ToolCall, tools::ToolExecutor}; + +#[derive(Debug, Serialize, Deserialize)] +struct FileParams { + name: String, + file_type: String, + yml_content: String, +} + +#[derive(Debug, Serialize, Deserialize)] +struct CreateFilesParams { + files: Vec, +} + +pub struct CreateFilesTool; + +#[async_trait] +impl ToolExecutor for CreateFilesTool { + fn get_name(&self) -> String { + "create_files".to_string() + } + + async fn execute(&self, tool_call: &ToolCall) -> Result { + let params: CreateFilesParams = + serde_json::from_str(&tool_call.function.arguments.clone())?; + + Ok(Value::Array(vec![])) + } + + fn get_schema(&self) -> Value { + serde_json::json!({ + "name": "create_files", + "strict": true, + "parameters": { + "type": "object", + "required": ["files"], + "properties": { + "files": { + "type": "array", + "items": { + "type": "object", + "required": ["name", "file_type", "yml_content"], + "properties": { + "name": { + "type": "string", + "description": "The name of the file to be created" + }, + "file_type": { + "type": "string", + "enum": ["metric", "dashboard"], + "description": "The type of file to create" + }, + "yml_content": { + "type": "string", + "description": "The YAML content to be included in the created file" + } + }, + "additionalProperties": false + }, + "description": "Array of files to create" + } + }, + "additionalProperties": false + }, + "description": "Creates **new** metric or dashboard files. Use this if no existing file can fulfill the user's needs. This will automatically open the metric/dashboard for the user." + }) + } +} diff --git a/api/src/utils/tools/file_tools/mod.rs b/api/src/utils/tools/file_tools/mod.rs new file mode 100644 index 000000000..ccb7336a6 --- /dev/null +++ b/api/src/utils/tools/file_tools/mod.rs @@ -0,0 +1,15 @@ +mod bulk_modify_files; +mod create_files; +mod open_files; +mod search_data_catalog; +mod search_files; +mod send_to_user; +mod types; + +pub use bulk_modify_files::BulkModifyFilesTool; +pub use create_files::CreateFilesTool; +pub use open_files::OpenFilesTool; +pub use search_data_catalog::SearchDataCatalogTool; +pub use search_files::SearchFilesTool; +pub use send_to_user::SendToUserTool; +pub use types::*; diff --git a/api/src/utils/tools/open_files.rs b/api/src/utils/tools/file_tools/open_files.rs similarity index 95% rename from api/src/utils/tools/open_files.rs rename to api/src/utils/tools/file_tools/open_files.rs index 97cf49bdd..b416d0248 100644 --- a/api/src/utils/tools/open_files.rs +++ b/api/src/utils/tools/file_tools/open_files.rs @@ -14,6 +14,10 @@ pub struct OpenFilesTool; #[async_trait] impl ToolExecutor for OpenFilesTool { + fn get_name(&self) -> String { + "open_files".to_string() + } + async fn execute(&self, tool_call: &ToolCall) -> Result { let params: OpenFilesParams = serde_json::from_str(&tool_call.function.arguments.clone())?; // TODO: Implement actual file opening logic diff --git a/api/src/utils/tools/search_data_catalog.rs b/api/src/utils/tools/file_tools/search_data_catalog.rs similarity index 96% rename from api/src/utils/tools/search_data_catalog.rs rename to api/src/utils/tools/file_tools/search_data_catalog.rs index 674f99c33..54d5a1991 100644 --- a/api/src/utils/tools/search_data_catalog.rs +++ b/api/src/utils/tools/file_tools/search_data_catalog.rs @@ -26,6 +26,10 @@ pub struct SearchDataCatalogTool; #[async_trait] impl ToolExecutor for SearchDataCatalogTool { + fn get_name(&self) -> String { + "search_data_catalog".to_string() + } + async fn execute(&self, tool_call: &ToolCall) -> Result { let params: SearchDataCatalogParams = serde_json::from_str(&tool_call.function.arguments.clone())?; // TODO: Implement actual data catalog search logic diff --git a/api/src/utils/tools/search_files.rs b/api/src/utils/tools/file_tools/search_files.rs similarity index 95% rename from api/src/utils/tools/search_files.rs rename to api/src/utils/tools/file_tools/search_files.rs index b56bb8c9f..6a8852bd0 100644 --- a/api/src/utils/tools/search_files.rs +++ b/api/src/utils/tools/file_tools/search_files.rs @@ -14,6 +14,10 @@ pub struct SearchFilesTool; #[async_trait] impl ToolExecutor for SearchFilesTool { + fn get_name(&self) -> String { + "search_files".to_string() + } + async fn execute(&self, tool_call: &ToolCall) -> Result { let params: SearchFilesParams = serde_json::from_str(&tool_call.function.arguments.clone())?; // TODO: Implement actual file search logic diff --git a/api/src/utils/tools/send_to_user.rs b/api/src/utils/tools/file_tools/send_to_user.rs similarity index 94% rename from api/src/utils/tools/send_to_user.rs rename to api/src/utils/tools/file_tools/send_to_user.rs index 4f53c3512..34979a56e 100644 --- a/api/src/utils/tools/send_to_user.rs +++ b/api/src/utils/tools/file_tools/send_to_user.rs @@ -14,6 +14,10 @@ pub struct SendToUserTool; #[async_trait] impl ToolExecutor for SendToUserTool { + fn get_name(&self) -> String { + "send_to_user".to_string() + } + async fn execute(&self, tool_call: &ToolCall) -> Result { let params: SendToUserParams = serde_json::from_str(&tool_call.function.arguments.clone())?; // TODO: Implement actual send to user logic diff --git a/api/src/utils/tools/file_tools/types.rs b/api/src/utils/tools/file_tools/types.rs new file mode 100644 index 000000000..e873ec653 --- /dev/null +++ b/api/src/utils/tools/file_tools/types.rs @@ -0,0 +1,9 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize)] +pub struct File { + pub name: String, + #[serde(rename = "type")] + pub file_type: String, + pub yml_content: String, +} diff --git a/api/src/utils/tools/mod.rs b/api/src/utils/tools/mod.rs index ec43f5e85..6294617af 100644 --- a/api/src/utils/tools/mod.rs +++ b/api/src/utils/tools/mod.rs @@ -4,19 +4,7 @@ use serde_json::Value; use crate::utils::clients::ai::litellm::ToolCall; -// mod bulk_modify_files; -// mod create_files; -// mod open_files; -// mod search_data_catalog; -// mod search_files; -// mod send_to_user; - -// pub use bulk_modify_files::BulkModifyFilesTool; -// pub use create_files::CreateFilesTool; -// pub use open_files::OpenFilesTool; -// pub use search_data_catalog::SearchDataCatalogTool; -// pub use search_files::SearchFilesTool; -// pub use send_to_user::SendToUserTool; +pub mod file_tools; /// A trait that defines how tools should be implemented. /// Any struct that wants to be used as a tool must implement this trait.