安装和使用promptfoo的具体步骤如下:
- Installing command line tools: Install globally via npm
npm install -g promptfoo
- Initialization Project:创建基础配置文件和目录结构
npx promptfoo@latest init
- Configuring Test Cases:编辑生成的promptfooconfig.yaml文件,添加要测试的提示和变量,示例配置:
targets: - id: 'example' config: method: 'POST' headers: 'Content-Type: application/json' body: userInput: '{{prompt}}'
- Operational assessment:执行基础评估
promptfoo evaluate
或运行红队测试npx promptfoo@latest redteam init
- analysis:在命令行输出或网页界面查看评估报告
项目初始化后会创建完整的目录结构,包含:
- prompts/ – 存放提示模板
- providers/ – API提供商配置
- testcases/ – 测试用例文件
- promptfooconfig.yaml – 主配置文件
开发者可以根据需要调整这些配置,逐步建立全面的测试套件。
This answer comes from the articlePromptfoo: Providing a Safe and Reliable LLM Application Testing ToolThe