fix: eliminate redundancy in system prompt

The old prompt had two problems:
1. {style} placeholder was filled with the full promptModifier sentence,
   producing gibberish like "rewrite strongly in a Rewrite in a
   sarcastic... style"
2. The promptModifier was then repeated as its own line

New design separates concerns cleanly:
- intensityMap no longer uses {style} placeholder — instructions are
  pure intensity adverbs ("strongly", "subtly, with a light touch", etc.)
- buildSystemPrompt strips the leading "Rewrite" verb from the style
  modifier and combines both into one non-redundant instruction:
  "Rewrite the text strongly: in a sarcastic, snarky tone with biting wit"

Example outputs by intensity:
  1: Rewrite the text subtly, with a light touch: in a sarcastic...
  3: Rewrite the text strongly: in a sarcastic...
  5: Rewrite the text with absolute maximum intensity, no restraint: ...
This commit is contained in:
2026-04-12 23:23:58 -04:00
parent cb8755f59e
commit 90bb701068
5 changed files with 344 additions and 250 deletions

View File

@@ -2,25 +2,33 @@ import { describe, it, expect } from 'vitest';
import { buildSystemPrompt, buildUserMessage } from '$lib/llm';
describe('buildSystemPrompt', () => {
it('fills in {style} placeholder from intensity instruction', () => {
it('combines intensity and style detail without redundancy', () => {
const result = buildSystemPrompt(
'Rewrite in a sarcastic, snarky tone with biting wit',
'rewrite strongly in a {style} style'
'strongly'
);
expect(result).toContain('rewrite strongly in a Rewrite in a sarcastic, snarky tone with biting wit style');
expect(result).not.toContain('{style}');
expect(result).toContain('Rewrite the text strongly: in a sarcastic, snarky tone with biting wit');
});
it('includes the style modifier on its own line', () => {
const result = buildSystemPrompt('some modifier', 'lightly hint at a {style} tone');
expect(result).toContain('some modifier');
it('strips leading "Rewrite " verb from style modifier to avoid duplication', () => {
const result = buildSystemPrompt(
'Rewrite like a pirate with arrrs and nautical terms',
'completely, fully committing to the voice'
);
expect(result).toContain('like a pirate with arrrs and nautical terms');
expect(result).not.toMatch(/Rewrite.*Rewrite/i);
});
it('includes the core instruction text', () => {
const result = buildSystemPrompt('test', 'rewrite with a {style} tone');
const result = buildSystemPrompt('test modifier', 'with moderate intensity');
expect(result).toContain('You are an expert English style converter');
expect(result).toContain('Output ONLY the converted text');
});
it('does not contain {style} placeholder', () => {
const result = buildSystemPrompt('test modifier', 'strongly');
expect(result).not.toContain('{style}');
});
});
describe('buildUserMessage', () => {