> ## 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.

# Sử dụng Promptfoo với CometAPI

> Sử dụng hướng dẫn này để cấu hình Promptfoo với CometAPI bằng cách thiết lập base URL, API key và các tùy chọn model hoặc provider.

[Promptfoo](https://www.promptfoo.dev/) là một framework dành cho việc đánh giá prompt, kiểm thử hồi quy và red teaming cho AI. Promptfoo bao gồm một 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 qua `npx`
* Tài khoản CometAPI có API key đang hoạt động — [lấy tại dashboard](https://www.cometapi.com/console/token)
* Một model ID từ [trang Models của CometAPI](/vi/overview/models)

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

<Steps>
  <Step title="Thiết lập API key CometAPI của bạn">
    Thiết lập `COMETAPI_KEY` trước khi bạn chạy các lượt đánh giá:

    ```bash theme={null}
    read -rsp "CometAPI API key: " COMETAPI_KEY
    printf '\n'
    export COMETAPI_KEY
    ```
  </Step>

  <Step title="Chọn định dạng provider">
    Promptfoo sử dụng định dạng provider ID sau cho CometAPI:

    ```yaml theme={null}
    providers:
      - cometapi:<type>:<model>
    ```

    Sử dụng các loại provider sau:

    | Type         | Trường hợp sử dụng                              |
    | ------------ | ----------------------------------------------- |
    | `chat`       | Chat completions, thị giác và prompt multimodal |
    | `completion` | Các model hoàn tất 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.
  </Step>

  <Step title="Chạy đánh giá bằng CLI">
    Lệnh sau chạy một lượt đánh giá chat với một prompt:

    ```bash theme={null}
    npx promptfoo@latest eval \
      --prompts "Write a concise release note for {{feature}}" \
      --vars feature="a unified API dashboard" \
      -r cometapi:chat:your-model-id
    ```
  </Step>

  <Step title="Tạo tệp cấu hình Promptfoo">
    `promptfooconfig.yaml` sau đánh giá cùng một prompt với một model CometAPI:

    ```yaml theme={null}
    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 tệp cấu hình bằng Promptfoo:

    ```bash theme={null}
    npx promptfoo@latest eval -c promptfooconfig.yaml
    ```
  </Step>
</Steps>

## Ví dụ về provider

Sử dụng loại provider phù hợp với hành vi model mà bạn muốn đánh giá:

```yaml theme={null}
providers:
  - cometapi:chat:your-model-id
  - cometapi:completion:your-model-id
  - cometapi:embedding:your-model-id
  - cometapi:image:your-model-id
```

Đối với các bài kiểm thử multimodal, hãy giữ loại provider là `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ố

<AccordionGroup>
  <Accordion title="Promptfoo không thể tìm thấy API key">
    Xác nhận rằng `COMETAPI_KEY` được export trong cùng phiên shell chạy `promptfoo eval`.
  </Accordion>

  <Accordion title="Loại provider không khớp với model">
    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.
  </Accordion>

  <Accordion title="Model ID không hoạt động">
    Thay `your-model-id` bằng model ID chính xác từ [trang Models của CometAPI](/vi/overview/models).
  </Accordion>
</AccordionGroup>

## Tài nguyên liên quan

* [Nhà cung cấp Promptfoo CometAPI](https://www.promptfoo.dev/docs/providers/cometapi/)
* [Bắt đầu nhanh với CometAPI](/vi/overview/quick-start)
* [Trang Models của CometAPI](/vi/overview/models)

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "HowTo",
        "@id": "https://apidoc.cometapi.com/integrations/promptfoo#howto",
        "name": "Sử dụng Promptfoo với CometAPI",
        "description": "Sử dụng hướng dẫn này để cấu hình Promptfoo với CometAPI bằng cách thiết lập base URL, API key và các tùy chọn model hoặc provider.",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/promptfoo#step-1",
            "position": 1,
            "name": "Thiết lập CometAPI API key của bạn",
            "text": "Lưu CometAPI API key của bạn trong biến môi trường hoặc trường cài đặt mà tích hợp sử dụng."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/promptfoo#step-2",
            "position": 2,
            "name": "Chọn định dạng provider",
            "text": "Hoàn thành bước Chọn định dạng provider trong hướng dẫn Sử dụng Promptfoo với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/promptfoo#step-3",
            "position": 3,
            "name": "Chạy đánh giá CLI",
            "text": "Hoàn thành bước Chạy đánh giá CLI trong hướng dẫn Sử dụng Promptfoo với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/promptfoo#step-4",
            "position": 4,
            "name": "Tạo tệp cấu hình Promptfoo",
            "text": "Hoàn thành bước Tạo tệp cấu hình Promptfoo trong hướng dẫn Sử dụng Promptfoo với CometAPI."
          }
        ]
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "Tài liệu CometAPI",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Tích hợp",
            "item": "https://apidoc.cometapi.com/integrations"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "Sử dụng Promptfoo với CometAPI",
            "item": "https://apidoc.cometapi.com/integrations/promptfoo"
          }
        ]
      }
    ]
    }
    `}
</script>
