fix(llm): stop leaking instruction prompts instead of processed text
Running a custom instruction (translate, summarise, rewrite, explain code,
free prompt) inserted the instruction's own wording instead of the result.
Two faults stacked:
The instruction was passed as the text to process, leaving the system-prompt
argument empty. `BASE_SYSTEM_PROMPTS` has no `custom` key, so resolution fell
back to `refine` without saying so, and the model dutifully polished the
instruction it had been handed. The transcript never reached it.
And only `{{text}}` was substituted, which none of the five built-in
instructions use — they carry `{{targetLanguage}}`, `{{userPrompt}}`, or no
placeholder at all. The substitution was a no-op from the day it was written:
the presets landed ten hours before the code that expected them.
- Instruction prompts now go to the system-prompt argument and the transcript
to the text argument. Instructions that spell out `{{text}}` keep their old
meaning, so hand-written ones still work.
- `renderInstructionPrompt` resolves `{{text}}`, `{{userPrompt}}` and
`{{targetLanguage}}` in one place, and warns by name when a placeholder is
left standing rather than letting it reach the model.
- `resolveSystemPrompt` no longer drops silently to `refine` for `custom`.
- Voice shortcuts no longer die at the `defaultLLMAction === 'none'` gate; an
explicitly named instruction outranks the default. Without one, `none` still
passes the transcript through untouched.
- `translate` receives its target language instead of relying on a default two
call frames away. It is still always English — `AppConfig` has no key for it,
and neither `language` (UI locale) nor `sttLanguage` (source language) can
stand in. Choosing a target language needs a setting and is not in this fix.
- Chains ran instructions with placeholders intact; they share the same
resolution now.
- The command screen's pipeline bench called `llm.generate`, which preload does
not expose, so every run threw and the catch showed the input back as if it
had succeeded. It uses `llm.process` now, over the same path production
takes, and a failure reads as a failure.
Present since the feature shipped: the custom-instruction path has never
worked. Plain actions (refine, summarise, grammar, expand) were unaffected and
are now covered by tests so they stay that way.
This commit is contained in:
parent
30d51c952f
commit
99f06c253c
14 changed files with 992 additions and 44 deletions
|
|
@ -26,6 +26,7 @@ import {
|
|||
Mic,
|
||||
Cpu,
|
||||
ClipboardCopy,
|
||||
TriangleAlert,
|
||||
} from 'lucide-react'
|
||||
import {
|
||||
MetalCard,
|
||||
|
|
@ -68,6 +69,7 @@ export function CommandsPage(): React.ReactElement {
|
|||
// Interactive Pipeline Test State
|
||||
const [testInput, setTestInput] = useState('')
|
||||
const [testResult, setTestResult] = useState<string | null>(null)
|
||||
const [testError, setTestError] = useState<string | null>(null)
|
||||
const [testing, setTesting] = useState(false)
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
|
|
@ -175,23 +177,28 @@ export function CommandsPage(): React.ReactElement {
|
|||
}
|
||||
}
|
||||
|
||||
// 이 벤치는 실제 받아쓰기와 같은 경로(llm.process → processText)를 탄다.
|
||||
// 지시문 원문을 customPrompt로 넘기면 메인 프로세스가 플레이스홀더 치환과
|
||||
// 시스템 프롬프트 배치를 처리한다 — 치환 규칙을 렌더러에 복제하지 않는다.
|
||||
const handleRunPipelineTest = async () => {
|
||||
if (!testInput.trim()) return
|
||||
setTesting(true)
|
||||
setTestResult(null)
|
||||
setTestError(null)
|
||||
try {
|
||||
const activeInst = instructions.find((i) => i.id === activeId)
|
||||
const prompt = activeInst?.prompt || '다음 문장을 자연스럽고 깔끔하게 다듬어주세요:'
|
||||
const res = await window.electronAPI.llm.generate({
|
||||
prompt: `${prompt}\n\n${testInput.trim()}`,
|
||||
})
|
||||
const res = await window.electronAPI.llm.process(
|
||||
activeInst
|
||||
? { text: testInput.trim(), action: 'custom', customPrompt: activeInst.prompt }
|
||||
: { text: testInput.trim(), action: 'refine' },
|
||||
)
|
||||
if (res.success) {
|
||||
setTestResult(res.data.text)
|
||||
setTestResult(res.data.processedText)
|
||||
} else {
|
||||
setTestResult(testInput.trim())
|
||||
setTestError(res.error.message || t('popup.error.default'))
|
||||
}
|
||||
} catch {
|
||||
setTestResult(testInput.trim())
|
||||
} catch (error) {
|
||||
setTestError(error instanceof Error ? error.message : t('popup.error.default'))
|
||||
} finally {
|
||||
setTesting(false)
|
||||
}
|
||||
|
|
@ -543,6 +550,25 @@ export function CommandsPage(): React.ReactElement {
|
|||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{testError && (
|
||||
<Box
|
||||
sx={{
|
||||
p: 2,
|
||||
bgcolor: d3roPalette.status.dangerBg,
|
||||
borderRadius: d3roRadius.inner,
|
||||
border: `1px solid ${d3roPalette.status.danger}`,
|
||||
display: 'flex',
|
||||
alignItems: 'flex-start',
|
||||
gap: 1.5,
|
||||
}}
|
||||
>
|
||||
<TriangleAlert size={16} style={{ color: d3roPalette.status.danger, marginTop: 2, flexShrink: 0 }} />
|
||||
<Typography sx={{ fontFamily: d3roFontSans, fontSize: '13.5px', color: d3roPalette.status.danger, lineHeight: 1.6 }}>
|
||||
{testError}
|
||||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
</MetalCard>
|
||||
</Box>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue