Skip to content

Commit

Permalink
Merge pull request #105 from dcSpark/nico/fix-upload
Browse files Browse the repository at this point in the history
fix upload (new max length 200mb)
  • Loading branch information
nicarq authored Oct 11, 2023
2 parents 1bc455e + 0db8510 commit 987d084
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 79 deletions.
17 changes: 16 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,22 @@
}
},
"args": [],
"cwd": "${workspaceFolder}"
"cwd": "${workspaceFolder}",
"env": {
"NODE_IP": "0.0.0.0",
"NODE_PORT": "9552",
"NODE_API_IP": "0.0.0.0",
"NODE_API_PORT": "9550",
"IDENTITY_SECRET_KEY": "df3f619804a92fdb4057192dc43dd748ea778adc52bc498ce80524c014b81119",
"ENCRYPTION_SECRET_KEY": "d83f619804a92fdb4057192dc43dd748ea778adc52bc498ce80524c014b81159",
"PING_INTERVAL_SECS": "0",
"GLOBAL_IDENTITY_NAME": "@@node1.shinkai",
"RUST_LOG": "debug,error,info",
"STARTING_NUM_QR_PROFILES": "1",
"STARTING_NUM_QR_DEVICES": "1",
"FIRST_DEVICE_NEEDS_REGISTRATION_CODE": "false",
"LOG_ALL": "1"
}
},
{
"type": "lldb",
Expand Down
8 changes: 1 addition & 7 deletions scripts/run_node1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ export STARTING_NUM_QR_DEVICES="1"
export FIRST_DEVICE_NEEDS_REGISTRATION_CODE="false"

# Add these lines to enable all log options
export LOG_BLOCKCHAIN=1
export LOG_DATABASE=1
export LOG_IDENTITY=1
export LOG_API=1
export LOG_DETAILED_API=1
export LOG_NODE=1
export LOG_INTERNAL_API=1
export LOG_ALL=1

cargo run
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use colored::*;
use chrono::Local;

#[derive(PartialEq)]
#[derive(PartialEq, Debug)]
pub enum ShinkaiLogOption {
Blockchain,
Database,
Identity,
JobExecution,
API,
DetailedAPI,
Node,
Expand All @@ -31,6 +32,20 @@ impl ShinkaiLogLevel {
}

fn active_log_options() -> Vec<ShinkaiLogOption> {
if std::env::var("LOG_ALL").is_ok() {
return vec![
ShinkaiLogOption::Blockchain,
ShinkaiLogOption::Database,
ShinkaiLogOption::Identity,
ShinkaiLogOption::JobExecution,
ShinkaiLogOption::API,
ShinkaiLogOption::DetailedAPI,
ShinkaiLogOption::Node,
ShinkaiLogOption::InternalAPI,
ShinkaiLogOption::Tests,
];
}

let mut active_options = Vec::new();
if std::env::var("LOG_BLOCKCHAIN").is_ok() {
active_options.push(ShinkaiLogOption::Blockchain);
Expand All @@ -56,6 +71,9 @@ fn active_log_options() -> Vec<ShinkaiLogOption> {
if std::env::var("LOG_TESTS").is_ok() {
active_options.push(ShinkaiLogOption::Tests);
}
if std::env::var("LOG_JOB_EXECUTION").is_ok() {
active_options.push(ShinkaiLogOption::JobExecution);
}

active_options
}
Expand All @@ -64,7 +82,8 @@ pub fn shinkai_log(option: ShinkaiLogOption, level: ShinkaiLogLevel, message: &s
let active_options = active_log_options();
if active_options.contains(&option) {
let time = Local::now().format("%Y-%m-%d %H:%M:%S");
let message_with_time = format!("{} | {}", time, message);
let option_str = format!("{:?}", option);
let message_with_time = format!("{} | {} | {}", time, option_str, message);
match level.to_log_level() {
log::Level::Error => eprintln!("{}", message_with_time.red()),
log::Level::Info => println!("{}", message_with_time.yellow()),
Expand Down
47 changes: 35 additions & 12 deletions src/db/db_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use shinkai_message_primitives::shinkai_message::shinkai_message_schemas::Identi
use shinkai_message_primitives::shinkai_utils::encryption::{
encryption_public_key_to_string, encryption_public_key_to_string_ref, string_to_encryption_public_key,
};
use shinkai_message_primitives::shinkai_utils::shinkai_logging::{shinkai_log, ShinkaiLogOption, ShinkaiLogLevel};
use shinkai_message_primitives::shinkai_utils::signatures::{
signature_public_key_to_string, signature_public_key_to_string_ref, string_to_signature_public_key,
};
Expand Down Expand Up @@ -256,11 +257,11 @@ impl ShinkaiDB {
// Write the batch
self.db.write(batch)?;

println!(
"insert_profile::identity.full_identity_name: {}",
identity.full_identity_name
shinkai_log(
ShinkaiLogOption::Identity,
ShinkaiLogLevel::Info,
format!("Inserted profile: {}", profile_name).as_str(),
);
self.debug_print_all_keys_for_profiles_identity_key();

Ok(())
}
Expand Down Expand Up @@ -319,7 +320,11 @@ impl ShinkaiDB {
let cf_identity = match self.db.cf_handle(Topic::ProfilesIdentityKey.as_str()) {
Some(handle) => handle,
None => {
eprintln!("Failed to get column family handle for ProfilesIdentityKey");
shinkai_log(
ShinkaiLogOption::Identity,
ShinkaiLogLevel::Error,
format!("Failed to get column family handle for ProfilesIdentityKey").as_str(),
);
return;
}
};
Expand All @@ -336,12 +341,20 @@ impl ShinkaiDB {
// If it's not, you might get a panic. Consider using
// String::from_utf8_lossy if there's a possibility of invalid UTF-8
let key_str = String::from_utf8(key.to_vec()).unwrap();
println!("print_all_keys_for_profiles_identity_key> {}", key_str);
shinkai_log(
ShinkaiLogOption::Identity,
ShinkaiLogLevel::Debug,
format!("print_all_keys_for_profiles_identity_key {}", key_str).as_str(),
);
self.print_all_devices_for_profile(&key_str);
}
Err(e) => {
// Optionally handle the error, e.g., print it out
eprintln!("Error reading from database: {}", e);
shinkai_log(
ShinkaiLogOption::Identity,
ShinkaiLogLevel::Error,
format!("Error reading from database: {}", e).as_str(),
);
}
}
}
Expand All @@ -352,7 +365,11 @@ impl ShinkaiDB {
let cf_device = match self.db.cf_handle(Topic::DevicesIdentityKey.as_str()) {
Some(handle) => handle,
None => {
eprintln!("Failed to get column family handle for Devices");
shinkai_log(
ShinkaiLogOption::Identity,
ShinkaiLogLevel::Error,
format!("Failed to get column family handle for Devices").as_str(),
);
return;
}
};
Expand All @@ -369,12 +386,20 @@ impl ShinkaiDB {

// Check if the key (device identity name) contains the profile name
if key_str.contains(profile_name) {
println!("print_all_devices_for_profile> {}", key_str);
shinkai_log(
ShinkaiLogOption::Identity,
ShinkaiLogLevel::Debug,
format!("print_all_devices_for_profile {}", key_str).as_str(),
);
}
}
Err(e) => {
// Optionally handle the error, e.g., print it out
eprintln!("Error reading from database: {}", e);
shinkai_log(
ShinkaiLogOption::Identity,
ShinkaiLogLevel::Error,
format!("Error reading from database: {}", e).as_str(),
);
}
}
}
Expand Down Expand Up @@ -478,8 +503,6 @@ impl ShinkaiDB {
}

pub fn get_profile(&self, full_identity_name: ShinkaiName) -> Result<Option<StandardIdentity>, ShinkaiDBError> {
self.debug_print_all_keys_for_profiles_identity_key();

let profile_name = full_identity_name
.get_profile_name()
.ok_or(ShinkaiDBError::InvalidIdentityName(full_identity_name.to_string()))?;
Expand Down
Loading

0 comments on commit 987d084

Please sign in to comment.