feat: 添加文件读取工具的字符截断逻辑,记录截断字符数量
This commit is contained in:
parent
4473c9fc47
commit
03c95e6b8f
@ -179,6 +179,7 @@ impl Tool for FileReadTool {
|
|||||||
|
|
||||||
// Truncate if too long
|
// Truncate if too long
|
||||||
if result.len() > MAX_CHARS {
|
if result.len() > MAX_CHARS {
|
||||||
|
let original_len = result.len();
|
||||||
let mut truncated_chars = 0;
|
let mut truncated_chars = 0;
|
||||||
let mut end_idx = 0;
|
let mut end_idx = 0;
|
||||||
for (i, line) in lines.iter().enumerate() {
|
for (i, line) in lines.iter().enumerate() {
|
||||||
@ -190,9 +191,10 @@ impl Tool for FileReadTool {
|
|||||||
end_idx = i + 1;
|
end_idx = i + 1;
|
||||||
}
|
}
|
||||||
result = lines[..end_idx].join("\n");
|
result = lines[..end_idx].join("\n");
|
||||||
|
let truncated_amount = original_len - result.len();
|
||||||
result.push_str(&format!(
|
result.push_str(&format!(
|
||||||
"\n\n... ({} chars truncated) ...",
|
"\n\n... ({} chars truncated) ...",
|
||||||
result.len() - MAX_CHARS
|
truncated_amount
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user