Skip to content

Commit

Permalink
- fix: removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
agallardol committed Nov 28, 2024
1 parent ff771b4 commit 3dda35e
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 111 deletions.
2 changes: 1 addition & 1 deletion apps/shinkai-tool-aave-state/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Deno.test({
name: 'echo',
sanitizeResources: false,
sanitizeOps: false,
ignore: Deno.build.os === 'windows',
ignore: Deno.env.get('CI') === 'true' || Deno.build.os === 'windows',
fn: async () => {
const result = await run(
{
Expand Down
26 changes: 0 additions & 26 deletions libs/shinkai-tools-runner/src/built_in_tools.test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,6 @@ use crate::{
tools::code_files::CodeFiles,
};

#[tokio::test]
async fn get_tools_all_load() {
let _ = env_logger::builder()
.filter_level(log::LevelFilter::Info)
.is_test(true)
.try_init();
let tools = get_tools();
for (tool_name, tool_definition) in tools {
println!("creating tool instance for {}", tool_name);
let code_files = CodeFiles {
files: HashMap::from([("main.ts".to_string(), tool_definition.code.unwrap())]),
entrypoint: "main.ts".to_string(),
};
let tool_instance = crate::tools::tool::Tool::new(code_files, Value::Null, None);
println!("fetching definition for {}", tool_name);
let defintion = tool_instance.definition().await;
println!(
"definition load successfully for {}: {:?}",
tool_name,
defintion.clone().unwrap().id
);
assert_eq!(defintion.as_ref().unwrap().id, tool_name);
assert!(defintion.is_ok(), "tool {} failed to load", tool_name);
}
}

#[tokio::test]
async fn list_tools_count() {
assert!(get_tools().len() >= 5);
Expand Down
51 changes: 0 additions & 51 deletions libs/shinkai-tools-runner/src/tools/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,6 @@ impl Tool {
}
}

pub async fn definition(&self) -> Result<ToolDefinition, ExecutionError> {
log::info!("preparing to get tool definition from code");

let mut deno_runner = DenoRunner::new(self.deno_runner_options.clone());

let mut code = self.code.clone();
let entrypoint_code = code.files.get(&self.code.entrypoint.clone());
if let Some(entrypoint_code) = entrypoint_code {
let adapted_entrypoint_code = format!(
r#"
{}
console.log("<shinkai-tool-definition>");
console.log(JSON.stringify(definition));
console.log("</shinkai-tool-definition>");
"#,
entrypoint_code
);
code.files.insert(
self.code.entrypoint.clone(),
adapted_entrypoint_code.clone(),
);
}

let result = deno_runner
.run(code, None, None)
.await
.map_err(|e| ExecutionError::new(format!("failed to run deno: {}", e), None))?;

let result_text = result
.iter()
.skip_while(|line| !line.contains("<shinkai-tool-definition>"))
.skip(1)
.take_while(|line| !line.contains("</shinkai-tool-definition>"))
.map(|s| s.to_string())
.collect::<Vec<String>>()
.join("\n");

log::info!("result text: {}", result_text);

let tool_definition: ToolDefinition = serde_json::from_str(&result_text).map_err(|e| {
log::info!("failed to parse tool definition: {}", e);
ExecutionError::new(format!("failed to parse tool definition: {}", e), None)
})?;

log::info!(
"successfully retrieved tool definition: {:?}",
tool_definition
);
Ok(tool_definition)
}

pub async fn check(&self) -> anyhow::Result<Vec<String>> {
let mut deno_runner = DenoRunner::new(self.deno_runner_options.clone());
let code = self.code.clone();
Expand Down
33 changes: 0 additions & 33 deletions libs/shinkai-tools-runner/src/tools/tool.test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,6 @@ use crate::tools::{
tool::Tool,
};

#[rstest]
#[case::host(RunnerType::Host)]
#[case::docker(RunnerType::Docker)]
#[tokio::test]
async fn get_tool_definition(#[case] runner_type: RunnerType) {
// Just for a simple test, it could be any tool
let code = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../apps/shinkai-tool-echo/src/index.ts"
))
.to_string();

let code_files = CodeFiles {
files: HashMap::from([("main.ts".to_string(), code.to_string())]),
entrypoint: "main.ts".to_string(),
};

let configurations = serde_json::json!({});

let tool = Tool::new(
code_files,
configurations,
Some(DenoRunnerOptions {
force_runner_type: Some(runner_type),
..Default::default()
}),
);

let definition = tool.definition().await.unwrap();

assert_eq!(definition.id, "shinkai-tool-echo");
}

#[rstest]
#[case::host(RunnerType::Host)]
#[case::docker(RunnerType::Docker)]
Expand Down

0 comments on commit 3dda35e

Please sign in to comment.