Skip to content

Commit

Permalink
Merge pull request #749 from dcSpark/nico/bump_code_runner
Browse files Browse the repository at this point in the history
bump code runner and filter out demo tools
  • Loading branch information
nicarq authored Dec 22, 2024
2 parents b900bcd + ffc78bf commit 096ad6f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ chrono = "0.4"
serde_json = "1.0.117"
anyhow = "1.0"
blake3 = "1.2.0"
shinkai_tools_runner = "0.9.5"
shinkai_tools_runner = "0.9.6"
serde = "1.0.188"
base64 = "0.22.0"
reqwest = "0.11.27"
Expand Down
84 changes: 41 additions & 43 deletions shinkai-bin/shinkai-node/src/managers/tool_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,49 +69,7 @@ impl ToolRouter {
.map_err(|e| ToolError::DatabaseError(e.to_string()))?;
}

// Import tools
async fn import_tools_from_directory(db: Arc<SqliteManager>) -> Result<(), ToolError> {
let url = env::var("SHINKAI_TOOLS_DIRECTORY_URL")
.map_err(|_| ToolError::MissingConfigError("SHINKAI_TOOLS_DIRECTORY_URL not set".to_string()))?;

let response = reqwest::get(url)
.await
.map_err(|e| ToolError::RequestError(e))?;

if response.status() != 200 {
return Err(ToolError::ExecutionError(format!("Import tools request returned a non OK status: {}", response.status())));
}

let tools: Vec<serde_json::Value> = response
.json()
.await
.map_err(|e| ToolError::ParseError(format!("Failed to parse tools directory: {}", e)))?;

for tool in tools {
let tool_url = tool["file"]
.as_str()
.ok_or_else(|| ToolError::ParseError("Missing or invalid file URL in tool definition".to_string()))?;

let tool_name = tool["name"]
.as_str()
.unwrap_or("unknown");

match Node::v2_api_import_tool_internal(
db.clone(),
fetch_node_environment(),
tool_url.to_string(),
)
.await
{
Ok(_) => println!("Successfully imported tool {}", tool_name),
Err(e) => eprintln!("Failed to import tool {}: {:#?}", tool_name, e),
}
}

Ok(())
}

if let Err(e) = import_tools_from_directory(self.sqlite_manager.clone()).await {
if let Err(e) = Self::import_tools_from_directory(self.sqlite_manager.clone()).await {
eprintln!("Error importing tools from directory: {}", e);
}

Expand Down Expand Up @@ -142,6 +100,40 @@ impl ToolRouter {
Ok(())
}

async fn import_tools_from_directory(db: Arc<SqliteManager>) -> Result<(), ToolError> {
let url = env::var("SHINKAI_TOOLS_DIRECTORY_URL")
.map_err(|_| ToolError::MissingConfigError("SHINKAI_TOOLS_DIRECTORY_URL not set".to_string()))?;

let response = reqwest::get(url).await.map_err(|e| ToolError::RequestError(e))?;

if response.status() != 200 {
return Err(ToolError::ExecutionError(format!(
"Import tools request returned a non OK status: {}",
response.status()
)));
}

let tools: Vec<serde_json::Value> = response
.json()
.await
.map_err(|e| ToolError::ParseError(format!("Failed to parse tools directory: {}", e)))?;

for tool in tools {
let tool_url = tool["file"]
.as_str()
.ok_or_else(|| ToolError::ParseError("Missing or invalid file URL in tool definition".to_string()))?;

let tool_name = tool["name"].as_str().unwrap_or("unknown");

match Node::v2_api_import_tool_internal(db.clone(), fetch_node_environment(), tool_url.to_string()).await {
Ok(_) => println!("Successfully imported tool {}", tool_name),
Err(e) => eprintln!("Failed to import tool {}: {:#?}", tool_name, e),
}
}

Ok(())
}

pub async fn add_static_prompts(&self, _generator: &Box<dyn EmbeddingGenerator>) -> Result<(), ToolError> {
// Check if ONLY_TESTING_PROMPTS is set
if env::var("ONLY_TESTING_PROMPTS").unwrap_or_default() == "1"
Expand Down Expand Up @@ -224,9 +216,15 @@ impl ToolRouter {

{
for (name, definition) in tools {
// Skip tools that start with "demo" if not only_testing_js_tools
if !only_testing_js_tools && name.starts_with("demo") {
continue;
}
// Skip tools that are not in the allowed list if only_testing_js_tools is true
if only_testing_js_tools && !allowed_tools.contains(&name.as_str()) {
continue; // Skip tools that are not in the allowed list
}

println!("Adding JS tool: {}", name);

let toolkit = JSToolkit::new(&name, vec![definition.clone()]);
Expand Down

0 comments on commit 096ad6f

Please sign in to comment.