Skip to content

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

Merge branch 'main' into align-recording-feedback

Gabriel Stein33696139f894
diff --cc src/services/ReasoningService.ts
index c156aeff8,a89c2ec66..284c1375f
--- a/src/services/ReasoningService.ts
+++ b/src/services/ReasoningService.ts
@@@ -135,10 -127,10 +127,10 @@@ class ReasoningService extends BaseReas
}
}
- private async getApiKey(provider: 'openai' | 'anthropic' | 'gemini'): Promise<string> {
+ private async getApiKey(provider: 'openai' | 'anthropic' | 'gemini' | 'groq'): Promise<string> {
let apiKey = this.apiKeyCache.get(provider);
-
+
- debugLogger.logReasoning(`${provider.toUpperCase()}_KEY_RETRIEVAL`, {
+ logger.logReasoning(`${provider.toUpperCase()}_KEY_RETRIEVAL`, {
provider,
fromCache: !!apiKey,
cacheSize: this.apiKeyCache.size || 0
@@@ -731,158 -719,6 +723,158 @@@
}
}
+ private async processWithGroq(
+ text: string,
+ model: string,
+ agentName: string | null = null,
+ config: ReasoningConfig = {}
+ ): Promise<string> {
- debugLogger.logReasoning("GROQ_START", {
++ logger.logReasoning("GROQ_START", {
+ model,
+ agentName,
+ hasApiKey: false
+ });
+
+ if (this.isProcessing) {
+ throw new Error("Already processing a request");
+ }
+
+ // Groq uses its own API key
+ const apiKey = await this.getApiKey('groq');
+
- debugLogger.logReasoning("GROQ_API_KEY", {
++ logger.logReasoning("GROQ_API_KEY", {
+ hasApiKey: !!apiKey,
+ keyLength: apiKey?.length || 0
+ });
+
+ this.isProcessing = true;
+
+ try {
+ const systemPrompt = "You are a dictation assistant. Clean up text by fixing grammar and punctuation. Output ONLY the cleaned text without any explanations, options, or commentary.";
+ const userPrompt = this.getReasoningPrompt(text, agentName, config);
+
+ // Build messages array for Chat Completions format
+ const messages = [
+ { role: "system", content: systemPrompt },
+ { role: "user", content: userPrompt }
+ ];
+
+ const requestBody: any = {
+ model: model,
+ messages,
+ temperature: config.temperature || 0.6,
+ max_tokens: config.maxTokens || Math.max(
+ 4096,
+ this.calculateMaxTokens(
+ text.length,
+ TOKEN_LIMITS.MIN_TOKENS,
+ TOKEN_LIMITS.MAX_TOKENS,
+ TOKEN_LIMITS.TOKEN_MULTIPLIER
+ )
+ ),
+ };
+
+ const endpoint = buildApiUrl(API_ENDPOINTS.GROQ_BASE, '/chat/completions');
+
- debugLogger.logReasoning("GROQ_REQUEST", {
++ logger.logReasoning("GROQ_REQUEST", {
+ endpoint,
+ model,
+ hasApiKey: !!apiKey,
+ requestBody: JSON.stringify(requestBody).substring(0, 200)
+ });
+
+ const response = await withRetry(
+ async () => {
+ const res = await fetch(endpoint, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${apiKey}`,
+ },
+ body: JSON.stringify(requestBody),
+ });
+
+ if (!res.ok) {
+ const errorText = await res.text();
+ let errorData: any = { error: res.statusText };
+
+ try {
+ errorData = JSON.parse(errorText);
+ } catch {
+ errorData = { error: errorText || res.statusText };
+ }
+
- debugLogger.logReasoning("GROQ_API_ERROR_DETAIL", {
++ logger.logReasoning("GROQ_API_ERROR_DETAIL", {
+ status: res.status,
+ statusText: res.statusText,
+ error: errorData,
+ errorMessage: errorData.error?.message || errorData.message || errorData.error,
+ fullResponse: errorText.substring(0, 500)
+ });
+
+ const errorMessage = errorData.error?.message || errorData.message || errorData.error || `Groq API error: ${res.status}`;
+ throw new Error(errorMessage);
+ }
+
+ const jsonResponse = await res.json();
+
- debugLogger.logReasoning("GROQ_RAW_RESPONSE", {
++ logger.logReasoning("GROQ_RAW_RESPONSE", {
+ hasResponse: !!jsonResponse,
+ responseKeys: jsonResponse ? Object.keys(jsonResponse) : [],
+ hasChoices: !!jsonResponse?.choices,
+ choicesLength: jsonResponse?.choices?.length || 0,
+ fullResponse: JSON.stringify(jsonResponse).substring(0, 500)
+ });
+
+ return jsonResponse;
+ },
+ createApiRetryStrategy("Groq")
+ );
+
+ // Extract text from Chat Completions format
+ if (!response.choices || !response.choices[0]) {
- debugLogger.logReasoning("GROQ_RESPONSE_ERROR", {
++ logger.logReasoning("GROQ_RESPONSE_ERROR", {
+ model,
+ response: JSON.stringify(response).substring(0, 500),
+ hasChoices: !!response.choices,
+ choicesCount: response.choices?.length || 0
+ });
+ throw new Error("Invalid response structure from Groq API");
+ }
+
+ const choice = response.choices[0];
+ const responseText = choice.message?.content?.trim() || "";
+
+ if (!responseText) {
- debugLogger.logReasoning("GROQ_EMPTY_RESPONSE", {
++ logger.logReasoning("GROQ_EMPTY_RESPONSE", {
+ model,
+ finishReason: choice.finish_reason,
+ hasMessage: !!choice.message,
+ response: JSON.stringify(choice).substring(0, 500)
+ });
+ throw new Error("Groq returned empty response");
+ }
+
- debugLogger.logReasoning("GROQ_RESPONSE", {
++ logger.logReasoning("GROQ_RESPONSE", {
+ model,
+ responseLength: responseText.length,
+ tokensUsed: response.usage?.total_tokens || 0,
+ success: true
+ });
+
+ return responseText;
+ } catch (error) {
- debugLogger.logReasoning("GROQ_ERROR", {
++ logger.logReasoning("GROQ_ERROR", {
+ model,
+ error: (error as Error).message,
+ errorType: (error as Error).name
+ });
+ throw error;
+ } finally {
+ this.isProcessing = false;
+ }
+ }
+
async isAvailable(): Promise<boolean> {
try {
// Check if we have at least one configured API key or local model available