Skip to content

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

refactor: extract shared generateNoteTitle utility

Gabriel Stein715c3c77abc5
diff --git a/src/components/notes/UploadAudioView.tsx b/src/components/notes/UploadAudioView.tsx
index 7d05ecf85..351dbc9d7 100644
--- a/src/components/notes/UploadAudioView.tsx
+++ b/src/components/notes/UploadAudioView.tsx
@@ -30,9 +30,9 @@ import { useAuth } from "../../hooks/useAuth";
import { useUsage } from "../../hooks/useUsage";
import { useSettings } from "../../hooks/useSettings";
import { withSessionRefresh } from "../../lib/neonAuth";
-import reasoningService from "../../services/ReasoningService";
import { getAllReasoningModels } from "../../models/ModelRegistry";
import { useSettingsStore, selectIsCloudReasoningMode } from "../../stores/settingsStore";
+import { generateNoteTitle } from "../../utils/generateTitle";
const TranscriptionModelPicker = React.lazy(() => import("../TranscriptionModelPicker"));
@@ -44,9 +44,6 @@ const BYOK_MAX_FILE_SIZE = 25 * 1024 * 1024; // 25 MB — hard limit for bring-y
const CLOUD_FREE_MAX_FILE_SIZE = 25 * 1024 * 1024; // 25 MB — free plan cloud limit
const CLOUD_PRO_MAX_FILE_SIZE = 500 * 1024 * 1024; // 500 MB — pro plan cloud limit
-const TITLE_SYSTEM_PROMPT =
- "Generate a concise 3-8 word title for these transcribed notes. Return ONLY the title text, nothing else — no quotes, no prefix, no explanation.";
-
function formatFileSize(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
@@ -272,16 +269,7 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: Uploa
? ""
: effectiveReasoningModel || getAllReasoningModels()[0]?.value;
if (!model && !isCloudReasoning) return "";
- try {
- const title = await reasoningService.processText(text.slice(0, 2000), model, null, {
- systemPrompt: TITLE_SYSTEM_PROMPT,
- temperature: 0.3,
- });
- const cleaned = title.trim().replace(/^["']|["']$/g, "");
- return cleaned.length > 0 && cleaned.length < 100 ? cleaned : "";
- } catch {
- return "";
- }
+ return generateNoteTitle(text, model);
};
const handleBrowse = async () => {
diff --git a/src/hooks/useActionProcessing.ts b/src/hooks/useActionProcessing.ts
index 4fcec4e92..8210a1edd 100644
--- a/src/hooks/useActionProcessing.ts
+++ b/src/hooks/useActionProcessing.ts
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
import reasoningService from "../services/ReasoningService";
import type { ActionItem } from "../types/electron";
import { getEffectiveReasoningModel } from "../stores/settingsStore";
+import { generateNoteTitle } from "../utils/generateTitle";
export type ActionProcessingState = "idle" | "processing" | "success";
@@ -30,9 +31,6 @@ CONTENT RULES:
Instructions: `;
-const TITLE_SYSTEM_PROMPT =
- "Generate a concise 3-8 word title for these meeting notes. Return ONLY the title text, nothing else — no quotes, no prefix, no explanation.";
-
interface UseActionProcessingOptions {
onSuccess: (enhancedContent: string, prompt: string, title?: string) => void;
onError: (errorMessage: string) => void;
@@ -84,14 +82,8 @@ export function useActionProcessing({ onSuccess, onError }: UseActionProcessingO
let title: string | undefined;
if (options.isMeetingNote) {
- try {
- const raw = await reasoningService.processText(enhanced.slice(0, 2000), modelId, null, {
- systemPrompt: TITLE_SYSTEM_PROMPT,
- temperature: 0.3,
- });
- const cleaned = raw.trim().replace(/^["']|["']$/g, "");
- if (cleaned.length > 0 && cleaned.length < 100) title = cleaned;
- } catch {}
+ const generated = await generateNoteTitle(enhanced, modelId);
+ if (generated) title = generated;
}
if (cancelledRef.current) return;
diff --git a/src/utils/generateTitle.ts b/src/utils/generateTitle.ts
new file mode 100644
index 000000000..39c2fc89d
--- /dev/null
+++ b/src/utils/generateTitle.ts
@@ -0,0 +1,17 @@
+import reasoningService from "../services/ReasoningService";
+
+const TITLE_SYSTEM_PROMPT =
+ "Generate a concise 3-8 word title for these notes. Return ONLY the title text, nothing else — no quotes, no prefix, no explanation.";
+
+export async function generateNoteTitle(text: string, modelId: string): Promise<string> {
+ try {
+ const raw = await reasoningService.processText(text.slice(0, 2000), modelId, null, {
+ systemPrompt: TITLE_SYSTEM_PROMPT,
+ temperature: 0.3,
+ });
+ const cleaned = raw.trim().replace(/^["']|["']$/g, "");
+ return cleaned.length > 0 && cleaned.length < 100 ? cleaned : "";
+ } catch {
+ return "";
+ }
+}