forked from 1jehuang/jcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.rs
More file actions
63 lines (61 loc) · 1.88 KB
/
tools.rs
File metadata and controls
63 lines (61 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::message::{ContentBlock, ToolCall};
use crate::tool::ToolOutput;
pub(super) fn tool_output_to_content_blocks(
tool_use_id: String,
output: ToolOutput,
) -> Vec<ContentBlock> {
let mut blocks = vec![ContentBlock::ToolResult {
tool_use_id,
content: output.output,
is_error: None,
}];
for img in output.images {
blocks.push(ContentBlock::Image {
media_type: img.media_type,
data: img.data,
});
if let Some(label) = img.label.filter(|label| !label.trim().is_empty()) {
blocks.push(ContentBlock::Text {
text: format!(
"[Attached image associated with the preceding tool result: {}]",
label
),
cache_control: None,
});
}
}
blocks
}
pub(super) fn print_tool_summary(tool: &ToolCall) {
match tool.name.as_str() {
"bash" => {
if let Some(cmd) = tool.input.get("command").and_then(|v| v.as_str()) {
let short = if cmd.len() > 60 {
format!("{}...", crate::util::truncate_str(cmd, 60))
} else {
cmd.to_string()
};
println!("$ {}", short);
}
}
"read" | "write" | "edit" => {
if let Some(path) = tool.input.get("file_path").and_then(|v| v.as_str()) {
println!("{}", path);
}
}
"glob" | "grep" => {
if let Some(pattern) = tool.input.get("pattern").and_then(|v| v.as_str()) {
println!("'{}'", pattern);
}
}
"ls" => {
let path = tool
.input
.get("path")
.and_then(|v| v.as_str())
.unwrap_or(".");
println!("{}", path);
}
_ => {}
}
}