Skip to content

Commit

Permalink
- fix: stackoverflow when use download-page (#17)
Browse files Browse the repository at this point in the history
* - fix: stackoverflow error when use download page tool

* - fix: fix stackoverflow error when use download-page tool
  • Loading branch information
agallardol authored Jul 9, 2024
1 parent 771ba3a commit e1bd4cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions libs/shinkai-tools-runner/src/lib.test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,31 @@ async fn max_execution_time() {
assert!(elapsed_time.as_millis() <= 10050);
assert!(run_result.err().unwrap().message().contains("time reached"));
}

#[tokio::test]
async fn shinkai_tool_download_page_stack_overflow() {
let managed_thread = std::thread::Builder::new().stack_size(8 * 1024 * 1024);
let run_result = managed_thread
.spawn(move || {
let managed_runtime =
tokio::runtime::Runtime::new().expect("Failed to create Tokio runtime");
managed_runtime.block_on(async {
let tool_definition = get_tool("shinkai-tool-download-page").unwrap();
let mut tool = Tool::new();
let _ = tool
.load_from_code(&tool_definition.code.clone().unwrap(), "")
.await;
tool.run(
r#"{
"url": "https://en.wikipedia.org/wiki/Prospect_Park_(Brooklyn)"
}"#,
None,
)
.await
})
})
.unwrap()
.join()
.unwrap();
assert!(run_result.is_ok());
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Script {
Ok(wrapped_value) => {
if let Ok(Some(json_str)) = ctx.json_stringify(wrapped_value.as_ref()) {
let json_str: String = json_str.to_string().expect("Failed to convert to String"); // Convert to Rust String
println!("id:{} value from code execution result {}", id.clone(), json_str);
println!("id:{} value from code execution result {}", id.clone(), &json_str[..500.min(json_str.len())]);
}
let js_value = wrapped_value.get::<&str, Value>("value").map_err(|e| {
ExecutionError::new(e.to_string(), None)
Expand Down

0 comments on commit e1bd4cb

Please sign in to comment.