Open selimrbd opened 2 weeks ago
This is my current solution, using a Code Node
to replace the inputs in the prompt.
My prompt text file (prompt.txt):
This is the beginning of my prompt
{{userInstructions}}
{{userContext}}
Here are additional instructions.
And the parsing code :
const prompt = inputs.prompt.value
const variables = Object.fromEntries(
Object.entries(inputs).filter(([key, _]) => key !== "prompt")
);
function replacePlaceholders(prompt, variables) {
var result = prompt
for(let placeholder in variables) {
let regex = new RegExp(`{{${placeholder}}}`, 'g')
result = result.replace(regex, variables[placeholder].value);
}
return result;
}
const outputString = replacePlaceholders(prompt, variables);
return {
output: {
type: 'string',
value: outputString
}
};
Does anybody have a more elegant / less complicated solution ?
Feature Request
I'd like to load my prompts from external text files, so they are versioned cleanly.
The
Read File
doesn't solve my problem: The variables can't be linked to inputs in the resulting text node.Example:
I would like
{{userInstructions}}
and{{context}}
to be available as variables / inputs.Is it possible to do this currently in Rivet ?
If not, what workaround do you use to properly version your prompts ?
Code of Conduct