Chuyển đến nội dung chính

Documentation Index

Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt

Use this file to discover all available pages before exploring further.

Promptfoo là một framework để đánh giá prompt, kiểm thử hồi quy và red teaming cho AI. Promptfoo bao gồm provider cometapi gọi CometAPI thông qua các endpoint tương thích OpenAI.

Điều kiện tiên quyết

  • Node.js 18+
  • Promptfoo được cài đặt cục bộ hoặc chạy thông qua npx
  • Một tài khoản CometAPI với API key đang hoạt động — lấy tại dashboard
  • Một model ID từ trang CometAPI Models

Cấu hình tích hợp

1

Đặt CometAPI API key của bạn

Đặt COMETAPI_KEY trước khi bạn chạy đánh giá:
read -rsp "CometAPI API key: " COMETAPI_KEY
printf '\n'
export COMETAPI_KEY
2

Chọn định dạng provider

Promptfoo sử dụng định dạng provider ID sau cho CometAPI:
providers:
  - cometapi:<type>:<model>
Sử dụng các loại provider sau:
TypeTrường hợp sử dụng
chatChat completions, vision và prompt multimodal
completionCác model hoàn thành văn bản
embeddingĐánh giá text embedding
imageĐánh giá tạo ảnh
Bạn cũng có thể sử dụng cometapi:your-model-id cho chế độ chat mặc định.
3

Chạy đánh giá bằng CLI

Lệnh sau chạy một đánh giá chat với một prompt:
npx promptfoo@latest eval \
  --prompts "Write a concise release note for {{feature}}" \
  --vars feature="a unified API dashboard" \
  -r cometapi:chat:your-model-id
4

Tạo file cấu hình Promptfoo

promptfooconfig.yaml sau đánh giá cùng một prompt trên một model CometAPI:
prompts:
  - "Classify this support request: {{message}}"

providers:
  - id: cometapi:chat:your-model-id
    config:
      temperature: 0.2
      max_tokens: 256

tests:
  - vars:
      message: "The API key works locally but fails in production."
    assert:
      - type: contains-any
        value:
          - authentication
          - configuration
Chạy file cấu hình bằng Promptfoo:
npx promptfoo@latest eval -c promptfooconfig.yaml

Ví dụ về provider

Sử dụng loại provider khớp với hành vi model mà bạn muốn đánh giá:
providers:
  - cometapi:chat:your-model-id
  - cometapi:completion:your-model-id
  - cometapi:embedding:your-model-id
  - cometapi:image:your-model-id
Đối với kiểm thử multimodal, hãy giữ loại provider chat và truyền các biến hình ảnh thông qua biến kiểm thử của Promptfoo.

Khắc phục sự cố

Xác nhận rằng COMETAPI_KEY được export trong cùng phiên shell đang chạy promptfoo eval.
Sử dụng chat cho các model hội thoại và multimodal, embedding cho các model embedding, và image cho các model tạo ảnh.
Thay your-model-id bằng một model ID chính xác từ trang CometAPI Models.

Tài nguyên liên quan