fix: do template substition after parsing prompt YAML
This commit is contained in:
+8
-3
@@ -52572,10 +52572,8 @@ function loadPromptFile(filePath, templateVariables = {}) {
|
||||
throw new Error(`Prompt file not found: ${filePath}`);
|
||||
}
|
||||
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
||||
// Apply template variable substitution
|
||||
const processedContent = replaceTemplateVariables(fileContent, templateVariables);
|
||||
try {
|
||||
const config = load(processedContent);
|
||||
const config = load(fileContent);
|
||||
if (!config.messages || !Array.isArray(config.messages)) {
|
||||
throw new Error('Prompt file must contain a "messages" array');
|
||||
}
|
||||
@@ -52588,6 +52586,13 @@ function loadPromptFile(filePath, templateVariables = {}) {
|
||||
throw new Error(`Invalid message role: ${message.role}`);
|
||||
}
|
||||
}
|
||||
// Prepare messages by replacing template variables with actual content
|
||||
config.messages = config.messages.map(msg => {
|
||||
return {
|
||||
...msg,
|
||||
content: replaceTemplateVariables(msg.content, templateVariables),
|
||||
};
|
||||
});
|
||||
return config;
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+9
-4
@@ -101,11 +101,8 @@ export function loadPromptFile(filePath: string, templateVariables: TemplateVari
|
||||
|
||||
const fileContent = fs.readFileSync(filePath, 'utf-8')
|
||||
|
||||
// Apply template variable substitution
|
||||
const processedContent = replaceTemplateVariables(fileContent, templateVariables)
|
||||
|
||||
try {
|
||||
const config = yaml.load(processedContent) as PromptConfig
|
||||
const config = yaml.load(fileContent) as PromptConfig
|
||||
|
||||
if (!config.messages || !Array.isArray(config.messages)) {
|
||||
throw new Error('Prompt file must contain a "messages" array')
|
||||
@@ -121,6 +118,14 @@ export function loadPromptFile(filePath: string, templateVariables: TemplateVari
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare messages by replacing template variables with actual content
|
||||
config.messages = config.messages.map(msg => {
|
||||
return {
|
||||
...msg,
|
||||
content: replaceTemplateVariables(msg.content, templateVariables),
|
||||
}
|
||||
})
|
||||
|
||||
return config
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to parse prompt file: ${error instanceof Error ? error.message : 'Unknown error'}`)
|
||||
|
||||
Reference in New Issue
Block a user