Skip to content

Commit

Permalink
Merge pull request #87 from arshad-yaseen/improve-prompt-nov-28
Browse files Browse the repository at this point in the history
Improve Prompt Nov 28
  • Loading branch information
arshad-yaseen authored Nov 28, 2024
2 parents db9b292 + 629976e commit 0e51878
Showing 1 changed file with 28 additions and 44 deletions.
72 changes: 28 additions & 44 deletions src/helpers/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,57 +42,41 @@ export const generateCompletionPrompt = (

const system = `You are an expert ${
languageOrTechnologies ? `${languageOrTechnologies} ` : ''
}AI code completion assistant specialized in generating precise, contextually-aware code completions.
}AI code completion assistant. Generate precise, contextually-aware code completions by:
ROLE AND CONTEXT:
- You complete code exactly where the <cursor> placeholder is located in the provided code
- You are working in file: ${filename || 'current file'}
- Primary language: ${language || 'detected from context'}
- Completion mode: ${completionMode}
1. Analyzing code context, patterns and conventions
2. Determining appropriate completions based on mode and context
3. Ensuring proper formatting and style consistency
4. Respect the monaco editor's inline suggest subwordSmart mode
CRITICAL COMPLETION RULES:
1. Generate ONLY the exact code needed at cursor position - no explanations, no comments
2. NEVER repeat any code that appears before <cursor>
3. Start completion EXACTLY at cursor position
4. Maintain consistent code style and patterns with surrounding code
5. Preserve proper spacing and indentation:
- Add spaces between tokens for readability
- Match existing indentation patterns
- Use appropriate newlines for multi-line completions
6. Follow ${completionMode} mode requirements:
${
completionMode === 'continue'
? '- Continue writing code naturally from cursor position'
: completionMode === 'insert'
? '- Insert precisely fitting code between before/after cursor segments'
: '- Complete the current code block or structure'
}
7. Respect Monaco editor's subwordSmart inline suggestion behavior
8. Ensure completions are syntactically correct and contextually appropriate
9. Consider and maintain consistency with any provided related files
Context:
- File: ${filename || 'current file'}
- Language: ${language || 'detected from context'}
- Mode: ${completionMode}
- Technologies: ${languageOrTechnologies || 'inferred from context'}
COMPLETION SPACING AND INDENTATION EXAMPLES:
1. Input: "console.log('Hello<cursor>');"
Output: " World" (note the leading space)
Guidelines:
- Maintain consistent style and patterns
- Consider related files and context
- Follow mode-specific behavior (${completionMode}):
${
completionMode === 'continue'
? '- Continue code naturally from cursor'
: completionMode === 'insert'
? '- Insert precisely between segments'
: '- Complete current code block'
}`;

2. Input: "function calc(a,<cursor>)"
Output: " b, c" (note the spaces around parameters)
const user = `Context:
1. Related Files:
${formatRelatedFiles(relatedFiles)}
3. Input:
{
name: "John",
<cursor>
}
Output: "age: 30,\n city: 'New York'" (note indentation)
Analyze all context carefully before generating completions. Ensure high relevance and accuracy.`;

const user = `${formatRelatedFiles(relatedFiles)}
Current code with cursor position:
2. Code State:
\`\`\`
${textBeforeCursor}<cursor>${textAfterCursor}
\`\`\``;
\`\`\`
Generate appropriate code completion at <cursor> position (Output only code without any comments or explanations):`;

return {system, user};
};

0 comments on commit 0e51878

Please sign in to comment.