examples/provider-ruby/README.md
This example demonstrates how to create a custom Ruby provider for promptfoo that integrates with the OpenAI API.
You can run this example with:
npx promptfoo@latest init --example provider-ruby
cd provider-ruby
The Ruby provider allows you to use Ruby code as a provider in promptfoo evaluations. This example also demonstrates Ruby assertions for custom validation logic.
Ruby Provider is useful when you need to:
Ruby Assertions allow you to:
This example requires the following environment variable:
OPENAI_API_KEY - Your OpenAI API keyYou can set this in a .env file or directly in your environment.
net/http and json from standard library)provider.rb - The Ruby provider implementation that calls OpenAI's APIassert.rb - Custom Ruby assertion functions for validationpromptfooconfig.yaml - Configuration for promptfoo evaluation with proper YAML schema referenceprovider.rb)The Ruby provider includes:
call_api function that makes API calls to OpenAIBy default, the example is configured to use gpt-4.1-mini model, but you can modify it to use other models as needed.
The example demonstrates three types of Ruby assertions:
output.length > 10)assert.rb) - Reusable assertion functionsRuby assertions can:
GradingResult hashes with pass/fail, score, reason, and component resultsWhen you run this example, you'll see:
Run the example with:
npx promptfoo@latest evaluate -c examples/provider-ruby/promptfooconfig.yaml
For more information, see the promptfoo documentation: