Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

Portkey AI

Cấu hình Portkey AI làm endpoint tùy chỉnh trong LibreChat.

Portkey là một AI gateway hỗ trợ hơn 250 mô hình thông qua endpoint tương thích với OpenAI, bổ sung khả năng quan sát (observability), hơn 50 cơ chế bảo vệ (guardrails), bộ nhớ đệm (caching) và định tuyến có điều kiện với cơ chế dự phòng (fallbacks) và thử lại (retries). Xem danh sách nhà cung cấp đầy đủ trong Portkey docs.

Nhận API key

Tạo một key tại app.portkey.ai và thêm nó vào tệp .env của bạn. Bạn cũng sẽ cần một gateway URL, thứ mà Portkey cung cấp cho các gateway tự lưu trữ (self-hosted) hoặc được lưu trữ (hosted):

PORTKEY_API_KEY=your-api-key
PORTKEY_GATEWAY_URL=your-gateway-url

Cấu hình

LibreChat yêu cầu trường apiKey, nhưng Portkey không sử dụng nó, vì vậy hãy truyền chuỗi dummy. Xác thực diễn ra thông qua các tiêu đề x-portkey-* thay thế. Có hai cách để kết nối, tùy thuộc vào việc bạn định tuyến theo Virtual Keys hay Configs. Thêm một trong các mục sau vào dưới endpoints.custom trong tệp librechat.yaml của bạn.

Virtual Keys

    - name: "Portkey"
      apiKey: "dummy"
      baseURL: ${PORTKEY_GATEWAY_URL}
      headers:
        x-portkey-api-key: "${PORTKEY_API_KEY}"
        x-portkey-virtual-key: "PORTKEY_OPENAI_VIRTUAL_KEY"
      models:
        default: ["gpt-4o-mini"]
        fetch: true
      titleConvo: true
      titleModel: "current_model"
      summarize: false
      summaryModel: "current_model"
      modelDisplayLabel: "Portkey:OpenAI"
      iconURL: https://images.crunchbase.com/image/upload/c_pad,f_auto,q_auto:eco,dpr_1/rjqy7ghvjoiu4cd1xjbf

Các cấu hình

    - name: "Portkey"
      apiKey: "dummy"
      baseURL: ${PORTKEY_GATEWAY_URL}
      headers:
        x-portkey-api-key: "${PORTKEY_API_KEY}"
        x-portkey-config: "pc-libre-xxx"
      models:
        default: ["llama-3.2"]
        fetch: true
      titleConvo: true
      titleModel: "current_model"
      summarize: false
      summaryModel: "current_model"
      modelDisplayLabel: "Portkey:Llama"
      iconURL: https://images.crunchbase.com/image/upload/c_pad,f_auto,q_auto:eco,dpr_1/rjqy7ghvjoiu4cd1xjbf

Ghi chú

  • Các Config cho phép bạn thiết lập các tham số cụ thể cho model như top_pmax_tokens ở phía Portkey. Xem tài liệu về Configs.
  • Thay thế PORTKEY_OPENAI_VIRTUAL_KEYpc-libre-xxx bằng khóa ảo (virtual key) hoặc ID cấu hình từ bảng điều khiển Portkey của bạn.

Hướng dẫn này thế nào?