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

# Kết nối Flowise với CometAPI

> Sử dụng hướng dẫn này để kết nối Flowise 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.

FlowiseAI là một nền tảng low-code để xây dựng các ứng dụng LLM theo cách trực quan. Sử dụng node **ChatCometAPI** gốc để kết nối CometAPI với chatflow, hệ thống hỏi đáp và quy trình RAG gọi các text chat model.

<Note>
  Hướng dẫn này bao gồm quy trình text chat và RAG. Không bao gồm quy trình tạo ảnh.
</Note>

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

* Một tài khoản CometAPI với API key đang hoạt động - [lấy tại đây](https://www.cometapi.com/console/token)
* Một tài khoản FlowiseAI hoặc một phiên bản Flowise tự lưu trữ - [đăng nhập vào Flowise Cloud](https://cloud.flowiseai.com/chatflows)
* Một model ID text hiện tại từ [trang Models của CometAPI](/vi/overview/models)
* Với RAG, cần có một nguồn tài liệu cùng với một embeddings provider và vector store được Flowise hỗ trợ

## Cấu hình ChatCometAPI

<Steps>
  <Step title="Lấy CometAPI API key của bạn">
    Đăng nhập vào [CometAPI console](https://www.cometapi.com/console/token). Nhấp **Add API Key** và sao chép CometAPI API key của bạn.

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/overview/810968_364191.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=aef81a83f29f8eb16655ed4060425f50" alt="Bảng điều khiển CometAPI hiển thị nút Add API Key" width="3824" height="1892" data-path="images/overview/810968_364191.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/cometapi/HhtmQffktazbxUvS/images/overview/810968_364193.png?fit=max&auto=format&n=HhtmQffktazbxUvS&q=85&s=d893f659267150d0faf45f99eb5dffc1" alt="Chi tiết CometAPI API key cùng base URL" width="2434" height="1232" data-path="images/overview/810968_364193.png" />
    </Frame>
  </Step>

  <Step title="Thêm node ChatCometAPI">
    1. Trong canvas chatflow của FlowiseAI, nhấp **Add New**.

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_361945.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=f36fc7cc6d541af1acd95f6b8aea9b04" alt="Canvas FlowiseAI với nút Add New" width="1874" height="960" data-path="images/integrations/810968_361945.png" />
    </Frame>

    2. Tìm kiếm **cometapi** và chọn node **ChatCometAPI**.

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_361946.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=0da9222351e5378eeeb928b1acf1e959" alt="Tìm kiếm node hiển thị kết quả ChatCometAPI" width="1880" height="910" data-path="images/integrations/810968_361946.png" />
    </Frame>

    3. Kéo node này vào canvas.

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_361947.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=c727ab9ff734355a0f2d5de4ff479c97" alt="Node ChatCometAPI được đặt trên canvas" width="1810" height="950" data-path="images/integrations/810968_361947.png" />
    </Frame>
  </Step>

  <Step title="Tạo credential CometAPI">
    Trong node ChatCometAPI, mở **Connect Credential**, chọn **Create New**, dán CometAPI API key của bạn, rồi lưu credential.

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_361948.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=b64309fa10d20704751e433c3316cf82" alt="Hộp thoại credential với API key đã được nhập" width="1820" height="900" data-path="images/integrations/810968_361948.png" />
    </Frame>
  </Step>

  <Step title="Thiết lập base path của CometAPI">
    Mở rộng **Additional Parameters** trên node ChatCometAPI.

    Nếu bản dựng Flowise của bạn hiển thị trường **Base Path**, hãy đặt thành:

    ```text theme={null}
    https://api.cometapi.com/v1/
    ```

    Nếu thay vào đó nó hiển thị **Base Options**, hãy thêm một mục `basePath`:

    ```json theme={null}
    {
      "basePath": "https://api.cometapi.com/v1/"
    }
    ```

    Đặt **Model Name** thành đúng text model ID mà bạn muốn gọi, ví dụ `your-model-id`, và chỉ điều chỉnh **Temperature** nếu quy trình của bạn cần mức độ biến thiên nhiều hơn hoặc ít hơn.
  </Step>
</Steps>

## Tạo một chatflow cơ bản

<Steps>
  <Step title="Thêm một Prompt Template">
    Thêm một node **Prompt Template** và xác định prompt mà chatflow của bạn sẽ gửi đến model.

    ```text theme={null}
    Question: {question}
    Answer clearly and concisely.
    ```

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_361949.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=201c0e040b56a7a5338ba34b5761cac1" alt="Node Prompt Template với mẫu ví dụ" width="1238" height="850" data-path="images/integrations/810968_361949.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_361950.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=9a872c659549ba024457a015a5c75064" alt="Node Prompt Template được đặt trên canvas" width="511" height="805" data-path="images/integrations/810968_361950.png" />
    </Frame>
  </Step>

  <Step title="Thêm một LLM Chain">
    Thêm một node **LLM Chain**. Kết nối node **ChatCometAPI** với đầu vào **Language Model** của chain, sau đó kết nối node **Prompt Template** với đầu vào **Prompt** của chain.

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_361951.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=a44d838bb2fc70911e0407b1ea2ed7f2" alt="Node LLM Chain với Language Model và Prompt đã được kết nối" width="514" height="724" data-path="images/integrations/810968_361951.png" />
    </Frame>
  </Step>

  <Step title="Lưu và kiểm tra flow">
    Lưu chatflow, mở phần xem trước chat và gửi một câu hỏi kiểm tra ngắn. Một cấu hình hoạt động bình thường sẽ trả về câu trả lời văn bản thông thường từ model CometAPI đã chọn.

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_361954.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=73647ee6f0995ed8c36a9fd1a2e6fd97" alt="Chatflow hoàn chỉnh với cả ba node đã được kết nối" width="1466" height="789" data-path="images/integrations/810968_361954.png" />
    </Frame>
  </Step>
</Steps>

## Chuyển model ID

Để chuyển model, giữ nguyên credential và base path của CometAPI, sau đó chỉ thay đổi trường model ID của ChatCometAPI.

Sử dụng model ID chính xác từ [trang CometAPI Models](/vi/overview/models). Tránh sao chép tên hiển thị, tên nhà cung cấp hoặc khoảng trắng thừa.

| Trường hợp sử dụng      | Giá trị model ID          |
| ----------------------- | ------------------------- |
| Họ model chat tổng quát | `your-chat-model-id`      |
| Họ model suy luận       | `your-reasoning-model-id` |
| Họ model lập trình      | `your-coding-model-id`    |

Sau khi thay đổi model ID, hãy lưu chatflow và chạy một prompt kiểm tra ngắn. Nếu bạn duy trì nhiều flow production, trước tiên hãy nhân bản chatflow và đặt cho mỗi bản sao một tên phản ánh họ model.

## Cấu hình retrieval-augmented generation

Flowise RAG có hai phần: trước tiên chuẩn bị và upsert tài liệu trong **Document Stores**, sau đó kết nối retriever đã được chuẩn bị với một chatflow. ChatCometAPI là chat model viết ra câu trả lời cuối cùng; Document Store vẫn cần một embeddings provider được Flowise hỗ trợ và vector store.

<Steps>
  <Step title="Tạo và xử lý một Document Store">
    Trong Flowise, mở **Document Stores** và tạo một store mới. Thêm một document loader, chẳng hạn như **File Loader**, **PDF Loader**, **Web Scraper** hoặc loader khác phù hợp với nguồn của bạn. Thêm một text splitter khi tài liệu đủ dài để cần chia chunk, sau đó nhấp **Process** để xem trước các chunk được tạo.
  </Step>

  <Step title="Cấu hình embeddings và lưu trữ vector">
    Nhấp **Upsert** hoặc **Upsert All Chunks**. Chọn:

    * **Embeddings**: một node embeddings của Flowise tương thích với dữ liệu và vector store của bạn.
    * **Vector Store**: cơ sở dữ liệu vector nơi Flowise sẽ lưu trữ document embeddings.
    * **Record Manager**: tùy chọn. Dùng khi bạn muốn các lần upsert lặp lại tránh tạo bản ghi trùng lặp.

    Giữ cho dimension của embedding model khớp với dimension của index trong vector store. Sau khi upsert hoàn tất, dùng bài kiểm tra retrieval query của Document Store để xác nhận rằng các chunk liên quan được trả về trước khi xây dựng chatflow.
  </Step>

  <Step title="Tạo chatflow retrieval">
    Trong một chatflow, thêm node **Document Store (Vector)** hoặc **Document Store Retriever** và chọn Document Store đã được xử lý. Đặt **Top K** thành số lượng chunk mà bạn muốn Flowise truy xuất cho mỗi câu hỏi.
  </Step>

  <Step title="Kết nối Conversational Retrieval QA Chain">
    Thêm **Conversational Retrieval QA Chain** và kết nối:

    * Đầu vào **Language Model** từ **ChatCometAPI**.
    * Đầu vào **Vector Store Retriever** từ retriever của Document Store.
    * **Memory** chỉ khi chatflow của bạn cần lịch sử hội thoại.

    Bật **Return Source Documents** khi bạn muốn câu trả lời bao gồm trích dẫn hoặc các chunk nguồn đã được truy xuất. Lưu flow và đặt một câu hỏi mà câu trả lời chỉ tồn tại trong tài liệu đã tải lên.
  </Step>
</Steps>

## Khắc phục sự cố

<AccordionGroup>
  <Accordion title="Thiếu node ChatCometAPI">
    Hãy xác nhận rằng phiên bản Flowise của bạn có tích hợp chat model **ChatCometAPI**. Trong các bản triển khai Flowise cũ hơn hoặc đã được tùy chỉnh, hãy cập nhật Flowise hoặc kiểm tra xem quản trị viên có vô hiệu hóa tích hợp này hay không.
  </Accordion>

  <Accordion title="Yêu cầu thất bại vì base path không đúng">
    Đặt CometAPI base path thành `https://api.cometapi.com/v1/`. Trong một số bản dựng Flowise, đây là trường **Base Path**. Trong các bản khác, hãy thêm `basePath` bên trong **Base Options**.

    Không dùng `https://api.cometapi.com` cho chatflow ChatCometAPI, vì chat node gọi các route OpenAI-compatible `/chat/completions` dưới `/v1`.
  </Accordion>

  <Accordion title="API key hoặc credential bị lỗi">
    Sao chép lại key từ [CometAPI console](https://www.cometapi.com/console/token), tạo một credential Flowise mới, và đảm bảo chatflow sử dụng credential đó. Nếu cùng key đó hoạt động trong các lệnh gọi API trực tiếp nhưng thất bại trong Flowise, hãy kiểm tra xem có phải Flowise vẫn đang dùng một credential cũ hơn được gắn với node hay không.
  </Accordion>

  <Accordion title="model ID bị lỗi">
    Thay giá trị model ID trong node ChatCometAPI bằng một model ID văn bản hiện tại chính xác từ [trang Models của CometAPI](/vi/overview/models). Giá trị này không được bao gồm dấu ngoặc kép, tiền tố provider, nhãn hiển thị, hoặc khoảng trắng ở cuối.
  </Accordion>

  <Accordion title="Workflow cố gắng tạo ảnh">
    ChatCometAPI là một chat model node cho các workflow văn bản. Hãy dùng nó cho chat, chain, agent và tạo câu trả lời RAG. Không sử dụng thiết lập Flowise này cho các node tạo ảnh hoặc các workflow chỉ dành cho ảnh.
  </Accordion>

  <Accordion title="RAG không trả về nguồn hoặc câu trả lời yếu">
    Trước tiên, hãy kiểm thử truy vấn truy xuất của Document Store trước khi kiểm thử toàn bộ chatflow. Nếu khả năng truy xuất yếu, hãy tinh chỉnh text splitter, chunk size, chunk overlap, metadata filter và **Top K**. Nếu thiếu trích dẫn, hãy bật **Return Source Documents** trên **Conversational Retrieval QA Chain**.
  </Accordion>

  <Accordion title="Cấu hình upsert hoặc vector store bị lỗi">
    Hãy kiểm tra rằng embedding provider, vector store và kích thước vector khớp nhau. Các vector store của Flowise Cloud thường yêu cầu URL dịch vụ và credential riêng có thể truy cập được; URL vector store chỉ chạy cục bộ như `localhost` sẽ không thể truy cập từ Flowise Cloud. Record Manager là tùy chọn, nhưng nếu bạn bật nó, hãy cấu hình kết nối cơ sở dữ liệu của nó riêng biệt.
  </Accordion>

  <Accordion title="Yêu cầu bị hết thời gian chờ hoặc bị rate limited">
    Giảm **Top K** của truy xuất, giảm kích thước prompt, dùng chunk nhỏ hơn, hoặc chọn model ID nhanh hơn cho node ChatCometAPI. Với rate limit, hãy chờ rồi thử lại với mức đồng thời thấp hơn, sau đó kiểm tra mức sử dụng và giới hạn tài khoản trong CometAPI console.
  </Accordion>
</AccordionGroup>

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "HowTo",
        "@id": "https://apidoc.cometapi.com/integrations/flowiseai#howto",
        "name": "Kết nối Flowise với CometAPI",
        "description": "Sử dụng hướng dẫn này để kết nối Flowise với CometAPI bằng cách thiết lập URL cơ sở, API key và các tùy chọn model hoặc provider.",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/flowiseai#step-1",
            "position": 1,
            "name": "Lấy API key CometAPI của bạn",
            "text": "Tạo hoặc mở tài khoản CometAPI của bạn, sau đó sao chép một API key đang hoạt động từ bảng điều khiển."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/flowiseai#step-2",
            "position": 2,
            "name": "Thêm node ChatCometAPI",
            "text": "Hoàn thành bước Thêm node ChatCometAPI trong hướng dẫn Kết nối Flowise với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/flowiseai#step-3",
            "position": 3,
            "name": "Tạo credential CometAPI",
            "text": "Hoàn thành bước Tạo credential CometAPI trong hướng dẫn Kết nối Flowise với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/flowiseai#step-4",
            "position": 4,
            "name": "Đặt CometAPI base path",
            "text": "Hoàn thành bước Đặt CometAPI base path trong hướng dẫn Kết nối Flowise với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/flowiseai#step-5",
            "position": 5,
            "name": "Thêm Prompt Template",
            "text": "Hoàn thành bước Thêm Prompt Template trong hướng dẫn Kết nối Flowise với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/flowiseai#step-6",
            "position": 6,
            "name": "Thêm LLM Chain",
            "text": "Hoàn thành bước Thêm LLM Chain trong hướng dẫn Kết nối Flowise với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/flowiseai#step-7",
            "position": 7,
            "name": "Lưu và kiểm thử flow",
            "text": "Hoàn thành bước Lưu và kiểm thử flow trong hướng dẫn Kết nối Flowise với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/flowiseai#step-8",
            "position": 8,
            "name": "Tạo và xử lý một Document Store",
            "text": "Hoàn thành bước Tạo và xử lý một Document Store trong hướng dẫn Kết nối Flowise 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": "Kết nối Flowise với CometAPI",
            "item": "https://apidoc.cometapi.com/integrations/flowiseai"
          }
        ]
      }
    ]
    }
    `}
</script>
