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: configure deepgram api key in ui
joegoldince6202cf2f57
diff --git a/examples/apps/screenpipe-app-tauri/components/settings.tsx b/examples/apps/screenpipe-app-tauri/components/settings.tsxnew file mode 100644index 000000000..7c5334155--- /dev/null+++ b/examples/apps/screenpipe-app-tauri/components/settings.tsx@@ -0,0 +1,429 @@+"use client";+import React from "react";+import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+} from "@/components/ui/dialog";+import { Button } from "@/components/ui/button";+import { Switch } from "@/components/ui/switch";+import { useSettings } from "@/lib/hooks/use-settings";+import {+ Tooltip,+ TooltipContent,+ TooltipProvider,+ TooltipTrigger,+} from "@/components/ui/tooltip";+import { Badge } from "@/components/ui/badge";+import { MemoizedReactMarkdown } from "./markdown";+import { Separator } from "@/components/ui/separator";+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";+import { Textarea } from "./ui/textarea";++import { platform } from "@tauri-apps/plugin-os";+import { Eye, EyeOff, RefreshCw } from "lucide-react";+import { RecordingSettings } from "./recording-settings";++export function Settings({ className }: { className?: string }) {+ const { settings, updateSettings, resetSetting } = useSettings();+ const [localSettings, setLocalSettings] = React.useState(settings);+ const [currentPlatform, setCurrentPlatform] = React.useState<string>("");+ const [showApiKey, setShowApiKey] = React.useState(false);++ const handleApiKeyChange = (e: React.ChangeEvent<HTMLInputElement>) => {+ const newValue = e.target.value;+ setLocalSettings((prev) => ({ ...prev, openaiApiKey: newValue }));+ updateSettings({ openaiApiKey: newValue });+ };++ const handleOllamaToggle = (checked: boolean) => {+ setLocalSettings((prev) => ({ ...prev, useOllama: checked }));+ updateSettings({ useOllama: checked });+ };++ const handleOllamaUrlChange = (e: React.ChangeEvent<HTMLInputElement>) => {+ const newValue = e.target.value;+ setLocalSettings((prev) => ({ ...prev, ollamaUrl: newValue }));+ updateSettings({ ollamaUrl: newValue });+ };++ const handleModelChange = (e: React.ChangeEvent<HTMLInputElement>) => {+ const newValue = e.target.value;+ setLocalSettings((prev) => ({ ...prev, aiModel: newValue }));+ updateSettings({ aiModel: newValue });+ };++ const handleCustomPromptChange = (+ e: React.ChangeEvent<HTMLTextAreaElement>+ ) => {+ const newValue = e.target.value;+ setLocalSettings((prev) => ({ ...prev, customPrompt: newValue }));+ updateSettings({ customPrompt: newValue });+ };++ const handleDeepgramApiKeyChange = (+ e: React.ChangeEvent<HTMLInputElement>+ ) => {+ const newValue = e.target.value;+ setLocalSettings((prev) => ({ ...prev, deepgramApiKey: newValue }));+ updateSettings({ deepgramApiKey: newValue });+ };++ const handleResetCustomPrompt = () => {+ resetSetting("customPrompt");+ };++ React.useEffect(() => {+ setLocalSettings(settings);+ setCurrentPlatform(platform());+ }, [settings]);++ return (+ <Dialog+ onOpenChange={(open) => {+ if (!open) {+ location.reload(); // ! HACK to properly refresh stuff (tood beter)+ }+ }}+ >+ <DialogTrigger asChild>+ <Button variant="ghost" className={className}>+ settings+ </Button>+ </DialogTrigger>+ <DialogContent className="max-w-[80vw] w-full max-h-[80vh] h-full overflow-y-auto">+ <DialogHeader>+ <DialogTitle>settings</DialogTitle>+ <DialogDescription>+ choose your AI provider, enter necessary credentials, and more.+ </DialogDescription>+ {localSettings.useOllama ? (+ <p className="text-sm font-medium text-grey-600 dark:text-grey-400">+ you are now using ollama 🦙+ </p>+ ) : (+ <p className="text-sm font-medium text-grey-600 dark:text-grey-400">+ you are now using openai 🤖+ </p>+ )}+ </DialogHeader>+ <div className="mt-8 space-y-6">+ <RecordingSettings+ localSettings={localSettings}+ setLocalSettings={setLocalSettings}+ currentPlatform={currentPlatform}+ />++ <Separator />++ <Card>+ <CardHeader>+ <CardTitle className="text-center">general ai settings</CardTitle>+ </CardHeader>+ <CardContent className="flex flex-col items-center">+ <div className="w-full ">+ <div className="flex flex-col gap-2 mb-4">+ <Label htmlFor="aiModel" className="text-sm font-medium">+ {localSettings.useOllama+ ? "enter your ollama model:"+ : "enter your openai model:"}+ </Label>+ <Input+ autoCorrect="off"+ autoComplete="off"+ id="aiModel"+ value={localSettings.aiModel}+ onChange={handleModelChange}+ className="w-full"+ placeholder={+ localSettings.useOllama+ ? "e.g., mistral-nemo"+ : "e.g., gpt-4o"+ }+ />+ </div>+ <p className="text-sm text-muted-foreground text-center">+ {localSettings.useOllama+ ? "recommended: mistral-nemo for ollama (we only support models supporting tools like llama3.1, mistral-nemo, etc.)"+ : "recommended: gpt-4o for openai"}+ </p>+ </div>+ <Separator className="my-4" />+ <div className="w-full ">+ <div className="flex flex-col gap-2 mb-4">+ <div className="flex justify-between items-center">+ <Label+ htmlFor="customPrompt"+ className="text-sm font-medium"+ >+ enter your custom prompt (keep it short, less is more):+ </Label>+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger asChild>+ <Button+ variant="ghost"+ size="icon"+ onClick={handleResetCustomPrompt}+ >+ <RefreshCw className="h-4 w-4" />+ </Button>+ </TooltipTrigger>+ <TooltipContent>+ <p>Reset to default prompt</p>+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ </div>+ <Textarea+ id="customPrompt"+ value={localSettings.customPrompt || ""}+ onChange={handleCustomPromptChange}+ className="w-full"+ rows={6}+ maxLength={2000}+ />+ </div>+ <p className="text-sm text-muted-foreground text-center">+ This prompt will be added to the system message for all your+ queries.+ </p>+ </div>+ </CardContent>+ </Card>+ <Card>+ <CardHeader>+ <CardTitle className="text-center">openai</CardTitle>+ </CardHeader>+ <CardContent className="flex flex-col items-center">+ <div className="w-full ">+ <div className="flex items-center gap-4 mb-4">+ <Label htmlFor="apiKey" className="min-w-[80px] text-right">+ api key+ </Label>+ <div className="flex-grow relative">+ <Input+ id="apiKey"+ type={showApiKey ? "text" : "password"}+ value={settings.openaiApiKey}+ onChange={handleApiKeyChange}+ className="pr-10"+ placeholder="Enter your OpenAI API Key"+ />+ <Button+ type="button"+ variant="ghost"+ size="icon"+ className="absolute right-0 top-0 h-full"+ onClick={() => setShowApiKey(!showApiKey)}+ >+ {showApiKey ? (+ <EyeOff className="h-4 w-4" />+ ) : (+ <Eye className="h-4 w-4" />+ )}+ </Button>+ </div>+ </div>+ </div>+ <p className="mt-2 text-sm text-muted-foreground text-center">+ openai's GPT models are currently the most reliable for+ this application.+ </p>+ <p className="mt-1 text-sm text-muted-foreground text-center">+ don't have an API key? Get one from{" "}+ <a+ href="https://platform.openai.com/api-keys"+ target="_blank"+ rel="noopener noreferrer"+ className="text-primary hover:underline"+ >+ openai's website+ </a>+ .+ </p>+ </CardContent>+ </Card>+ <Card>+ <CardHeader>+ <CardTitle className="text-center">deepgram</CardTitle>+ </CardHeader>+ <CardContent className="flex flex-col items-center">+ <div className="w-full ">+ <div className="flex items-center gap-4 mb-4">+ <Label htmlFor="apiKey" className="min-w-[80px] text-right">+ api key+ </Label>+ <div className="flex-grow relative">+ <Input+ id="apiKey"+ type={showApiKey ? "text" : "password"}+ value={settings.deepgramApiKey}+ onChange={handleDeepgramApiKeyChange}+ className="pr-10"+ placeholder="Enter your Deepgram API Key"+ />+ <Button+ type="button"+ variant="ghost"+ size="icon"+ className="absolute right-0 top-0 h-full"+ onClick={() => setShowApiKey(!showApiKey)}+ >+ {showApiKey ? (+ <EyeOff className="h-4 w-4" />+ ) : (+ <Eye className="h-4 w-4" />+ )}+ </Button>+ </div>+ </div>+ </div>+ <p className="mt-2 text-sm text-muted-foreground text-center">+ deepgram's transcription models are currently the most+ reliable for this application.+ </p>+ <p className="mt-1 text-sm text-muted-foreground text-center">+ don't have an API key? Get one from{" "}+ <a+ href="https://console.deepgram.com/"+ target="_blank"+ rel="noopener noreferrer"+ className="text-primary hover:underline"+ >+ deepgram's website+ </a>+ .+ </p>+ </CardContent>+ </Card>++ <Separator />++ <Card>+ <CardHeader>+ <CardTitle className="text-center">+ Alternative AI Providers+ </CardTitle>+ </CardHeader>+ <CardContent className="space-y-6">+ <div className="flex flex-col items-center space-y-2">+ <div className="flex items-center space-x-4">+ <Switch+ id="use-ollama"+ checked={localSettings.useOllama}+ onCheckedChange={handleOllamaToggle}+ />+ <Label+ htmlFor="use-ollama"+ className="flex items-center space-x-2"+ >+ Use Ollama+ <Badge variant="outline" className="ml-2">+ Experimental+ </Badge>+ </Label>+ </div>++ {localSettings.useOllama && (+ <div className="w-full mt-2">+ <div className="flex-col gap-2 mb-4">+ <div className="flex items-center gap-4 mb-4">+ <Label+ htmlFor="ollamaUrl"+ className="min-w-[80px] text-right"+ >+ Ollama URL+ </Label>+ <Input+ id="ollamaUrl"+ value={localSettings.ollamaUrl}+ onChange={handleOllamaUrlChange}+ className="flex-grow"+ placeholder="Enter Ollama URL (e.g., http://localhost:11434)"+ />+ </div>+ <p className="mt-1 text-sm text-muted-foreground text-center">+ For now only port 11434 and 9000 are supported for+ security reasons.+ </p>+ </div>+ </div>+ )}+ <div className="text-sm text-muted-foreground mt-1">+ <MemoizedReactMarkdown+ components={{+ a: ({ href, children }) => (+ <a+ className="text-primary hover:underline"+ href={href}+ target="_blank"+ rel="noopener noreferrer"+ >+ {children}+ </a>+ ),+ code: ({ children }) => (+ <code className="px-1 py-0.5 rounded-sm bg-gray-100 dark:bg-gray-800 font-mono text-sm">+ {children}+ </code>+ ),+ }}+ >+ {currentPlatform === "windows"+ ? "You need to [install Ollama](https://ollama.com/) and run `set OLLAMA_ORIGINS=* && ollama run mistral-nemo` first. \n\nCurrently only supports models supporting tools like llama3.1, mistral-nemo, etc."+ : "You need to [install Ollama](https://ollama.com/) and run `ollama run mistral-nemo` first. \n\nCurrently only supports models supporting tools like llama3.1, mistral-nemo, etc."}+ </MemoizedReactMarkdown>+ </div>+ <a+ href="https://github.com/mediar-ai/screenpipe/issues/167"+ target="_blank"+ rel="noopener noreferrer"+ className="text-sm text-primary hover:underline font-bold"+ >+ want to help make this work well?+ </a>+ </div>++ <Separator />++ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger asChild>+ <div className="flex items-center justify-center space-x-4">+ <Switch+ id="use-embedded-llm"+ checked={false}+ disabled={true}+ />+ <Label+ htmlFor="use-embedded-llm"+ className="flex items-center space-x-2"+ >+ Use Embedded LLM+ <Badge variant="outline" className="ml-2">+ Soon+ </Badge>+ </Label>+ </div>+ </TooltipTrigger>+ <TooltipContent>+ <p>+ Embedded LLM support coming soon. Run locally without+ installation. No need Ollama.+ </p>+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ </CardContent>+ </Card>+ </div>+ </DialogContent>+ </Dialog>+ );+}diff --git a/screenpipe-app-tauri/components/recording-settings.tsx b/screenpipe-app-tauri/components/recording-settings.tsxindex 681beba63..762720407 100644--- a/screenpipe-app-tauri/components/recording-settings.tsx+++ b/screenpipe-app-tauri/components/recording-settings.tsx@@ -163,6 +163,7 @@ export function RecordingSettings({disableAudio: localSettings.disableAudio,ignoredWindows: localSettings.ignoredWindows,includedWindows: localSettings.includedWindows,+ deepgramApiKey: localSettings.deepgramApiKey,};console.log("Settings to update:", settingsToUpdate);await updateSettings(settingsToUpdate);diff --git a/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/screenpipe-app-tauri/lib/hooks/use-settings.tsxindex 08f7e11ee..840e779bd 100644--- a/screenpipe-app-tauri/lib/hooks/use-settings.tsx+++ b/screenpipe-app-tauri/lib/hooks/use-settings.tsx@@ -7,6 +7,7 @@ import { Pipe } from "./use-pipes";const defaultSettings: Settings = {openaiApiKey: "",+ deepgramApiKey: "",useOllama: false,ollamaUrl: "http://localhost:11434",isLoading: true,@@ -37,6 +38,7 @@ const defaultSettings: Settings = {export interface Settings {openaiApiKey: string;+ deepgramApiKey: string;useOllama: boolean;ollamaUrl: string;isLoading: boolean;@@ -97,6 +99,8 @@ export function useSettings() {try {await store!.load();const savedKey = ((await store!.get("openaiApiKey")) as string) || "";+ const savedDeepgramKey =+ ((await store!.get("deepgramApiKey")) as string) || "";const savedUseOllama =((await store!.get("useOllama")) as boolean) || false;const savedOllamaUrl =@@ -138,6 +142,7 @@ export function useSettings() {((await store!.get("aiUrl")) as string) || "https://api.openai.com/v1";setSettings({openaiApiKey: savedKey,+ deepgramApiKey: savedDeepgramKey,useOllama: savedUseOllama,isLoading: false,ollamaUrl: savedOllamaUrl,diff --git a/screenpipe-app-tauri/src-tauri/src/sidecar.rs b/screenpipe-app-tauri/src-tauri/src/sidecar.rsindex 4dbfacfe7..f4a1191c7 100644--- a/screenpipe-app-tauri/src-tauri/src/sidecar.rs+++ b/screenpipe-app-tauri/src-tauri/src/sidecar.rs@@ -165,6 +165,14 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {+ let deepgram_api_key = with_store(app.clone(), stores.clone(), path.clone(), |store| {+ Ok(store+ .get("deepgramApiKey")+ .and_then(|v| v.as_str().map(String::from)))+ })+ .map_err(|e| e.to_string())?+ .unwrap_or(String::from("default"));+let port_str = port.to_string();let mut args = vec!["--port", port_str.as_str()];if cfg!(target_os = "macos") {@@ -202,6 +210,12 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {}}+ if deepgram_api_key != "default" {+ args.push("--deepgram-api-key");+ let key = deepgram_api_key.as_str();+ args.push(key);+ }+if !audio_devices.is_empty() && audio_devices[0] != Value::String("default".to_string()) {for device in &audio_devices {args.push("--audio-device");diff --git a/screenpipe-audio/src/bin/screenpipe-audio-forever.rs b/screenpipe-audio/src/bin/screenpipe-audio-forever.rsindex 393e13cff..ef0565f54 100644--- a/screenpipe-audio/src/bin/screenpipe-audio-forever.rs+++ b/screenpipe-audio/src/bin/screenpipe-audio-forever.rs@@ -30,6 +30,9 @@ struct Args {#[clap(long, help = "Audio chunk duration in seconds")]audio_chunk_duration: f32,++ #[clap(long, help = "Deepgram API key")]+ deepgram_api_key: Option<String>,}fn print_devices(devices: &[AudioDevice]) {@@ -81,6 +84,7 @@ async fn main() -> Result<()> {create_whisper_channel(Arc::new(AudioTranscriptionEngine::WhisperDistilLargeV3),VadEngineEnum::Silero, // Or VadEngineEnum::WebRtc, hardcoded for now+ args.deepgram_api_key,).await?;// Spawn threads for each devicelet _recording_threads: Vec<_> = devicesdiff --git a/screenpipe-audio/src/bin/screenpipe-audio.rs b/screenpipe-audio/src/bin/screenpipe-audio.rsindex bf219d7db..c6118bbfe 100644--- a/screenpipe-audio/src/bin/screenpipe-audio.rs+++ b/screenpipe-audio/src/bin/screenpipe-audio.rs@@ -27,6 +27,9 @@ struct Args {#[clap(long, help = "List available audio devices")]list_audio_devices: bool,++ #[clap(long, help = "Deepgram API key")]+ deepgram_api_key: Option<String>,}fn print_devices(devices: &[AudioDevice]) {@@ -60,6 +63,8 @@ async fn main() -> Result<()> {return Ok(());}+ let deepgram_api_key = args.deepgram_api_key;+let devices = if args.audio_device.is_empty() {vec![default_input_device()?, default_output_device().await?]} else {@@ -83,6 +88,7 @@ async fn main() -> Result<()> {create_whisper_channel(Arc::new(AudioTranscriptionEngine::WhisperDistilLargeV3),VadEngineEnum::Silero, // Or VadEngineEnum::WebRtc, hardcoded for now+ deepgram_api_key,).await?;// Spawn threads for each devicelet recording_threads: Vec<_> = devicesdiff --git a/screenpipe-audio/src/stt.rs b/screenpipe-audio/src/stt.rsindex 3a2ffabb7..6019987f9 100644--- a/screenpipe-audio/src/stt.rs+++ b/screenpipe-audio/src/stt.rs@@ -513,6 +513,7 @@ pub fn stt(whisper_model: &WhisperModel,audio_transcription_engine: Arc<AudioTranscriptionEngine>,vad_engine: &mut dyn VadEngine,+ deepgram_api_key: Option<String>,) -> Result<String> {debug!("Starting speech to text for file: {}", file_path);let model = &whisper_model.model;@@ -578,7 +579,13 @@ pub fn stt(if audio_transcription_engine == AudioTranscriptionEngine::Deepgram.into() {// Deepgram implementation- let api_key = get_deepgram_api_key();+ //check if key is set or empty or no chars in it+ let api_key = if deepgram_api_key.clone().is_some() && !deepgram_api_key.clone().unwrap().is_empty() && deepgram_api_key.clone().unwrap().chars().count() > 0 {+ deepgram_api_key.clone().unwrap()+ } else {+ get_deepgram_api_key()+ };+ info!("Using Deepgram API key: {}...", &api_key[..8]);match transcribe_with_deepgram(&api_key, &speech_frames) {Ok(transcription) => Ok(transcription),Err(e) => {@@ -718,6 +725,7 @@ use std::sync::atomic::{AtomicBool, Ordering};pub async fn create_whisper_channel(audio_transcription_engine: Arc<AudioTranscriptionEngine>,vad_engine: VadEngineEnum,+ deepgram_api_key: Option<String>,) -> Result<(UnboundedSender<AudioInput>,UnboundedReceiver<TranscriptionResult>,@@ -758,7 +766,7 @@ pub async fn create_whisper_channel(#[cfg(target_os = "macos")]{autoreleasepool(|| {- match stt(&input.path, &whisper_model, audio_transcription_engine.clone(), &mut *vad_engine) {+ match stt(&input.path, &whisper_model, audio_transcription_engine.clone(), &mut *vad_engine, deepgram_api_key) {Ok(transcription) => TranscriptionResult {input: input.clone(),transcription: Some(transcription),@@ -782,7 +790,7 @@ pub async fn create_whisper_channel(unreachable!("This code should not be reached on non-macOS platforms")}} else {- match stt(&input.path, &whisper_model, audio_transcription_engine.clone(), &mut *vad_engine) {+ match stt(&input.path, &whisper_model, audio_transcription_engine.clone(), deepgram_api_key.clone(), deepgram_api_key) {Ok(transcription) => TranscriptionResult {input: input.clone(),transcription: Some(transcription),diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rsindex 437d3acf6..f90cd8cf4 100644--- a/screenpipe-server/src/bin/screenpipe-server.rs+++ b/screenpipe-server/src/bin/screenpipe-server.rs@@ -334,6 +334,7 @@ async fn main() -> anyhow::Result<()> {&audio_handle,&cli.ignored_windows,&cli.included_windows,+ cli.deepgram_api_key.clone(),);let result = tokio::select! {diff --git a/screenpipe-server/src/cli.rs b/screenpipe-server/src/cli.rsindex b2b489fe7..be6396ac3 100644--- a/screenpipe-server/src/cli.rs+++ b/screenpipe-server/src/cli.rs@@ -184,9 +184,13 @@ pub struct Cli {#[arg(long)]pub included_windows: Vec<String>,- /// Video chunk duration in seconds- #[arg(long, default_value_t = 30)]- pub video_chunk_duration: u64,+ /// Video chunk duration in seconds+ #[arg(long, default_value_t = 30)]+ pub video_chunk_duration: u64,++ /// Deepgram API Key for audio transcription+ #[arg(long = "deepgram-api-key")]+ pub deepgram_api_key: Option<String>,#[command(subcommand)]pub command: Option<Command>,@@ -234,4 +238,4 @@ pub enum PipeCommand {/// New configuration as a JSON stringconfig: String,},-}\ No newline at end of file+}diff --git a/screenpipe-server/src/core.rs b/screenpipe-server/src/core.rsindex df4953a45..c706cc6c4 100644--- a/screenpipe-server/src/core.rs+++ b/screenpipe-server/src/core.rs@@ -43,6 +43,7 @@ pub async fn start_continuous_recording(audio_handle: &Handle,ignored_windows: &[String],include_windows: &[String],+ deepgram_api_key: Option<String>,) -> Result<()> {let (whisper_sender, whisper_receiver, whisper_shutdown_flag) = if audio_disabled {// Create a dummy channel if no audio devices are available, e.g. audio disabled@@ -58,7 +59,7 @@ pub async fn start_continuous_recording(Arc::new(AtomicBool::new(false)),)} else {- create_whisper_channel(audio_transcription_engine.clone(), VadEngineEnum::from(vad_engine)).await?+ create_whisper_channel(audio_transcription_engine.clone(), VadEngineEnum::from(vad_engine), deepgram_api_key).await?};let whisper_sender_clone = whisper_sender.clone();let db_manager_audio = Arc::clone(&db);