Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nicarq committed Oct 31, 2024
1 parent 0998758 commit 3531cc3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
15 changes: 1 addition & 14 deletions shinkai-bin/shinkai-node/tests/it/db_llm_providers_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ mod tests {
let profiles = db.get_llm_provider_profiles_with_access(&test_agent.id, &profile);
assert!(profiles.is_ok(), "Failed to get agent profiles");
assert_eq!(vec!["profilename"], profiles.unwrap());

// Get agent toolkits accessible
let toolkits = db.get_llm_provider_toolkits_accessible(&test_agent.id, &profile);
assert!(toolkits.is_ok(), "Failed to get agent toolkits");
assert_eq!(vec!["toolkit1", "toolkit2"], toolkits.unwrap());
}

#[test]
Expand Down Expand Up @@ -200,14 +195,6 @@ mod tests {
let profiles = db
.get_llm_provider_profiles_with_access(&test_agent.id, &profile)
.unwrap();
assert_eq!(vec!["profilename", "sender2"], profiles);

// Remove a toolkit from agent access
let result = db.remove_toolkit_from_llm_provider_access(&test_agent.id, "toolkit1", &profile);
assert!(result.is_ok(), "Failed to remove toolkit from agent access");
let toolkits = db
.get_llm_provider_toolkits_accessible(&test_agent.id, &profile)
.unwrap();
assert_eq!(vec!["toolkit2"], toolkits);
assert_eq!(vec!["profilename"], profiles);
}
}
32 changes: 0 additions & 32 deletions shinkai-libs/shinkai-db/src/db/db_llm_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,38 +227,6 @@ impl ShinkaiDB {
Ok(profiles_with_access)
}

pub fn get_llm_provider_toolkits_accessible(
&self,
llm_provider_id: &str,
profile: &ShinkaiName,
) -> Result<Vec<String>, ShinkaiDBError> {
let cf_node_and_users = self.cf_handle(Topic::NodeAndUsers.as_str())?;
let llm_provider_id_for_db = Self::db_llm_provider_id(llm_provider_id, profile)?;
let llm_provider_id_for_db_hash = Self::llm_provider_id_to_hash(&llm_provider_id_for_db);
let prefix = format!("agent_{}_toolkit_", llm_provider_id_for_db_hash);
let mut toolkits_accessible = Vec::new();

let iter = self.db.prefix_iterator_cf(cf_node_and_users, prefix.as_bytes());
for item in iter {
match item {
Ok((key, _)) => {
// Extract toolkit name from the key
let key_str = String::from_utf8(key.to_vec())
.map_err(|_| ShinkaiDBError::DataConversionError("UTF-8 conversion error".to_string()))?;
// Ensure the key follows the prefix convention before extracting the toolkit name
if key_str.starts_with(&prefix) {
if let Some(toolkit_name) = key_str.split('_').last() {
toolkits_accessible.push(toolkit_name.to_string());
}
}
}
Err(e) => return Err(ShinkaiDBError::RocksDBError(e)),
}
}

Ok(toolkits_accessible)
}

pub fn remove_profile_from_llm_provider_access(
&self,
llm_provider_id: &str,
Expand Down

0 comments on commit 3531cc3

Please sign in to comment.