Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Load a prompt from an external file and use inputs #418

Open
1 task done
selimrbd opened this issue Jun 12, 2024 · 2 comments
Open
1 task done

[Feature]: Load a prompt from an external file and use inputs #418

selimrbd opened this issue Jun 12, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@selimrbd
Copy link

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:

Screenshot 2024-06-12 at 21 17 24 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

  • I agree to follow this project's Code of Conduct
@selimrbd selimrbd added the enhancement New feature or request label Jun 12, 2024
@selimrbd
Copy link
Author

This is my current solution, using a Code Node to replace the inputs in the prompt.

Screenshot 2024-06-12 at 22 06 18

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 ?

@abrenneke
Copy link
Collaborator

I think this is a great opportunity for a rivet plugin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants