Comments (5)
#93 addresses some of this feedback, adding support for pure Javascript functions as Providers and Assertions.
from promptfoo.
Thanks for this feedback, Nick. In general, the node package needs some love - I've been pretty focused on the CLI, and right now the package is just a wrapper around the CLI. Running evals in a script definitely has different requirements/ergonomics.
- Agree it would be great to support
ApiProviders
that are functions, so you can hook into your full app logic. Can add this one soon. - Also agreed
- Makes sense, probably not too much of a lift to expose this separately. Worth mentioning if you are leaning hard into test running, it may be easier to use an established test framework like Jest and use a custom matcher for semantic similarity or LLM grading (example).
- The NodeJS API is getting support for
outputPath
shortly - #91
from promptfoo.
That all makes sense!
For (3) – I'm actually not in a Jest mindset at all. I'm very much exploring what different prompts do / just want an accuracy score; I don't have anything robust enough that I'd link Jest test pass/fails to it.
from promptfoo.
Also, in case it's helpful context, this is the framework that my AI-driven programs are built with: https://github.com/fixie-ai/ai-jsx.
from promptfoo.
Since this issue was opened, promptfoo has much improved support for use as a node library or with custom API providers or script providers.
Providers, prompts, and assertions can be passed as functions like in this example:
import promptfoo from 'promptfoo';
const prompts = [
// Prompts can be raw text...
'Write a haiku about: {{body}}',
// Or message arrays...
[{
role: 'system',
content: 'You are speaking to a time traveler. Begin your conversation.',
},
{
role: 'user',
content: '{{body}}',
},
],
// Or functions
(vars) => {
const genres = ['fantasy', 'sci-fi', 'mystery', 'horror'];
const characters = {
'fantasy': 'wizard',
'sci-fi': 'alien',
'mystery': 'detective',
'horror': 'ghost'
};
const genre = genres[Math.floor(Math.random() * genres.length)];
const character = characters[genre];
return [{
role: 'system',
content: `You have encountered a ${character} in a ${genre} setting. Engage with the character using the knowledge typical for that genre.`,
},
{
role: 'user',
content: '{{body}}',
},
];
},
];
const providers = [
// Call the OpenAI API GPT 3.5
'openai:gpt-3.5-turbo',
// Or use a custom function. Call an LLM API in this function, or any other logic.
(prompt, context) => {
console.log(`Prompt: ${prompt}, vars: ${JSON.stringify(context.vars)}`);
return {
output: '<LLM output>',
};
},
];
const tests = [{
vars: {
body: 'Hello world',
},
},
{
vars: {
body: "I'm hungry",
},
assert: [{
type: 'javascript',
value: (output) => {
// Logic for checking LLM output goes here...
const pass = output.includes("foo bar");
return {
pass,
score: pass ? 1.0 : 0.0,
reason: pass ? 'Output contained substring' : 'Output did not contain substring',
};
},
}, ],
},
];
(async () => {
const results = await promptfoo.evaluate({ prompts, providers, tests });
console.log(JSON.stringify(results, null, 2));
})();
Hope this is useful and address your asks. I assume promptfoo wasn't a great fit at the time, so I'm curious what you wound up using for evals.
from promptfoo.
Related Issues (20)
- Add ability to bust cache from the web UI
- When Python provider raises exception, details are no longer recorded HOT 3
- Ensure percent complete accurately reflects test suite
- Migrations path incorrect in self host docker build HOT 4
- [Web UI] Image previewer not working for variables or failed tests
- CI passes despite failing build HOT 1
- python external assertion not working HOT 2
- [Web UI] Increase robustness of markdown rendering
- Specify a label with a prompt function HOT 3
- --no confirmation for cli view HOT 1
- expression to select subset of output to display in view HOT 3
- SqliteError: no such table: evals HOT 1
- Error: Unknown Amazon Bedrock model: meta.llama3-70b-instruct-v1:0 HOT 4
- Compare providers based on latency HOT 3
- Failed to fetch when attempting to log in/sign up on the web-UI after promptfoo share
- Issue when using Vertex Gemini - "undefined" JSON Error HOT 2
- bedrock:meta.llama3-70b-instruct-v1:0 - No output HOT 3
- bedrock:mistral.mixtral-8x7b-instruct-v0:1 - Validation Error HOT 1
- bedrock:cohere.command-r-plus-v1:0 - ValidationException HOT 1
- default param values not getting added to bedrock requests on any provider HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from promptfoo.