diff --git a/src/lib/components/LoadingModal.svelte b/src/lib/components/LoadingModal.svelte index c693c4e..8d167ab 100644 --- a/src/lib/components/LoadingModal.svelte +++ b/src/lib/components/LoadingModal.svelte @@ -1,256 +1,347 @@ \ No newline at end of file + @keyframes fade-in { + from { + opacity: 0; + } + to { + opacity: 1; + } + } + diff --git a/src/lib/llm.test.ts b/src/lib/llm.test.ts index 351b372..568adea 100644 --- a/src/lib/llm.test.ts +++ b/src/lib/llm.test.ts @@ -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', () => { diff --git a/src/lib/llm.ts b/src/lib/llm.ts index 9e9552e..0916aaa 100644 --- a/src/lib/llm.ts +++ b/src/lib/llm.ts @@ -22,10 +22,11 @@ export interface ConvertResult { } export function buildSystemPrompt(styleModifier: string, intensityInstruction: string): string { - const intensityFilled = intensityInstruction.replace('{style}', styleModifier); + // Strip the leading verb ("Rewrite ") from the style modifier since + // it's redundant with the "Rewrite the text" line already in the prompt. + const styleDetail = styleModifier.replace(/^Rewrite\s+/i, ''); return `You are an expert English style converter. -${intensityFilled}. -${styleModifier} +Rewrite the text ${intensityInstruction}: ${styleDetail} Preserve the core meaning but fully transform the voice and tone. Output ONLY the converted text — no explanations, no labels, no quotes.`; } diff --git a/src/lib/styles.test.ts b/src/lib/styles.test.ts index b064e2a..ecd9e4c 100644 --- a/src/lib/styles.test.ts +++ b/src/lib/styles.test.ts @@ -91,7 +91,7 @@ describe('getIntensityConfig', () => { const config = getIntensityConfig(i); expect(config).toBeDefined(); expect(config!.label).toBeTruthy(); - expect(config!.instruction).toContain('{style}'); + expect(config!.instruction).toBeTruthy(); } }); @@ -103,10 +103,10 @@ describe('getIntensityConfig', () => { expect(getIntensityConfig(6)).toBeUndefined(); }); - it('all intensity instructions contain {style} placeholder', () => { + it('intensity instructions do not contain {style} placeholder', () => { for (let i = 1; i <= 5; i++) { const config = getIntensityConfig(i); - expect(config!.instruction).toContain('{style}'); + expect(config!.instruction).not.toContain('{style}'); } }); }); \ No newline at end of file diff --git a/src/lib/styles.ts b/src/lib/styles.ts index 88d734e..2e93a12 100644 --- a/src/lib/styles.ts +++ b/src/lib/styles.ts @@ -195,17 +195,11 @@ export const intensityMap: Record< number, { label: string; instruction: string } > = { - 1: { label: "Subtle", instruction: "lightly hint at a {style} tone" }, - 2: { label: "Moderate", instruction: "rewrite with a {style} tone" }, - 3: { label: "Strong", instruction: "rewrite strongly in a {style} style" }, - 4: { - label: "Heavy", - instruction: "rewrite completely in {style} — fully commit to the voice", - }, - 5: { - label: "Maximum", - instruction: "go absolutely all-out {style} — no restraint", - }, + 1: { label: "Subtle", instruction: "subtly, with a light touch" }, + 2: { label: "Moderate", instruction: "with moderate intensity" }, + 3: { label: "Strong", instruction: "strongly" }, + 4: { label: "Heavy", instruction: "completely, fully committing to the voice" }, + 5: { label: "Maximum", instruction: "with absolute maximum intensity, no restraint" }, }; export function getStylesByCategory(categoryId: string): Style[] {