mirror of https://github.com/buster-so/buster.git
refactor: Consolidate file-related tools into a single module
- Removed individual tool files for bulk file modifications, file creation, file opening, data catalog search, file search, and sending to user - Created a new `file_tools` module in `tools/mod.rs` to centralize file-related tool implementations - Commented out individual tool module imports in preparation for future implementation - Simplified the tools module structure for better organization and maintainability
This commit is contained in:
parent
ec04a5e98e
commit
7d153e06af
|
@ -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<String>,
|
||||
yml_content: String,
|
||||
}
|
||||
|
||||
pub struct CreateFilesTool;
|
||||
|
||||
#[async_trait]
|
||||
impl ToolExecutor for CreateFilesTool {
|
||||
async fn execute(&self, tool_call: &ToolCall) -> Result<Value> {
|
||||
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."
|
||||
})
|
||||
}
|
||||
}
|
|
@ -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<Value> {
|
||||
let params: BulkModifyFilesParams = serde_json::from_str(&tool_call.function.arguments.clone())?;
|
||||
// TODO: Implement actual file modification logic
|
|
@ -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<FileParams>,
|
||||
}
|
||||
|
||||
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<Value> {
|
||||
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."
|
||||
})
|
||||
}
|
||||
}
|
|
@ -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::*;
|
|
@ -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<Value> {
|
||||
let params: OpenFilesParams = serde_json::from_str(&tool_call.function.arguments.clone())?;
|
||||
// TODO: Implement actual file opening logic
|
|
@ -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<Value> {
|
||||
let params: SearchDataCatalogParams = serde_json::from_str(&tool_call.function.arguments.clone())?;
|
||||
// TODO: Implement actual data catalog search logic
|
|
@ -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<Value> {
|
||||
let params: SearchFilesParams = serde_json::from_str(&tool_call.function.arguments.clone())?;
|
||||
// TODO: Implement actual file search logic
|
|
@ -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<Value> {
|
||||
let params: SendToUserParams = serde_json::from_str(&tool_call.function.arguments.clone())?;
|
||||
// TODO: Implement actual send to user logic
|
|
@ -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,
|
||||
}
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue