promptfoo / promptfoo

Test your prompts, agents, and RAGs. Redteaming, pentesting, vulnerability scanning for LLMs. Improve your app's quality and catch problems. Compare performance of GPT, Claude, Gemini, Llama, and more. Simple declarative configs with command line and CI/CD integration.

Home Page:https://www.promptfoo.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Using a python or javascript prompt function when using promptfoo.evaluate()

anthonyivn2 opened this issue · comments

Hi, I am trying to understand on whether it is possible to use a prompt function defined within a separate python/javascript file as the prompts value that is passed to promptfoo.evaluate(). I am not seeing that functionality in the documentations, and I would like to use promptfoo.evaluate() directly instead as my test data will only be available in memory (not as local files).

You can specify a separate python/js file using a path (e.g. file://path/to/file.py), which should follow the prompt functions documentation.

Or, when calling evaluate directly with node, you can supply a function directly in the prompts array that you pass to evaluate:

prompts: [
      ({ vars }) => {
        // Call your own code here
        const foo = require('foo');
        finalResult = await foo(vars);
        return finalResult;
      },
    ],

Right now what I am seeing is that when I tried adding file://path/to/file.js to the prompts argument in evaluate(), the prompt used would just be the path instead of the content from the prompt function js file

ok seems like I can proceed with the second method by importing the prompt function content and then adding it to prompts.

👍

Looks like I misremembered the prompt function/file support for the node package, it was never actually added. I've PRed that here: #668