Giter Club home page Giter Club logo

Comments (5)

typpo avatar typpo commented on July 26, 2024 1

#93 addresses some of this feedback, adding support for pure Javascript functions as Providers and Assertions.

from promptfoo.

typpo avatar typpo commented on July 26, 2024

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.

  1. 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.
  2. Also agreed
  3. 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).
  4. The NodeJS API is getting support for outputPath shortly - #91

from promptfoo.

NickHeiner avatar NickHeiner commented on July 26, 2024

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.

NickHeiner avatar NickHeiner commented on July 26, 2024

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.

typpo avatar typpo commented on July 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.