Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Promptfoo Promptfoo providerMap

From Leeroopedia
Knowledge Sources
Domains Provider_Management, Plugin_Architecture
Last Updated 2026-02-14 08:00 GMT

Overview

Concrete factory registry mapping provider path patterns to provider class constructors, provided by the Promptfoo framework.

Description

The providerMap is an array of ProviderFactory objects defined in the registry module. Each factory has a `test()` predicate that matches provider path strings and a `create()` async function that instantiates the appropriate provider class. The array contains 70+ entries covering all built-in providers.

Usage

Reference this registry when understanding provider resolution or when adding new built-in providers. Custom providers use the `file://`, `python:`, or `https://` protocols which are handled before the registry is consulted.

Code Reference

Source Location

  • Repository: promptfoo
  • File: src/providers/registry.ts
  • Lines: L136-1400

Signature

export const providerMap: ProviderFactory[] = [
  // Each entry:
  {
    test: (providerPath: string) => boolean,  // Prefix matcher
    create: (
      providerPath: string,
      providerOptions: ProviderOptions,
      context: LoadApiProviderContext,
    ) => Promise<ApiProvider>,
  },
  // 70+ entries...
];

Import

import { providerMap } from './providers/registry';

I/O Contract

Inputs

Name Type Required Description
providerPath string Yes Provider identifier to match against (e.g., 'openai:gpt-4')
providerOptions ProviderOptions Yes Config, env overrides, transforms
context LoadApiProviderContext Yes Base path and loading context

Outputs

Name Type Description
(return from create) ApiProvider Instantiated provider ready for callApi() invocations

Usage Examples

Registry Lookup

import { providerMap } from './providers/registry';

// Find the factory for an OpenAI provider
const factory = providerMap.find(f => f.test('openai:gpt-4o'));
if (factory) {
  const provider = await factory.create('openai:gpt-4o', options, context);
  console.log(provider.id()); // 'openai:gpt-4o'
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment