add XML formatting instructions file and update prompt generator to include instructions
This commit is contained in:
@@ -73,16 +73,19 @@ export class PromptGenerator {
|
||||
private static generateXMLPrompt(files: Map<string, { content: string; tokens: number }>, settings: PrompterSettings): string {
|
||||
const xmlParts: string[] = [];
|
||||
|
||||
// Include XML formatting instructions if enabled
|
||||
// Store formatting instructions to add at the end if enabled
|
||||
let formattingInstructions = '';
|
||||
if (settings.includeFormattingInstructions) {
|
||||
try {
|
||||
// Get the workspace root path
|
||||
const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath || '';
|
||||
const formattingInstructionsPath = path.join(workspaceRoot, '..', 'project_management', 'xml_formatting_instructions.xml');
|
||||
// Get the extension path
|
||||
const extensionPath = vscode.extensions.getExtension('prompter')?.extensionPath ||
|
||||
path.join(__dirname, '..', '..');
|
||||
const formattingInstructionsPath = path.join(extensionPath, 'resources', 'xml_formatting_instructions.xml');
|
||||
|
||||
if (fs.existsSync(formattingInstructionsPath)) {
|
||||
const instructions = fs.readFileSync(formattingInstructionsPath, 'utf8');
|
||||
xmlParts.push(instructions);
|
||||
formattingInstructions = fs.readFileSync(formattingInstructionsPath, 'utf8');
|
||||
} else {
|
||||
console.warn('XML formatting instructions file not found at:', formattingInstructionsPath);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error reading XML formatting instructions:', error);
|
||||
@@ -150,6 +153,11 @@ export class PromptGenerator {
|
||||
vscode.window.showInformationMessage(`Total tokens: ${totalTokens}`);
|
||||
}
|
||||
|
||||
// Add formatting instructions at the end if enabled
|
||||
if (settings.includeFormattingInstructions && formattingInstructions) {
|
||||
xmlParts.push(formattingInstructions);
|
||||
}
|
||||
|
||||
return xmlParts.join('\n');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user