Prompt Chain

Build custom TypeScript providers for prompt evaluation

Create custom TypeScript API providers for prompt testing with CSV test cases and structured output validation.

Works with openai

72
Spark score
out of 100
Updated 19 days ago
Version 0.121.18

Add to Favorites

Why it matters

Enable developers to create and test custom API providers in TypeScript for prompt evaluation workflows, allowing integration of proprietary or specialized language models into the promptfoo testing framework.

Outcomes

What it gets done

01

Implement custom provider logic in TypeScript with type safety

02

Load and process CSV test cases for prompt evaluation

03

Execute prompt evaluations against custom API endpoints

04

Output structured JSON results from evaluation runs

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-typescript | bash

Overview

Typescript

A TypeScript example showing how to implement a custom provider for promptfoo with CSV test cases When you need to create a custom provider in TypeScript for promptfoo evaluation workflows

What it does

This example demonstrates how to implement a custom API provider in TypeScript for promptfoo. It includes a custom provider implementation in customProvider.ts and uses CSV-based test cases for prompt evaluation.

When to use - and when NOT to

Use this example when you want to create a custom provider in TypeScript for promptfoo. It provides a starting point for implementing your own provider logic.

Do NOT use this if standard promptfoo providers already support your target API - the built-in providers offer better maintenance and feature support. Avoid this approach if you're just starting with promptfoo and haven't yet mastered the standard evaluation workflow.

Inputs and outputs

You provide a custom TypeScript provider implementation in customProvider.ts, a prompts file (prompts.txt), and test cases in CSV format (vars.csv). The example accepts standard promptfoo configuration including prompt templates and variable substitutions from the CSV.

You receive evaluation results with output saved to output.json.

Getting started

Initialize the example with:

npx promptfoo@latest init --example provider-custom/typescript
cd provider-custom/typescript

Run the evaluation:

promptfoo eval

For the full command-line equivalent with explicit parameters:

promptfoo eval --prompts prompts.txt --tests vars.csv --providers openai:chat --output output.json --providers customProvider.js

Integrations

The example uses promptfoo's evaluation framework for test execution and result collection.

Who it's for

This example serves TypeScript developers who want to build custom providers for promptfoo. It's designed for developers who need to implement their own provider logic beyond what standard providers offer.

Source README

provider-custom/typescript (Custom Provider Typescript)

You can run this example with:

npx promptfoo@latest init --example provider-custom/typescript
cd provider-custom/typescript

Usage

This example uses a custom API provider in customProvider.ts. It also uses CSV test cases.

Run:

promptfoo eval

Full command-line equivalent:

promptfoo eval --prompts prompts.txt --tests vars.csv --providers openai:chat --output output.json --providers customProvider.js

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.