Skip to content

Commit 1083d40

Browse files
fix: Improve the use_aws tool specification (#668)
1 parent fe8b4ad commit 1083d40

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

crates/q_cli/src/cli/chat/tools/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ pub fn serde_value_to_document(value: serde_json::Value) -> Document {
185185
}
186186
}
187187

188+
#[allow(dead_code)]
189+
fn path_expand(_ctx: &Context, _path: impl AsRef<Path>) -> PathBuf {
190+
PathBuf::new()
191+
}
192+
188193
/// Converts `path` to a relative path according to the current working directory `cwd`.
189194
fn absolute_to_relative(cwd: impl AsRef<Path>, path: impl AsRef<Path>) -> Result<PathBuf> {
190195
let cwd = cwd.as_ref().canonicalize()?;

crates/q_cli/src/cli/chat/tools/tool_index.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
},
7676
{
7777
"name": "use_aws",
78-
"description": "Make an AWS api call with the specified service, operation, and parameters. You may not create resources or perform any write or mutating actions. You may only use this tool to call read operations with names that start with: get, describe, list, search, batch_get.",
78+
"description": "Make an AWS CLI api call with the specified service, operation, and parameters. The arguments MUST conform to the AWS CLI specification. You may not create resources or perform any write or mutating actions. You may only use this tool to call read operations with names that start with: get, describe, list, search, batch_get.",
7979
"input_schema": {
8080
"type": "object",
8181
"properties": {
@@ -85,11 +85,11 @@
8585
},
8686
"operation_name": {
8787
"type": "string",
88-
"description": "The name of the operation to perform. All of the operation name will be in kebab case. If incorrect operations are encountered, try different variation (e.g. if list-buckets is not correct, try ls)"
88+
"description": "The name of the operation to perform."
8989
},
9090
"parameters": {
9191
"type": "object",
92-
"description": "The parameters for the operation."
92+
"description": "The parameters for the operation. Each parameter must be encoded as a string."
9393
},
9494
"region": {
9595
"type": "string",
@@ -108,7 +108,6 @@
108108
"region",
109109
"service_name",
110110
"operation_name",
111-
"parameters",
112111
"label"
113112
]
114113
}

crates/q_cli/src/cli/chat/tools/use_aws.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl std::fmt::Display for AwsToolError {
4040
pub struct UseAws {
4141
pub service_name: String,
4242
pub operation_name: String,
43-
pub parameters: HashMap<String, String>,
43+
pub parameters: Option<HashMap<String, String>>,
4444
pub region: String,
4545
pub profile_name: Option<String>,
4646
pub label: Option<String>,
@@ -64,11 +64,13 @@ impl UseAws {
6464
command.arg("--profile").arg(profile_name);
6565
}
6666
command.arg(&self.service_name).arg(&self.operation_name);
67-
for (param_name, val) in &self.parameters {
68-
if param_name.starts_with("--") {
69-
command.arg(param_name).arg(val);
70-
} else {
71-
command.arg(format!("--{}", param_name)).arg(val);
67+
if let Some(parameters) = &self.parameters {
68+
for (param_name, val) in parameters {
69+
if param_name.starts_with("--") {
70+
command.arg(param_name).arg(val);
71+
} else {
72+
command.arg(format!("--{}", param_name)).arg(val);
73+
}
7274
}
7375
}
7476
let output = command
@@ -104,8 +106,10 @@ impl UseAws {
104106
style::Print(format!("Operation name: {}\n", self.operation_name)),
105107
style::Print("Parameters: \n".to_string()),
106108
)?;
107-
for (name, value) in &self.parameters {
108-
queue!(updates, style::Print(format!("{}: {}\n", name, value)))?;
109+
if let Some(parameters) = &self.parameters {
110+
for (name, value) in parameters {
111+
queue!(updates, style::Print(format!("{}: {}\n", name, value)))?;
112+
}
109113
}
110114

111115
if let Some(ref profile_name) = self.profile_name {

0 commit comments

Comments
 (0)