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
chore: small fixes
Louis Beaumontbccff2b1ef37
diff --git a/Cargo.toml b/Cargo.tomlindex c048c618d..3a0f4e590 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -7,7 +7,7 @@ members = []exclude = [- "examples/apps/screenpipe-app-tauri/src-tauri",+ "examples/apps/screenpipe-app-tauri/src-tauri","examples/apps/screenpipe-app-dioxus",]resolver = "2"diff --git a/content/docs/NOTES.md b/content/docs/NOTES.mdindex 59a769095..6ffae6871 100644--- a/content/docs/NOTES.md+++ b/content/docs/NOTES.md@@ -35,5 +35,11 @@By default files are in your home directory under `.screenpipe`.</details>+<details>+ <summary>How can I interpret my data more intuitively?</summary>++ We recommend using [TablePlus](https://tableplus.com/) to open the SQLite database.+ You can find it in the `.screenpipe` directory with name `db.sqlite`.+</details>diff --git a/examples/apps/screenpipe-app-tauri/package.json b/examples/apps/screenpipe-app-tauri/package.jsonindex a9da950cd..2a444d22d 100644--- a/examples/apps/screenpipe-app-tauri/package.json+++ b/examples/apps/screenpipe-app-tauri/package.json@@ -8,7 +8,7 @@"lint": "next lint","build": "next build","tauri": "tauri",- "clean": "rm -rf out && cargo clean"+ "clean": "rm -rf out && cargo clean && rm -rf src-tauri/{screenpipe,tesseract,ffmpeg}"},"dependencies": {"@mlc-ai/web-llm": "^0.2.51",diff --git a/examples/apps/screenpipe-app-tauri/src-tauri/.gitignore b/examples/apps/screenpipe-app-tauri/src-tauri/.gitignoreold mode 100644new mode 100755diff --git a/examples/apps/screenpipe-app-tauri/src-tauri/src/analytics.rs b/examples/apps/screenpipe-app-tauri/src-tauri/src/analytics.rsold mode 100644new mode 100755index 02c89b123..4fd7c45fa--- a/examples/apps/screenpipe-app-tauri/src-tauri/src/analytics.rs+++ b/examples/apps/screenpipe-app-tauri/src-tauri/src/analytics.rs@@ -2,11 +2,11 @@ use log::{error, info};use reqwest::Client;use serde_json::json;use std::fs;-use std::sync::{Arc, Mutex};+use std::sync::Arc;use std::time::Duration;+use tokio::sync::Mutex;use tokio::time::interval;use uuid::Uuid;-pub struct AnalyticsManager {client: Client,posthog_api_key: String,@@ -76,8 +76,6 @@ impl AnalyticsManager {}}}--}pub fn get_or_create_unique_id(app_name: &str) -> Result<String, Box<dyn std::error::Error>> {diff --git a/examples/apps/screenpipe-app-tauri/src-tauri/src/llm.rs b/examples/apps/screenpipe-app-tauri/src-tauri/src/llm.rsnew file mode 100755index 000000000..fb40b310f--- /dev/null+++ b/examples/apps/screenpipe-app-tauri/src-tauri/src/llm.rs@@ -0,0 +1,141 @@+use anyhow::{bail, Result};+use candle::{DType, Device, Tensor};+use candle_nn::VarBuilder;+use candle_transformers::models::llama::{Cache, Llama, LlamaConfig};+use hf_hub::{api::sync::Api, Repo, RepoType};+use tokenizers::Tokenizer;++pub fn load_llama_model(device: &Device) -> Result<(Llama, Tokenizer, Cache)> {+ let api = Api::new()?;+ let model_id = "meta-llama/Meta-Llama-3-8B-Instruct";+ let revision = "main";++ let api = api.repo(Repo::with_revision(+ model_id.to_string(),+ RepoType::Model,+ revision.to_string(),+ ));+ let tokenizer_filename = api.get("tokenizer.json")?;+ let config_filename = api.get("config.json")?;++ let config: LlamaConfig = serde_json::from_slice(&std::fs::read(config_filename)?)?;+ let config = config.into_config(false); // Assuming no flash attention++ let dtype = DType::BF16; // You can change this to F16 if preferred+ let cache = Cache::new(true, dtype, &config, device)?;++ let filenames = candle_examples::hub_load_safetensors(&api, "model.safetensors.index.json")?;+ let vb = unsafe { VarBuilder::from_mmaped_safetensors(&filenames, dtype, device)? };++ let model = Llama::load(vb, &config)?;+ let tokenizer = Tokenizer::from_file(tokenizer_filename).map_err(anyhow::Error::msg)?;++ Ok((model, tokenizer, cache))+}++pub fn generate_text(+ model: &Llama,+ tokenizer: &Tokenizer,+ cache: &mut Cache,+ prompt: &str,+ max_tokens: usize,+ temperature: f64,+ device: &Device,+) -> Result<String> {+ // Implement text generation logic here+ // This would include tokenization, forward passes, and token sampling+ // You can refer to the main() function in the GitHub example for details++ // Placeholder return+ Ok("Generated text placeholder".to_string())+}++pub fn generate_text_streaming<F>(+ model: &Llama,+ tokenizer: &Tokenizer,+ cache: &mut Cache,+ prompt: &str,+ max_tokens: usize,+ temperature: f64,+ device: &Device,+ callback: F,+) -> Result<()>+where+ F: FnMut(String) -> Result<()>,+{+ let mut rng = rand::rngs::StdRng::seed_from_u64(299792458);+ let mut logits_processor =+ candle_transformers::generation::LogitsProcessor::new(299792458, temperature, None);++ let mut tokens = tokenizer.encode(prompt, true).map_err(anyhow::Error::msg)?;+ let mut generated_tokens = 0;+ let mut callback = callback;++ let eos_token = tokenizer.token_to_id("</s>");+ let bos_token = tokenizer.token_to_id("<s>");++ if let Some(bos_token) = bos_token {+ tokens.insert(0, bos_token);+ }++ let mut all_tokens = tokens.clone();++ for index in 0..max_tokens {+ let context_size = if index > 0 { 1 } else { tokens.len() };+ let start_pos = tokens.len().saturating_sub(context_size);+ let input = Tensor::new(&tokens[start_pos..], device)?;++ let logits = model.forward(&input, start_pos, cache)?;+ let logits = logits.squeeze(0)?;+ let logits = if temperature == 0. {+ logits+ } else {+ logits.div(temperature)?+ };++ let next_token = logits_processor.sample(&logits)?;+ tokens.push(next_token);+ all_tokens.push(next_token);++ if let Some(eos_token) = eos_token {+ if next_token == eos_token {+ break;+ }+ }++ if let Some(text) = tokenizer+ .decode(&[next_token], true)+ .map_err(anyhow::Error::msg)?+ {+ callback(text)?;+ }++ generated_tokens += 1;+ }++ Ok(())+}++fn main() {+ let device = Device::new_metal(0).unwrap_or(Device::new_cuda(0).unwrap_or(Device::Cpu));+ let (model, tokenizer, cache) = load_llama_model(&device).unwrap();+ let prompt = "Hello, world!";+ let max_tokens = 10;+ let temperature = 0.1;+ let callback = |text| {+ println!("Generated text: {}", text);+ Ok(())+ };+ // streaming+ generate_text_streaming(+ &model,+ &tokenizer,+ &mut cache,+ &prompt,+ max_tokens,+ temperature,+ &device,+ callback,+ )+ .unwrap();+}diff --git a/examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/examples/apps/screenpipe-app-tauri/src-tauri/src/main.rsold mode 100644new mode 100755index 637754eb5..e1f0286d0--- a/examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -35,8 +35,6 @@ fn get_base_dir(custom_path: Option<String>) -> anyhow::Result<PathBuf> {Ok(local_data_dir)}--#[tokio::main]async fn main() {let _ = fix_path_env::fix();@@ -149,50 +147,61 @@ async fn main() {.arg("-f").arg("screenpipe").output()- .await;+ .await;});}_ => {}});}+use std::sync::Arc;use tokio::io::{AsyncBufReadExt, BufReader};+use tokio::time::{interval, Duration};async fn start_server() -> anyhow::Result<()> {- let _t = tokio::spawn(async move {- debug!("Starting server");+ let restart_interval = Duration::from_secs(1 * 60); // Restart every 20 minutes+ let server_handle: Arc<tokio::sync::Mutex<Option<tokio::task::JoinHandle<()>>>> =+ Arc::new(tokio::sync::Mutex::new(None));+ let server_handle_clone = Arc::clone(&server_handle);++ tokio::spawn(async move {+ let mut interval = interval(restart_interval);++ loop {+ interval.tick().await;+ debug!("Restarting screenpipe sidecar...");++ // Stop the current server+ if let Some(handle) = server_handle_clone.lock().await.take() {+ handle.abort();+ }- // kill any all process on port 3030+ // Start a new server+ *server_handle_clone.lock().await = Some(start_screenpipe_server());+ }+ });++ // Initial server start+ *server_handle.lock().await = Some(start_screenpipe_server());++ Ok(())+}++fn start_screenpipe_server() -> tokio::task::JoinHandle<()> {+ tokio::spawn(async move {+ debug!("Starting screenpipe server");++ // Kill any existing process on port 3030let _ = tokio::process::Command::new("pkill").arg("-f").arg("screenpipe").output().await;-let mut cmd =tokio::process::Command::new(find_screenpipe::find_screenpipe_path().unwrap());cmd.arg("--port").arg("3030");cmd.arg("--debug");- // let base_dir = get_base_dir(None).expect("Failed to ensure local data directory");- // cmd.arg("--data-dir").arg(base_dir);- // add tesseract to path from ./tesseract- // cmd.env(- // "PATH",- // format!(- // "{:?}:{:?}",- // std::env::var("PATH").unwrap(),- // "/Applications/screenpipe.app/Contents/Resources/tesseract"- // ),- // );- // cmd.env(- // "PATH",- // format!(- // "{:?}:{:?}",- // std::env::var("PATH").unwrap(),- // "/Applications/screenpipe.app/Contents/Resources"- // ),- // );cmd.stdout(std::process::Stdio::piped());cmd.stderr(std::process::Stdio::piped());@@ -221,19 +230,5 @@ async fn start_server() -> anyhow::Result<()> {.await.expect("Failed to wait for child process");debug!("Child process exited with output: {:?}", output);- if output.status.success() {- Ok(())- } else {- Err(anyhow::anyhow!(- "Child process exited with output: {:?}",- output- ))- }- });-- // stop when rx is received- // let _ = rx.recv().await;- // t.abort();-- Ok(())+ })}