Bài thực hành Promptfoo cơ bản

Dưới đây là bài thực hành Promptfoo cơ bản để giúp bạn bắt đầu đánh giá và so sánh các prompt sử dụng mô hình ngôn ngữ (LLM). promptfoo rất hữu ích trong việc tối ưu prompt, benchmark nhiều model khác nhau, và kiểm thử các thay đổi trong ứng dụng sử dụng LLM.

MỤC TIÊU

 BƯỚC 1: CÀI ĐẶT PROMPTFOO

npm install -g promptfoo

BƯỚC 2: TẠO CẤU TRÚC THƯ MỤC DỰ ÁN

mkdir promptfoo-demo && cd promptfoo-demo
touch config.yaml
mkdir evals

BƯỚC 3: TẠO TẬP TIN CẤU HÌNH config.yaml

 

prompts:
  - "Translate to French: {{input}}"
  - "Please provide the French translation for: {{input}}"

providers:
  - id: openai:gpt-3.5-turbo
    config:
      apiKey: $OPENAI_API_KEY
  - id: openrouter:mistralai/mistral-7b-instruct
    config:
      apiKey: $OPENROUTER_API_KEY

tests:
  - vars:
      input: "Hello, how are you?"
    assert:
      includes:
        - "Bonjour"

  - vars:
      input: "I am going to the market."
    assert:
      includes:
        - "marché"

Bạn cần lấy API Key từ OpenAIOpenRouter.

BƯỚC 4: CHẠY ĐÁNH GIÁ

Chạy benchmark từ CLI:

promptfoo eval config.yaml

Sau đó, hiển thị dashboard kết quả:

promptfoo web

Mở trình duyệt tại địa chỉ: http://localhost:3000 để xem kết quả trực quan.



Phiên bản #1
Được tạo 7 tháng 5 2025 10:25:14 bởi Đỗ Ngọc Tú
Được cập nhật 7 tháng 5 2025 10:28:04 bởi Đỗ Ngọc Tú