Skip to content

Commit

Permalink
Merge pull request #845 from dcSpark/nico/fix_perms
Browse files Browse the repository at this point in the history
Nico/fix perms
  • Loading branch information
nicarq authored Feb 4, 2025
2 parents 329a36e + ea93f88 commit d6087ba
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,64 @@ impl GenericInferenceChain {
match tool_router.get_tool_by_name(&tool_name).await {
Ok(Some(tool)) => tools.push(tool),
Ok(None) => {
return Err(LLMProviderError::ToolNotFound(format!(
"Forced tool not found: {}",
tool_name
)));
// If tool not found directly, try FTS and vector search
let sanitized_query = tool_name.replace(|c: char| !c.is_alphanumeric() && c != ' ', " ");

// Perform FTS search
let fts_results = tool_router.sqlite_manager.search_tools_fts(&sanitized_query);

// Perform vector search
let vector_results = tool_router
.sqlite_manager
.tool_vector_search(&sanitized_query, 5, false, true)
.await;

match (fts_results, vector_results) {
(Ok(fts_tools), Ok(vector_tools)) => {
let mut combined_tools = Vec::new();
let mut seen_ids = std::collections::HashSet::new();

// Add FTS results first (exact matches)
for fts_tool in fts_tools {
if seen_ids.insert(fts_tool.tool_router_key.clone()) {
combined_tools.push(fts_tool);
}
}

// Add vector search results with high confidence (score < 0.2)
for (tool, score) in vector_tools {
if score < 0.2 && seen_ids.insert(tool.tool_router_key.clone()) {
combined_tools.push(tool);
}
}

if combined_tools.is_empty() {
return Err(LLMProviderError::ToolNotFound(format!(
"Forced tool not found: {} (no matches found in search)",
tool_name
)));
}

// Add the best matching tool
if let Some(best_tool) = combined_tools.first() {
match tool_router.get_tool_by_name(&best_tool.name).await {
Ok(Some(tool)) => tools.push(tool),
_ => {
return Err(LLMProviderError::ToolNotFound(format!(
"Best matching tool could not be retrieved: {}",
best_tool.name
)));
}
}
}
}
(Err(e), _) | (_, Err(e)) => {
return Err(LLMProviderError::ToolRetrievalError(format!(
"Error searching for tool alternatives: {:?}",
e
)));
}
}
}
Err(e) => {
return Err(LLMProviderError::ToolRetrievalError(format!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use shinkai_tools_primitives::tools::{
};

use std::{
collections::HashMap, env, fs::{File, Permissions}, io::{Read, Write}, os::unix::fs::PermissionsExt, sync::Arc, time::Instant
collections::HashMap, env, fs::File, io::{Read, Write}, sync::Arc, time::Instant
};
use tokio::{process::Command, sync::Mutex};
use zip::{write::FileOptions, ZipWriter};
Expand Down Expand Up @@ -2805,12 +2805,24 @@ start().then(() => {{
error: "Failed to write launch.sh".to_string(),
message: e.to_string(),
})?;
let perm = Permissions::from_mode(0o755);
fs::set_permissions(&launch_file, perm).await.map_err(|e| APIError {
code: 500,
error: "Failed to set permissions".to_string(),
message: e.to_string(),
})?;

// Set file permissions in a cross-platform way
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let perm = std::fs::Permissions::from_mode(0o755);
fs::set_permissions(&launch_file, perm).await.map_err(|e| APIError {
code: 500,
error: "Failed to set permissions".to_string(),
message: e.to_string(),
})?;
}

// On Windows, executable permissions don't exist in the same way
#[cfg(windows)]
{
// Windows doesn't need special executable permissions for .js files
}

// Create .vscode/launch.json
let mut vscode_dir = temp_dir.clone();
Expand Down

0 comments on commit d6087ba

Please sign in to comment.