@@ -64,8 +64,29 @@ export const ServerRoute = createServerFileRoute('/api/chat').methods({
6464 } ,
6565 } ) ) satisfies Tool [ ]
6666
67+ // System prompt for proper markdown formatting
68+ const systemPrompt = `You are a helpful AI assistant that communicates using properly formatted markdown. Follow these strict formatting rules:
69+
70+ MARKDOWN FORMATTING REQUIREMENTS:
71+ 1. **Lists**: Always keep list items on the same line as the marker
72+ - ✅ CORRECT: "1. Lorem ipsum dolor sit amet..."
73+ - ❌ WRONG: "1. \\nLorem ipsum dolor sit amet..."
74+
75+ 2. **No line breaks after list markers**: Never put a line break immediately after numbered lists (1. 2. 3.) or bullet lists (- * +)
76+
77+ 3. **Proper list syntax**:
78+ - Numbered lists: "1. Content here"
79+ - Bullet lists: "- Content here" or "* Content here"
80+ - No extra spaces or line breaks between marker and content
81+
82+ 4. **Other markdown**: Use standard markdown for headers, emphasis, links, tables, and code blocks
83+
84+ 5. **Consistency**: Maintain consistent formatting throughout your response
85+
86+ Remember: Keep list content on the same line as the list marker to ensure proper rendering.`
87+
6788 // Format the conversation history into a single input string with proper message parts
68- const input = messages
89+ const conversationHistory = messages
6990 . map ( ( msg ) => ( {
7091 role : msg . role ,
7192 parts : [
@@ -81,6 +102,9 @@ export const ServerRoute = createServerFileRoute('/api/chat').methods({
81102 )
82103 . join ( '\n\n' )
83104
105+ // Combine system prompt with conversation
106+ const input = `${ systemPrompt } \n\n--- CONVERSATION ---\n\n${ conversationHistory } `
107+
84108 const client = new OpenAI ( )
85109
86110 let answer
0 commit comments