Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel
Michael 3e3b7539b6
chore: update dependencies to latest minor and patch versions (#5109)
3 weeks ago
..
6d13ffa10a
chore(redteam): regenerate sessionId for each iteration in single-turn strategies (#4835)
1 month ago
7724d2cf57
chore: upgrade Express to v5.1.0 (#4378)
2 months ago
3e3b7539b6
chore: update dependencies to latest minor and patch versions (#5109)
3 weeks ago
6d13ffa10a
chore(redteam): regenerate sessionId for each iteration in single-turn strategies (#4835)
1 month ago
be46a6d2fd
chore(examples): Add mischievous-user strategy to redteam multi-turn examples (#4837)
1 month ago
cb02b7dd54
chore(examples): add redteam multi-turn chatbot example (#2306)
8 months ago

README.md

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

redteam-chatbot (Red teaming a Multi-turn Chatbot)

You can run this example with:

npx promptfoo@latest init --example redteam-chatbot

Introduction

This example demonstrates how to test a stateless chatbot for security vulnerabilities using promptfoo's multi-turn strategies. It includes a Node.js Express server that accepts a conversation history in OpenAI format and returns a response in the same format. It leverages promptfoo's goat, crescendo, and mischievous-user strategies for multi-turn red teaming. You can learn more about configuring these strategies here.

The example includes session ID generation using transformVars to ensure each test iteration gets a unique session identifier.

Setup

Installation

  1. Install dependencies:
npm install
  1. Set your OpenAI API key:
export OPENAI_API_KEY=your-api-key-here
  1. Start the server:
npm start

Running Tests

# Generate test cases
promptfoo redteam generate

# Execute evaluation
promptfoo redteam eval

# View results
promptfoo view

Node.js Webserver Example Usage

Single Message Request

curl -X POST http://localhost:2345/chat \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer your-token-here" \
    -d '{
        "api_provider": "openai",
        "chat_history": [
            {"role": "user", "content": "Tell me about your turboencabulator models"}
        ]
    }'

Multi-turn Conversation

curl -X POST http://localhost:2345/chat \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer your-token-here" \
    -d '{
        "api_provider": "openai",
        "chat_history": [
            {"role": "user", "content": "Tell me about your turboencabulator models"},
            {"role": "assistant", "content": "TurboTech offers several turboencabulator models..."},
            {"role": "user", "content": "What maintenance does it require?"}
        ]
    }'
Tip!

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

Comments

Loading...