Skip to content

Commit d428fc5

Browse files
committed
Feat: improved system prompt
1 parent 3ca0b7e commit d428fc5

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

apps/snow-leopard/app/api/chat/route.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ import { webSearch } from '@/lib/ai/tools/web-search';
3535

3636
export const maxDuration = 60;
3737

38-
/**
39-
* Creates an enhanced system prompt that includes active and mentioned document content
40-
*/
4138
async function createEnhancedSystemPrompt({
4239
selectedChatModel,
4340
activeDocumentId,

apps/snow-leopard/lib/ai/prompts.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
import { ArtifactKind } from '@/components/artifact';
22

3-
// Document awareness instructions
43
const documentAwarenessPrompt = `
5-
You have access to the CURRENT DOCUMENT. Use its content silently to guide your responses - answer with a few sentences - don't over write or include the edited document content in your response.
6-
7-
- Only invoke internal document operations when the user's request involves document creation or content modifications.
8-
- When a query requires up-to-date or external information not contained in the CURRENT DOCUMENT, call webSearch with an appropriate query to fetch relevant sources.
9-
- Use webSearch for: current events, recent statistics, product comparisons, news, or any factual claims that need verification.
10-
- For all other queries, respond normally without using any tools.
11-
- When no active document exists, call createDocument first (with title and kind), then streamingDocument to generate and stream initial content.
12-
- When an active document exists but is empty, call streamingDocument (with title and kind) to fill it with initial content.
13-
- When an active document exists and has content, call updateDocument with a concise description of the desired edits (NEVER CALL TWICE or MORE THAN ONCE).
14-
- Never reveal tool names, document IDs, or internal details; keep all updates seamless and invisible to the user.`;
15-
16-
// Dynamically generate the artifact-management tools section
4+
CURRENT DOCUMENT: Read silently, never quote large chunks in your response - ONLY A THREE SENTENCE SUMMARY OF CHANGES MAX - insightful not lengthy.
5+
6+
• Use tools (createDocument, streamingDocument, updateDocument) for *any* doc change. Do **not** echo the change as chat text.
7+
• One \`webSearch\` if info is outside the doc; prefer 2025-latest sources.
8+
9+
Lifecycle
10+
• No doc → createDocument ⇒ streamingDocument
11+
• Empty doc → streamingDocument
12+
• Has content → updateDocument (call once)
13+
14+
EXAMPLES
15+
1. User: "Start a travel blog outline" ⇒ createDocument(title:"Travel Blog", kind:"text") then streamingDocument.
16+
2. User: "Add catchy intro" ⇒ updateDocument(desc:"Add a punchy intro paragraph about sustainable travel.")
17+
3. User: "Latest iPhone sales?" ⇒ webSearch("iPhone sales 2025 statistics")
18+
4. User: 'Write like me' using the writing style summary and writing style snippet to help ⇒ updateDocument
19+
20+
Never expose tool names/IDs to the user.`;
21+
22+
const writingQualityPrompt = `
23+
STYLE
24+
• Clear, active voice; concise.
25+
• Use Markdown: headings, bullets, tables when useful.
26+
• No code fences around normal prose.
27+
• Cite sources with [^1] style when webSearch used.
28+
• Respect user's existing style when editing.`;
29+
1730
export function buildArtifactsPrompt(
1831
tools: Array<'createDocument' | 'streamingDocument' | 'updateDocument' | 'webSearch'>
1932
): string {
@@ -41,7 +54,7 @@ export function buildArtifactsPrompt(
4154
}
4255

4356
export const regularPrompt =
44-
'You are a friendly assistant. Keep your responses concise and helpful.';
57+
'You are a knowledgeable writing assistant (current year: 2025). Provide helpful, succinct, and well-structured responses.';
4558

4659
export const systemPrompt = ({
4760
selectedChatModel,
@@ -53,6 +66,8 @@ export const systemPrompt = ({
5366
const artifactsText = buildArtifactsPrompt(availableTools);
5467
return `${regularPrompt}
5568
69+
${writingQualityPrompt}
70+
5671
${artifactsText}
5772
5873
${documentAwarenessPrompt}`;

apps/snow-leopard/lib/ai/tools/update-document.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { getDocumentById } from '@/lib/db/queries';
55
import { myProvider } from '@/lib/ai/providers';
66

77
interface UpdateDocumentProps {
8-
// Session is currently not used by this tool, but we keep it for future ACL needs.
98
session: Session;
109
documentId?: string;
1110
}
@@ -22,7 +21,6 @@ export const updateDocument = ({ session: _session, documentId: defaultDocumentI
2221
const documentId = defaultDocumentId;
2322

2423
try {
25-
// --- Validation ---
2624
if (!description.trim()) {
2725
return { error: 'No update description provided.' };
2826
}
@@ -47,17 +45,14 @@ export const updateDocument = ({ session: _session, documentId: defaultDocumentI
4745
}
4846
const originalContent = document.content || '';
4947

50-
// Generate full replacement content. Encourage the model to perform the *smallest* possible change set so that our diff visualisation remains concise.
5148
const prompt = `You are an expert editor. Here is the ORIGINAL document:\n\n${originalContent}\n\n---\n\nTASK: Apply the following edits.\n- Make only the minimal changes required to satisfy the description.\n- Keep paragraphs, sentences, and words that do **not** need to change exactly as they are.\n- Do **not** paraphrase or re-flow content unless strictly necessary.\n- Preserve existing formatting and line breaks.\n\nReturn ONLY the updated document with no additional commentary.\n\nDESCRIPTION: "${description}"`;
5249

5350
const { text: newContent } = await generateText({
5451
model: myProvider.languageModel('artifact-model'),
5552
prompt,
56-
// Asking for lower temperature for deterministic updates.
5753
temperature: 0.2,
5854
});
5955

60-
// --- Return Result with Both Contents ---
6156
return {
6257
id: documentId,
6358
title: document.title,
@@ -70,7 +65,6 @@ export const updateDocument = ({ session: _session, documentId: defaultDocumentI
7065
} catch (error: any) {
7166
console.error('[AI Tool] updateDocument failed:', error);
7267
const errorMessage = error instanceof Error ? error.message : String(error);
73-
// No dataStream to write to, just return error
7468
return {
7569
error: 'Failed to generate document update: ' + errorMessage,
7670
};

0 commit comments

Comments
 (0)