YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: add example
Louis Beaumontd517eb88f3a9
diff --git a/Cargo.toml b/Cargo.tomlindex 28dc66c7b..93f8efc18 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -1,4 +1,4 @@[workspace]-members = ["screenpipe"]+members = ["screenpipe", "examples/maintain-a-log-of-my-day"]exclude = []-resolver = "2"\ No newline at end of file+resolver = "2"diff --git a/examples/maintain-a-log-of-my-day/Cargo.toml b/examples/maintain-a-log-of-my-day/Cargo.tomlnew file mode 100644index 000000000..00759e9ad--- /dev/null+++ b/examples/maintain-a-log-of-my-day/Cargo.toml@@ -0,0 +1,10 @@+[package]+name = "maintain-a-log-of-my-day"+version = "0.1.0"+edition = "2021"++[dependencies]+rusqlite = { version = "0.30.0", features = ["chrono", "bundled", "array"] }+reqwest = { version = "0.11", features = ["json", "multipart", "blocking"] }+serde = "1.0"+serde_json = "1.0"\ No newline at end of filediff --git a/examples/maintain-a-log-of-my-day/src/main.rs b/examples/maintain-a-log-of-my-day/src/main.rsnew file mode 100644index 000000000..ab684364b--- /dev/null+++ b/examples/maintain-a-log-of-my-day/src/main.rs@@ -0,0 +1,98 @@+// !!very experimental package!!+// This is a simple implementation of a main function that watches for changes in the database+// and performs actions based on specific triggers. The end goal is to create a system similar+// to Apple Shortcuts, where triggers and actions can be defined dynamically. In this version,+// we hardcode some trigger queries and actions for demonstration purposes.+//+// Triggers:+// - Specific SQL query hit like "dog appear 50 times within the past 2 days"+// - More advanced/complex triggers can be added later (e.g., "when I seem to watch TikTok videos about cats for 2 hours")+//+// Actions:+// - Make a request to an API+// - Function calling+// - Executing some code+//+// This is a basic version and can be iterated upon for more complex triggers and actions.+// This maintain a log of what you've been doing today++// make sure to run `ollama run phi3`++use reqwest::blocking::Client;+use rusqlite::Connection;+use std::fs;+use std::fs::File;+use std::thread;+use std::time::Duration;+use serde_json::json;+use std::io::Write;+use std::io::Read;+fn main() {+ let conn = Connection::open("../../screenpipe/data/db.sqlite").unwrap();+ let client = Client::new();+ // create file log with empty lines+ fs::write("log.md", "").unwrap();+ loop {+ let query = "+ SELECT COUNT(*), GROUP_CONCAT(at.text)+ FROM all_text at+ JOIN frames f ON at.frame_id = f.id+ WHERE f.timestamp <= datetime('now', '1 minutes')+ ORDER BY f.timestamp DESC+ LIMIT 100+ ";+ let count: i64 = conn.query_row(query, [], |row| row.get(0)).unwrap();+ let texts: Option<String> = conn.query_row(query, [], |row| row.get(1)).unwrap_or(None);+++ println!("{}", count);+ if texts.is_some() {+ let texts = texts.unwrap();+ // println!("{}", texts);+ let response = client+ .post("http://localhost:11434/api/chat")+ .json(&json!({+ "model": "phi3",+ "stream": false,+ "max_tokens": 4096,+ "messages": [+ {+ "role": "user",+ "content": format!(r#"you receive a markdown log of what the user has been doing today,+ that you maintain based on the text extracted from the user's screen.+ You can add new categories or update the existing ones. You can also add a new entry to the log.+ This is what has been shown on the user's screen over the past 5 minutes: {}+ And this is the current log: {}++ Rules:+ - Keep the log small and concise, formatted as a bullet list+ - Your responses are NOT in a code block e.g. no ```plaintext ```markdown etc.!++ Now update the log based on the user's screen and respond with only the updated log.+ LOG OF THE USER'S DAY:+ "#,+ texts,+ fs::read_to_string("log.md").unwrap()+ )+ }+ ]+ }))+ .send()+ .unwrap();+ let text: serde_json::Value = response.json().unwrap();+ // remove first " and last " from the response+ let llm_response = text["message"]["content"].to_string().trim_matches('"').to_string();++ println!("{}", llm_response);++ // replace all \n with \n\n+ let llm_response = llm_response.replace("\\n", "\n\n");++ // update to file+ fs::write("log.md", llm_response).unwrap();+ }++ // Sleep for a while before checking again+ thread::sleep(Duration::from_secs(5));+ }+}diff --git a/screenpipe/Cargo.toml b/screenpipe/Cargo.tomlindex 9abc0aa27..2ef9d5a4d 100644--- a/screenpipe/Cargo.toml+++ b/screenpipe/Cargo.toml@@ -43,6 +43,7 @@ tokio = { version = "1", features = ["full"] }hyper = "1.1"tower-http = { version = "0.5.0", features = ["cors"] }-[profile.release]-opt-level = 3+[[bin]]+name = "screenpipe"+path = "src/main.rs"diff --git a/screenpipe/src/main.rs b/screenpipe/src/main.rsindex 3b907bb24..107a53085 100644--- a/screenpipe/src/main.rs+++ b/screenpipe/src/main.rs@@ -25,7 +25,7 @@ async fn start_server(local_data_dir: String, db: Arc<Mutex<Option<DatabaseManag}fn ensure_local_data_dir() -> Result<String, ()> {- let local_data_dir = Option::Some("./data");+ let local_data_dir = Option::Some("./data"); // TODO $HOME/.screenpipe/dataif let Some(dir) = local_data_dir.clone() {if let Ok(()) = fs::create_dir_all(dir) {return Ok(dir.to_string());