Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

refactor: cleaned up key fetching (created reusable helper between providers)

Gabriel Stein794ed26d4f24
diff --git a/src/components/ui/PromptStudio.tsx b/src/components/ui/PromptStudio.tsx
index cea064bc2..ca4fb7a92 100644
--- a/src/components/ui/PromptStudio.tsx
+++ b/src/components/ui/PromptStudio.tsx
@@ -82,7 +82,7 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
try {
// Check if reasoning model is enabled and if we have the necessary settings
const useReasoningModel = localStorage.getItem("useReasoningModel") === "true";
- const reasoningModel = localStorage.getItem("reasoningModel") || "gpt-3.5-turbo";
+ const reasoningModel = localStorage.getItem("reasoningModel") || "gpt-4o-mini";
const reasoningProvider = localStorage.getItem("reasoningProvider") || "openai";
if (!useReasoningModel) {
@@ -278,7 +278,7 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
const renderTestPlayground = () => {
const useReasoningModel = localStorage.getItem("useReasoningModel") === "true";
- const reasoningModel = localStorage.getItem("reasoningModel") || "gpt-3.5-turbo";
+ const reasoningModel = localStorage.getItem("reasoningModel") || "gpt-4o-mini";
const reasoningProvider = localStorage.getItem("reasoningProvider") || "openai";
return (
diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.ts
index 94fbbf935..044a66e69 100644
--- a/src/services/ReasoningService.ts
+++ b/src/services/ReasoningService.ts
@@ -19,6 +19,31 @@ class ReasoningService extends BaseReasoningService {
this.cacheCleanupStop = this.apiKeyCache.startAutoCleanup();
}
+ private async getApiKey(provider: 'openai' | 'anthropic' | 'gemini'): Promise<string> {
+ let apiKey = this.apiKeyCache.get(provider);
+ if (!apiKey) {
+ try {
+ const keyGetters = {
+ openai: () => window.electronAPI.getOpenAIKey(),
+ anthropic: () => window.electronAPI.getAnthropicKey(),
+ gemini: () => window.electronAPI.getGeminiKey(),
+ };
+ apiKey = await keyGetters[provider]();
+ if (apiKey) {
+ this.apiKeyCache.set(provider, apiKey);
+ }
+ } catch (error) {
+ console.error(`Failed to retrieve ${provider} API key:`, error);
+ }
+ }
+
+ if (!apiKey) {
+ throw new Error(`${provider.charAt(0).toUpperCase() + provider.slice(1)} API key not configured`);
+ }
+
+ return apiKey;
+ }
+
async processText(
text: string,
model: string = "gpt-4o-mini",
@@ -56,21 +81,7 @@ class ReasoningService extends BaseReasoningService {
throw new Error("Already processing a request");
}
- let apiKey = this.apiKeyCache.get("openai");
- if (!apiKey) {
- try {
- apiKey = await window.electronAPI.getOpenAIKey();
- if (apiKey) {
- this.apiKeyCache.set("openai", apiKey);
- }
- } catch (error) {
- console.error("Failed to retrieve OpenAI API key:", error);
- }
- }
-
- if (!apiKey) {
- throw new Error("OpenAI API key not configured");
- }
+ const apiKey = await this.getApiKey('openai');
this.isProcessing = true;
@@ -130,21 +141,7 @@ class ReasoningService extends BaseReasoningService {
throw new Error("Already processing a request");
}
- let apiKey = this.apiKeyCache.get("anthropic");
- if (!apiKey) {
- try {
- apiKey = await window.electronAPI.getAnthropicKey();
- if (apiKey) {
- this.apiKeyCache.set("anthropic", apiKey);
- }
- } catch (error) {
- console.error("Failed to retrieve Anthropic API key:", error);
- }
- }
-
- if (!apiKey) {
- throw new Error("Anthropic API key not configured");
- }
+ const apiKey = await this.getApiKey('anthropic');
this.isProcessing = true;
@@ -223,21 +220,7 @@ class ReasoningService extends BaseReasoningService {
throw new Error("Already processing a request");
}
- let apiKey = this.apiKeyCache.get("gemini");
- if (!apiKey) {
- try {
- apiKey = await window.electronAPI.getGeminiKey();
- if (apiKey) {
- this.apiKeyCache.set("gemini", apiKey);
- }
- } catch (error) {
- console.error("Failed to retrieve Gemini API key:", error);
- }
- }
-
- if (!apiKey) {
- throw new Error("Gemini API key not configured");
- }
+ const apiKey = await this.getApiKey('gemini');
this.isProcessing = true;