Skip to main content

LifeOS Assistant - NEW!

Complete demo showcasing the Shared Memory System - calendar, files, browsing history, contacts, and more. Your AI-powered life dashboard with full privacy controls.

Demo Apps

See the full apps in the repo:
  • demo-app
  • privatechat
  • codecompanion
  • documind

Example: Simple Chat Bot

use pryveo_sdk::prelude::*;
use pryveo_sdk::{inference, logging, storage};

#[no_mangle]
pub extern "C" fn run() -> i32 {
    match chat_bot() {
        Ok(_) => 0,
        Err(e) => {
            logging::log(logging::LogLevel::Error, &format!("{}", e)).ok();
            1
        }
    }
}

fn chat_bot() -> pryveo_sdk::Result<()> {
    let history = storage::read("chat_history").unwrap_or_else(|_| Vec::new());
    let history_str = String::from_utf8(history).unwrap_or_default();

    let user_msg = "Tell me a joke about programming";
    let prompt = format!(
        "{}\n\nUser: {}\n\nAssistant:",
        history_str, user_msg
    );

    let response = inference::generate(inference::GenerateRequest {
        prompt,
        max_tokens: Some(100),
        temperature: Some(0.8),
        top_p: Some(0.95),
    })?;

    logging::log(logging::LogLevel::Info, &format!("AI: {}", response.text))?;

    let new_history = format!(
        "{}\n\nUser: {}\n\nAssistant: {}",
        history_str, user_msg, response.text
    );
    storage::write("chat_history", new_history.as_bytes())?;

    Ok(())
}

Example: Code Analyzer

use pryveo_sdk::prelude::*;
use pryveo_sdk::{clipboard, inference, logging, vector};
use std::collections::HashMap;

#[no_mangle]
pub extern "C" fn run() -> i32 {
    match analyze_code() {
        Ok(_) => 0,
        Err(_) => 1,
    }
}

fn analyze_code() -> pryveo_sdk::Result<()> {
    let code = clipboard::read_text()?;
    if code.trim().is_empty() {
        logging::log(logging::LogLevel::Warn, "Clipboard is empty")?;
        return Ok(());
    }

    let mut metadata = HashMap::new();
    metadata.insert("type".to_string(), "code".to_string());
    vector::index_document("current_code", &code, metadata)?;

    let prompt = format!(
        "Analyze this code:\n\n```\n{}\n```\n\nProvide:\n1. What it does\n2. Potential bugs\n3. Improvement suggestions",
        &code[..code.len().min(500)]
    );

    let analysis = inference::generate(inference::GenerateRequest {
        prompt,
        max_tokens: Some(300),
        temperature: Some(0.5),
        top_p: Some(0.9),
    })?;

    clipboard::write_text(&analysis.text)?;
    logging::log(logging::LogLevel::Info, "Analysis copied to clipboard")?;

    Ok(())
}