Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

Fold dictation cleanup into a single user message with ${transcript} placeholder

Adam Jones52ea3da641df
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swift
index b6ff8c17..3aa81a86 100644
--- a/Sources/Fluid/ContentView.swift
+++ b/Sources/Fluid/ContentView.swift
@@ -1524,15 +1524,37 @@ struct ContentView: View {
DebugLogger.shared.debug("processTextWithAI using provider=\(derivedCurrentProvider), model=\(derivedSelectedModel)", source: "ContentView")
- // Resolve the effective system prompt once so every provider path
- // honors transient overrides such as "Transcribe with Prompt".
+ // Resolve the effective prompt once so every provider path honors
+ // transient overrides such as "Transcribe with Prompt".
let appInfo = self.recordingAppInfo ?? self.getCurrentAppInfo()
- let systemPrompt: String = {
+ let promptText: String = {
let override = overrideSystemPrompt?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
if !override.isEmpty { return override }
return self.buildSystemPrompt(appInfo: appInfo, dictationSlot: dictationSlot)
}()
+ // Dictation cleanup folds the prompt + transcript into a single user
+ // turn (substituting `${transcript}` when present, otherwise appending
+ // the transcript after a blank line). Non-dictation callers — the AI
+ // chat tab specifically — keep the legacy two-message layout where
+ // the prompt is the system turn and the input is the user turn.
+ let isDictationCall = overrideSystemPrompt != nil
+ || dictationSlot != nil
+ || self.currentDictationShortcutSlot(for: self.activeRecordingMode) != nil
+
+ let systemPrompt: String
+ let userMessageContent: String
+ if isDictationCall {
+ systemPrompt = ""
+ userMessageContent = SettingsStore.renderDictationUserMessage(
+ promptText: promptText,
+ transcript: inputText
+ )
+ } else {
+ systemPrompt = promptText
+ userMessageContent = inputText
+ }
+
// Route to Apple Intelligence if selected
if currentSelectedProviderID == "apple-intelligence" {
#if canImport(FoundationModels)
@@ -1561,10 +1583,13 @@ struct ContentView: View {
self.logDictationPromptTrace("Built-in default system prompt (baseline)", value: SettingsStore.defaultSystemPromptText(for: .dictate))
self.logDictationPromptTrace("Final system prompt sent to model", value: systemPrompt)
self.logDictationPromptTrace("Input transcription (Q)", value: inputText)
+ if userMessageContent != inputText {
+ self.logDictationPromptTrace("Final user message sent to model", value: userMessageContent)
+ }
self.logDictationPromptTrace("Selected context text", value: "<none (dictation mode)>")
}
DebugLogger.shared.debug("Using Apple Intelligence for transcription cleanup", source: "ContentView")
- let output = await provider.process(systemPrompt: systemPrompt, userText: inputText)
+ let output = await provider.process(systemPrompt: systemPrompt, userText: userMessageContent)
if self.shouldTracePromptProcessing {
self.logDictationPromptTrace("Model answer (A)", value: output)
}
@@ -1612,6 +1637,9 @@ struct ContentView: View {
}
self.logDictationPromptTrace("Final system prompt sent to model", value: systemPrompt)
self.logDictationPromptTrace("Input transcription (Q)", value: inputText)
+ if userMessageContent != inputText {
+ self.logDictationPromptTrace("Final user message sent to model", value: userMessageContent)
+ }
self.logDictationPromptTrace("Selected context text", value: "<none (dictation mode)>")
}
@@ -1640,11 +1668,15 @@ struct ContentView: View {
)
}
- // Build messages array
- let messages: [[String: Any]] = [
- ["role": "system", "content": systemPrompt],
- ["role": "user", "content": inputText],
- ]
+ // Build messages array. For dictation cleanup the whole prompt +
+ // transcript is folded into a single user message, so we omit the
+ // (empty) system role. Non-dictation callers keep the legacy
+ // system + user shape.
+ var messages: [[String: Any]] = []
+ if !systemPrompt.isEmpty {
+ messages.append(["role": "system", "content": systemPrompt])
+ }
+ messages.append(["role": "user", "content": userMessageContent])
// NOTE: Transcription doesn't need streaming - the full result appears at once
// Streaming is only useful for Command/Rewrite modes where real-time display helps
diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swift
index f4deb986..28ba0819 100644
--- a/Sources/Fluid/Persistence/SettingsStore.swift
+++ b/Sources/Fluid/Persistence/SettingsStore.swift
@@ -952,6 +952,24 @@ final class SettingsStore: ObservableObject {
self.promptResolution(for: mode, appBundleID: appBundleID).source
}
+ /// Literal placeholder that gets substituted with the raw transcription
+ /// when composing the user message for a dictation cleanup call.
+ static let transcriptPlaceholder = "${transcript}"
+
+ /// Compose the user-turn string for a dictation cleanup call by folding
+ /// the transcript into the prompt template. If the template contains the
+ /// `${transcript}` placeholder, the placeholder is replaced; otherwise
+ /// the transcript is appended after a blank line, matching the pre-PR
+ /// behaviour of sending the transcript as a separate user message.
+ static func renderDictationUserMessage(promptText: String, transcript: String) -> String {
+ if promptText.contains(transcriptPlaceholder) {
+ return promptText.replacingOccurrences(of: transcriptPlaceholder, with: transcript)
+ }
+ let trimmedPrompt = promptText.trimmingCharacters(in: .whitespacesAndNewlines)
+ if trimmedPrompt.isEmpty { return transcript }
+ return promptText + "\n\n" + transcript
+ }
+
private func defaultPromptResolution(
for mode: PromptMode,
source: PromptResolutionSource,