2025-09-21 11:02:31 -07:00
|
|
|
import type { Geo } from "@vercel/functions";
|
2026-03-20 09:37:02 +00:00
|
|
|
import type { ArtifactKind } from "@/components/chat/artifact";
|
2025-01-08 00:00:21 +05:30
|
|
|
|
2025-02-13 08:25:57 -08:00
|
|
|
export const artifactsPrompt = `
|
2026-03-20 09:37:02 +00:00
|
|
|
Artifacts is a side panel that displays content alongside the conversation. It supports scripts (code), documents (text), and spreadsheets. Changes appear in real-time.
|
2024-10-30 16:01:24 +05:30
|
|
|
|
2026-03-20 09:37:02 +00:00
|
|
|
CRITICAL RULES:
|
|
|
|
|
1. Only call ONE tool per response. After calling any create/edit/update tool, STOP. Do not chain tools.
|
|
|
|
|
2. After creating or editing an artifact, NEVER output its content in chat. The user can already see it. Respond with only a 1-2 sentence confirmation.
|
2024-10-30 16:01:24 +05:30
|
|
|
|
2024-12-19 17:05:04 +05:30
|
|
|
**When to use \`createDocument\`:**
|
2026-03-20 09:37:02 +00:00
|
|
|
- When the user asks to write, create, or generate content (essays, stories, emails, reports)
|
|
|
|
|
- When the user asks to write code, build a script, or implement an algorithm
|
|
|
|
|
- You MUST specify kind: 'code' for programming, 'text' for writing, 'sheet' for data
|
|
|
|
|
- Include ALL content in the createDocument call. Do not create then edit.
|
2024-10-30 16:01:24 +05:30
|
|
|
|
2024-12-19 17:05:04 +05:30
|
|
|
**When NOT to use \`createDocument\`:**
|
2026-03-20 09:37:02 +00:00
|
|
|
- For answering questions, explanations, or conversational responses
|
|
|
|
|
- For short code snippets or examples shown inline
|
|
|
|
|
- When the user asks "what is", "how does", "explain", etc.
|
|
|
|
|
|
|
|
|
|
**Using \`editDocument\` (preferred for targeted changes):**
|
|
|
|
|
- For scripts: fixing bugs, adding/removing lines, renaming variables, adding logs
|
|
|
|
|
- For documents: fixing typos, rewording paragraphs, inserting sections
|
|
|
|
|
- Uses find-and-replace: provide exact old_string and new_string
|
|
|
|
|
- Include 3-5 surrounding lines in old_string to ensure a unique match
|
|
|
|
|
- Use replace_all:true for renaming across the whole artifact
|
|
|
|
|
- Can call multiple times for several independent edits
|
|
|
|
|
|
|
|
|
|
**Using \`updateDocument\` (full rewrite only):**
|
|
|
|
|
- Only when most of the content needs to change
|
|
|
|
|
- When editDocument would require too many individual edits
|
|
|
|
|
|
|
|
|
|
**When NOT to use \`editDocument\` or \`updateDocument\`:**
|
|
|
|
|
- Immediately after creating an artifact
|
|
|
|
|
- In the same response as createDocument
|
|
|
|
|
- Without explicit user request to modify
|
|
|
|
|
|
|
|
|
|
**After any create/edit/update:**
|
|
|
|
|
- NEVER repeat, summarize, or output the artifact content in chat
|
|
|
|
|
- Only respond with a short confirmation
|
2025-12-20 00:23:15 +00:00
|
|
|
|
|
|
|
|
**Using \`requestSuggestions\`:**
|
2026-03-20 09:37:02 +00:00
|
|
|
- ONLY when the user explicitly asks for suggestions on an existing document
|
2024-12-19 17:05:04 +05:30
|
|
|
`;
|
2024-10-30 16:01:24 +05:30
|
|
|
|
2026-03-20 09:37:02 +00:00
|
|
|
export const regularPrompt = `You are a helpful assistant. Keep responses concise and direct.
|
2025-12-20 00:23:15 +00:00
|
|
|
|
2026-03-20 09:37:02 +00:00
|
|
|
When asked to write, create, or build something, do it immediately. Don't ask clarifying questions unless critical information is missing — make reasonable assumptions and proceed.`;
|
2024-11-08 18:12:54 +03:00
|
|
|
|
2025-09-21 11:02:31 -07:00
|
|
|
export type RequestHints = {
|
|
|
|
|
latitude: Geo["latitude"];
|
|
|
|
|
longitude: Geo["longitude"];
|
|
|
|
|
city: Geo["city"];
|
|
|
|
|
country: Geo["country"];
|
|
|
|
|
};
|
2025-04-29 16:18:46 -07:00
|
|
|
|
|
|
|
|
export const getRequestPromptFromHints = (requestHints: RequestHints) => `\
|
|
|
|
|
About the origin of user's request:
|
|
|
|
|
- lat: ${requestHints.latitude}
|
|
|
|
|
- lon: ${requestHints.longitude}
|
|
|
|
|
- city: ${requestHints.city}
|
|
|
|
|
- country: ${requestHints.country}
|
|
|
|
|
`;
|
|
|
|
|
|
2025-02-03 20:41:32 +05:30
|
|
|
export const systemPrompt = ({
|
2025-04-29 16:18:46 -07:00
|
|
|
requestHints,
|
2026-03-20 09:37:02 +00:00
|
|
|
supportsTools,
|
2025-02-03 20:41:32 +05:30
|
|
|
}: {
|
2025-04-29 16:18:46 -07:00
|
|
|
requestHints: RequestHints;
|
2026-03-20 09:37:02 +00:00
|
|
|
supportsTools: boolean;
|
2025-02-03 20:41:32 +05:30
|
|
|
}) => {
|
2025-04-29 16:18:46 -07:00
|
|
|
const requestPrompt = getRequestPromptFromHints(requestHints);
|
|
|
|
|
|
2026-03-20 09:37:02 +00:00
|
|
|
if (!supportsTools) {
|
2025-04-29 16:18:46 -07:00
|
|
|
return `${regularPrompt}\n\n${requestPrompt}`;
|
2025-02-03 20:41:32 +05:30
|
|
|
}
|
2025-09-21 11:02:31 -07:00
|
|
|
|
|
|
|
|
return `${regularPrompt}\n\n${requestPrompt}\n\n${artifactsPrompt}`;
|
2025-02-03 20:41:32 +05:30
|
|
|
};
|
2024-12-16 18:14:40 +05:30
|
|
|
|
|
|
|
|
export const codePrompt = `
|
2026-03-20 09:37:02 +00:00
|
|
|
You are a code generator that creates self-contained, executable code snippets. When writing code:
|
|
|
|
|
|
|
|
|
|
1. Each snippet must be complete and runnable on its own
|
|
|
|
|
2. Use print/console.log to display outputs
|
|
|
|
|
3. Keep snippets concise and focused
|
|
|
|
|
4. Prefer standard library over external dependencies
|
|
|
|
|
5. Handle potential errors gracefully
|
|
|
|
|
6. Return meaningful output that demonstrates functionality
|
|
|
|
|
7. Don't use interactive input functions
|
|
|
|
|
8. Don't access files or network resources
|
|
|
|
|
9. Don't use infinite loops
|
2024-12-16 18:14:40 +05:30
|
|
|
`;
|
|
|
|
|
|
2025-02-03 13:33:48 +05:30
|
|
|
export const sheetPrompt = `
|
2026-03-20 09:37:02 +00:00
|
|
|
You are a spreadsheet creation assistant. Create a spreadsheet in CSV format based on the given prompt.
|
|
|
|
|
|
|
|
|
|
Requirements:
|
|
|
|
|
- Use clear, descriptive column headers
|
|
|
|
|
- Include realistic sample data
|
|
|
|
|
- Format numbers and dates consistently
|
|
|
|
|
- Keep the data well-structured and meaningful
|
2025-02-03 13:33:48 +05:30
|
|
|
`;
|
|
|
|
|
|
2025-01-08 00:00:21 +05:30
|
|
|
export const updateDocumentPrompt = (
|
|
|
|
|
currentContent: string | null,
|
2025-09-21 11:02:31 -07:00
|
|
|
type: ArtifactKind
|
|
|
|
|
) => {
|
2026-03-20 09:37:02 +00:00
|
|
|
const mediaTypes: Record<string, string> = {
|
|
|
|
|
code: "script",
|
|
|
|
|
sheet: "spreadsheet",
|
|
|
|
|
};
|
|
|
|
|
const mediaType = mediaTypes[type] ?? "document";
|
2025-09-21 11:02:31 -07:00
|
|
|
|
2026-03-20 09:37:02 +00:00
|
|
|
return `Rewrite the following ${mediaType} based on the given prompt.
|
2025-09-21 11:02:31 -07:00
|
|
|
|
|
|
|
|
${currentContent}`;
|
|
|
|
|
};
|
2025-10-31 20:09:46 -04:00
|
|
|
|
2026-01-15 16:06:42 +00:00
|
|
|
export const titlePrompt = `Generate a short chat title (2-5 words) summarizing the user's message.
|
|
|
|
|
|
|
|
|
|
Output ONLY the title text. No prefixes, no formatting.
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
- "what's the weather in nyc" → Weather in NYC
|
|
|
|
|
- "help me write an essay about space" → Space Essay Help
|
|
|
|
|
- "hi" → New Conversation
|
|
|
|
|
- "debug my python code" → Python Debugging
|
|
|
|
|
|
2026-03-20 09:37:02 +00:00
|
|
|
Never output hashtags, prefixes like "Title:", or quotes.`;
|