Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel
Guangshuo Zang b9357683eb
fix(go-provider): resolve CallApi redeclaration issue (#3414)
5 months ago
..
9e4e380d9a
fix(providers): support nested directory structures in Go provider (#3118)
6 months ago
b9357683eb
fix(go-provider): resolve CallApi redeclaration issue (#3414)
5 months ago
9e4e380d9a
fix(providers): support nested directory structures in Go provider (#3118)
6 months ago
981c58c234
feat: add golang provider (#1693)
11 months ago
9e4e380d9a
fix(providers): support nested directory structures in Go provider (#3118)
6 months ago
b69af66a3a
fix(go-mod): update go toolchain version to valid syntax (#3170)
6 months ago
9e4e380d9a
fix(providers): support nested directory structures in Go provider (#3118)
6 months ago
9e4e380d9a
fix(providers): support nested directory structures in Go provider (#3118)
6 months ago
9e4e380d9a
fix(providers): support nested directory structures in Go provider (#3118)
6 months ago

README.md

You have to be logged in to leave a comment. Sign In

Golang Provider Example

This example demonstrates how to structure a Go-based provider for promptfoo. For detailed documentation, see Go Provider documentation.

To get started with this example:

promptfoo init --example golang-provider

Directory Structure

This example shows two implementations of the same provider interface:

golang-provider/
├── go.mod            # Root module definition
├── main.go           # Root provider implementation
├── core/             # Supporting code
│   └── openai.go     # OpenAI client wrapper
├── pkg1/             # Shared utilities
│   └── utils.go      # Configuration
├── evaluation/       # Alternative implementation
│   └── main.go      # Provider with same interface
└── promptfooconfig.yml  # Config comparing both implementations

The structure demonstrates how to:

  1. Keep shared Go code in a single module
  2. Implement the same provider interface in different ways
  3. Compare multiple implementations in one config

Prerequisites

  1. Go installed (1.16 or later)

  2. OpenAI Go client library:

    go get github.com/sashabaranov/go-openai@v1.37.0
    
  3. Set your API key:

    export OPENAI_API_KEY=your_key_here
    

Usage

Run the comparison:

npx promptfoo eval

Then view the results with:

npx promptfoo view

Configuration

The config compares both implementations:

providers:
  - id: 'file://evaluation/main.go:CallApi'
    label: 'Provider in evaluation/'

  - id: 'file://main.go:CallApi'
    label: 'Provider in root'
    config:
      reasoning_effort: 'high'

Provider Implementations

Both main.go and evaluation/main.go implement the same interface:

func CallApi(prompt string, options map[string]interface{}) (string, error)

They share the same OpenAI client code but can be configured differently through the config file.

Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...