Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Version #756

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ impl SheetRustFunctions {
ToolOutputArg::empty(),
None,
"local:::rust_toolkit:::shinkai_sheet_ui_create_new_column_with_values".to_string(),
Some(1_000_000),
);

// Add the tool definition for update_column_with_values
Expand All @@ -547,6 +548,7 @@ impl SheetRustFunctions {
ToolOutputArg::empty(),
None,
"local:::rust_toolkit:::shinkai_sheet_ui_update_column_with_values".to_string(),
Some(1_000_000),
);

// Add the tool definition for replace_value_at_position
Expand All @@ -563,6 +565,7 @@ impl SheetRustFunctions {
ToolOutputArg::empty(),
None,
"local:::rust_toolkit:::shinkai_sheet_ui_replace_value_at_position".to_string(),
Some(1_000_000),
);

// Add the tool definition for create_new_columns_with_csv
Expand All @@ -577,6 +580,7 @@ impl SheetRustFunctions {
ToolOutputArg::empty(),
None,
"local:::rust_toolkit:::shinkai_sheet_ui_create_new_columns_with_csv".to_string(),
Some(1_000_000),
);

// Add the tool definition for get_table
Expand All @@ -587,6 +591,7 @@ impl SheetRustFunctions {
ToolOutputArg::empty(),
None,
"local:::rust_toolkit:::shinkai_sheet_ui_get_table".to_string(),
Some(1_000_000),
);

vec![
Expand Down
170 changes: 3 additions & 167 deletions shinkai-bin/shinkai-node/src/managers/tool_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ impl ToolRouter {
// Add JS tools
let _ = self.add_deno_tools().await;
let _ = self.add_rust_tools().await;
let _ = self.add_python_tools().await;
// Add static prompts
let _ = self.add_static_prompts(&generator).await;
} else if !has_any_js_tools {
// Add JS tools
let _ = self.add_deno_tools().await;
let _ = self.add_rust_tools().await;
let _ = self.add_python_tools().await;
}

Ok(())
Expand All @@ -95,7 +93,6 @@ impl ToolRouter {
// Add JS tools
let _ = self.add_deno_tools().await;
let _ = self.add_rust_tools().await;
let _ = self.add_python_tools().await;
let _ = self.add_static_prompts(generator).await;
let _ = Self::import_tools_from_directory(self.sqlite_manager.clone()).await;
Ok(())
Expand Down Expand Up @@ -226,6 +223,7 @@ impl ToolRouter {
tool.output_arg,
None,
tool.tool_router_key,
tool.version,
);
self.sqlite_manager
.add_tool(ShinkaiTool::Rust(rust_tool, true))
Expand All @@ -238,44 +236,6 @@ impl ToolRouter {
async fn add_deno_tools(&self) -> Result<(), ToolError> {
let start_time = Instant::now(); // Start the timer

let tools = built_in_tools::get_tools();

let only_testing_js_tools =
std::env::var("ONLY_TESTING_JS_TOOLS").unwrap_or_else(|_| "false".to_string()) == "true";
let allowed_tools = vec![
"shinkai-tool-echo",
"shinkai-tool-coinbase-create-wallet",
"shinkai-tool-coinbase-get-my-address",
"shinkai-tool-coinbase-get-balance",
"shinkai-tool-coinbase-get-transactions",
"shinkai-tool-coinbase-send-tx",
"shinkai-tool-coinbase-call-faucet",
];

{
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()]);
for tool in toolkit.tools {
let shinkai_tool = ShinkaiTool::Deno(tool.clone(), true);
self.sqlite_manager
.add_tool(shinkai_tool)
.await
.map_err(|e| ToolError::DatabaseError(e.to_string()))?;
}
}
}

// Check if ADD_TESTING_EXTERNAL_NETWORK_ECHO is set
if std::env::var("ADD_TESTING_EXTERNAL_NETWORK_ECHO").unwrap_or_else(|_| "false".to_string()) == "true" {
let usage_type = UsageType::PerUse(ToolPrice::Payment(vec![AssetPayment {
Expand All @@ -293,7 +253,7 @@ impl ToolRouter {
name: "network__echo".to_string(),
toolkit_name: "shinkai-tool-echo".to_string(),
description: "Echoes the input message".to_string(),
version: "v0.1".to_string(),
version: Some(1_000_000),
provider: ShinkaiName::new("@@agent_provider.arb-sep-shinkai".to_string()).unwrap(),
usage_type: usage_type.clone(),
activated: true,
Expand Down Expand Up @@ -326,7 +286,7 @@ impl ToolRouter {
name: "youtube_transcript_with_timestamps".to_string(),
toolkit_name: "shinkai-tool-youtube-transcript".to_string(),
description: "Takes a YouTube link and summarizes the content by creating multiple sections with a summary and a timestamp.".to_string(),
version: "v0.1".to_string(),
version: Some(1_000_000),
provider: ShinkaiName::new("@@agent_provider.arb-sep-shinkai".to_string()).unwrap(),
usage_type: usage_type.clone(),
activated: true,
Expand Down Expand Up @@ -405,130 +365,6 @@ impl ToolRouter {
Ok(())
}

fn generate_google_search_tool() -> PythonTool {
// Create parameters for Google search
let mut params = Parameters::new();
params.add_property(
"query".to_string(),
"string".to_string(),
"The search query to look up".to_string(),
true,
);
params.add_property(
"num_results".to_string(),
"number".to_string(),
"Number of search results to return".to_string(),
false,
);

let mut output_arg = ToolOutputArg::empty();
output_arg.json = r#"{
"query": "string",
"results": [
{
"title": "string",
"url": "string",
"description": "string"
}
]
}"#
.to_string();

let python_tool = PythonTool {
toolkit_name: "google_search_shinkai".to_string(),
embedding: None,
name: "Google Search".to_string(),
author: "Shinkai".to_string(),
py_code: r#"
# /// script
# dependencies = [
# "googlesearch-python"
# ]
# ///
from googlesearch import search, SearchResult
from typing import List
from dataclasses import dataclass
import json

class CONFIG:
pass

class INPUTS:
query: str
num_results: int = 10

class OUTPUT:
results: List[SearchResult]
query: str

async def run(c: CONFIG, p: INPUTS) -> OUTPUT:
query = p.query
if not query:
raise ValueError("No search query provided")

results = []
try:
results = search(query, num_results=p.num_results, advanced=True)
except Exception as e:
raise RuntimeError(f"Search failed: {str(e)}")

output = OUTPUT()
output.results = results
output.query = query
return output
"#
.to_string(),
tools: None,
config: vec![],
description: "Search the web using Google".to_string(),
keywords: vec![
"web search".to_string(),
"google search".to_string(),
"internet search".to_string(),
],
input_args: params,
output_arg,
activated: true,
result: ToolResult {
r#type: "object".to_string(),
properties: serde_json::json!({
"query": {"type": "string"},
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {"type": "string"},
"url": {"type": "string"},
"description": {"type": "string"}
},
"required": ["title", "url", "description"]
}
}
}),
required: vec!["query".to_string(), "results".to_string()],
},
sql_tables: None,
sql_queries: None,
file_inbox: None,
oauth: None,
assets: None,
};
python_tool
}

async fn add_python_tools(&self) -> Result<(), ToolError> {
let python_tools = vec![Self::generate_google_search_tool()];
for python_tool in python_tools {
self.sqlite_manager
.add_tool(ShinkaiTool::Python(python_tool, true))
.await
.map_err(|e| ToolError::DatabaseError(e.to_string()))?;
}

Ok(())
}

pub async fn get_tool_by_name(&self, name: &str) -> Result<Option<ShinkaiTool>, ToolError> {
match self.sqlite_manager.get_tool_by_key(name) {
Ok(tool) => Ok(Some(tool)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,21 @@ impl Node {

let shinkai_tool = match payload.language {
CodeLanguage::Typescript => {
let version = ShinkaiTool::from_string_to_numeric_version(payload.metadata.version.clone());
if version.is_err() {
let api_error = APIError {
code: StatusCode::BAD_REQUEST.as_u16(),
error: "Bad Request".to_string(),
message: format!(
"Failed to convert version to numeric version: {}",
version.err().unwrap()
),
};
let _ = res.send(Err(api_error)).await;
return Ok(());
}
let version = Some(version.unwrap());

let tool = DenoTool {
toolkit_name,
name: payload.metadata.name.clone(),
Expand All @@ -459,10 +474,26 @@ impl Node {
sql_queries: Some(payload.metadata.sql_queries),
file_inbox: None,
assets: payload.assets.clone(),
version,
};
ShinkaiTool::Deno(tool, false)
}
CodeLanguage::Python => {
let version = ShinkaiTool::from_string_to_numeric_version(payload.metadata.version.clone());
if version.is_err() {
let api_error = APIError {
code: StatusCode::BAD_REQUEST.as_u16(),
error: "Bad Request".to_string(),
message: format!(
"Failed to convert version to numeric version: {}",
version.err().unwrap()
),
};
let _ = res.send(Err(api_error)).await;
return Ok(());
}
let version = Some(version.unwrap());

let tool = PythonTool {
toolkit_name,
name: payload.metadata.name.clone(),
Expand All @@ -482,6 +513,7 @@ impl Node {
sql_queries: Some(payload.metadata.sql_queries),
file_inbox: None,
assets: payload.assets.clone(),
version,
};
ShinkaiTool::Python(tool, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub async fn execute_deno_tool(
sql_queries: None,
file_inbox: None,
assets: None,
version: Some(1_000_000),
};

let env = generate_execution_environment(
Expand Down Expand Up @@ -137,6 +138,7 @@ pub fn check_deno_tool(
sql_queries: None,
file_inbox: None,
assets: None,
version: Some(1_000_000),
};

let node_env = fetch_node_environment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub async fn execute_python_tool(
file_inbox: None,
oauth: oauth.clone(),
assets: None,
version: Some(1_000_000),
};

let env = generate_execution_environment(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use shinkai_message_primitives::schemas::inbox_name::InboxName;
use shinkai_sqlite::SqliteManager;
use shinkai_tools_primitives::tools::parameters::Parameters;
use shinkai_tools_primitives::tools::{tool_output_arg::ToolOutputArg, error::ToolError, shinkai_tool::ShinkaiToolHeader};
use shinkai_tools_primitives::tools::{
error::ToolError, shinkai_tool::ShinkaiToolHeader, tool_output_arg::ToolOutputArg,
};
use shinkai_vector_fs::vector_fs::vector_fs::VectorFS;
use std::sync::Arc;

Expand Down Expand Up @@ -44,7 +46,7 @@ This can be used to process complex requests, text analysis, text matching, text
tool_type: "Rust".to_string(),
formatted_tool_summary_for_ui: "Tool for processing prompts with LLM".to_string(),
author: "Shinkai".to_string(),
version: "1.0".to_string(),
version: Some(1_000_000),
enabled: true,
input_args: {
let mut params = Parameters::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ SELECT field_1, field_3 FROM table_name WHERE field_3 > 100 ORDER BY field_2 DES
tool_type: "Rust".to_string(),
formatted_tool_summary_for_ui: "Execute SQLite queries".to_string(),
author: "Shinkai".to_string(),
version: "1.0".to_string(),
version: Some(1_000_000),
enabled: true,
input_args: {
let mut params = Parameters::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Example usage:
tool_type: "Rust".to_string(),
formatted_tool_summary_for_ui: "Process embeddings in job scope".to_string(),
author: "Shinkai".to_string(),
version: "1.0".to_string(),
version: Some(1_000_000),
enabled: true,
input_args: {
let mut params = Parameters::new();
Expand Down
Loading
Loading