Skip to content

Commit b2664f8

Browse files
committed
fix(ai): restore Groq/Gemini enhancement path and keep OpenAI-compatible config; cache non-openai keys in backend
- Enhance enhance_transcription to route groq/gemini via AIProviderFactory using cached API keys - Keep OpenAI-compatible base_url + no_auth flow unchanged - Frontend: saveApiKey caches keys for groq/gemini and validates only for openai - Verified: cargo test (150/150) and TS typecheck pass
1 parent a28030b commit b2664f8

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src-tauri/src/commands/ai.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,25 @@ pub async fn enhance_transcription(text: String, app: tauri::AppHandle) -> Resul
584584
opts.insert("base_url".into(), serde_json::Value::String(base_url));
585585
opts.insert("no_auth".into(), serde_json::Value::Bool(no_auth));
586586
(api_key, opts)
587+
} else if provider == "groq" || provider == "gemini" {
588+
// Require API key from in-memory cache
589+
let cache = API_KEY_CACHE
590+
.lock()
591+
.map_err(|_| "Failed to access cache".to_string())?;
592+
let key_name = format!("ai_api_key_{}", provider);
593+
let api_key = cache
594+
.get(&key_name)
595+
.cloned()
596+
.ok_or_else(|| {
597+
log::error!(
598+
"API key not found in cache for provider: {}. Cache keys: {:?}",
599+
provider,
600+
cache.keys().collect::<Vec<_>>()
601+
);
602+
"API key not found in cache".to_string()
603+
})?;
604+
605+
(api_key, std::collections::HashMap::new())
587606
} else {
588607
return Err("Unsupported provider".to_string());
589608
};

src/utils/keyring.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ export const saveApiKey = async (provider: string, apiKey: string): Promise<void
4141
const key = `ai_api_key_${provider}`;
4242
await keyringSet(key, apiKey);
4343

44-
// Validate and cache in backend for fast access during transcription
45-
await invoke('validate_and_cache_api_key', { provider, apiKey });
44+
// Cache or validate depending on provider
45+
if (provider === 'openai') {
46+
// OpenAI-compatible requires validation (may include no-auth path via separate modal)
47+
await invoke('validate_and_cache_api_key', { provider, apiKey });
48+
} else {
49+
// For Groq/Gemini, just cache the key; validation happens during usage
50+
await invoke('cache_ai_api_key', { provider, apiKey });
51+
}
4652

4753
console.log(`[Keyring] API key saved and validated for ${provider}`);
4854

0 commit comments

Comments
 (0)