DeepSeek 模型

Vertex AI 上的 DeepSeek 模型提供全代管無伺服器模型,並以 API 形式提供。如要在 Vertex AI 上使用 DeepSeek 模型,請直接將要求傳送至 Vertex AI API 端點。由於 DeepSeek 模型使用受管理的 API,因此您不必佈建或管理基礎架構。

您可以串流回應,減少使用者感受到的延遲時間。串流回應會使用伺服器推送事件 (SSE) 逐步串流回應。

可用的 DeepSeek 模型

您可以在 Vertex AI 中使用 DeepSeek 提供的下列模型。如要存取 DeepSeek 模型,請前往其 Model Garden 模型資訊卡。

DeepSeek-V3.1

DeepSeek-V3.1 是混合式模型,支援思考模式和非思考模式。與舊版相比,這個升級版在混合思考模式、工具呼叫和思考效率方面都有所提升。

DeepSeek R1 (0528)

DeepSeek R1 (0528) 是 DeepSeek R1 模型的最新版本。 與 DeepSeek-R1 相比,這款模型在推論深度和推論能力方面都有顯著提升。DeepSeek R1 (0528) 擅長處理各種工作,例如: 創意寫作、回答一般問題、編輯和摘要。

注意事項

  • 如要確保正式環境安全無虞,請將 DeepSeek R1 (0528) 與 Model Armor 整合,篩選 LLM 提示詞和回覆,找出各種安全風險。

前往 DeepSeek R1 (0528) 模型資訊卡

使用 DeepSeek 模型

您可以使用 curl 指令,透過下列模型名稱將要求傳送至 Vertex AI 端點:

  • 如要使用 DeepSeek-V3.1,請使用 deepseek-v3.1-maas
  • 如要使用 DeepSeek R1 (0528),請使用 deepseek-r1-0528-maas

事前準備

如要在 Vertex AI 中使用 DeepSeek 模型,請完成下列步驟。如要使用 Vertex AI,必須啟用 Vertex AI API (aiplatform.googleapis.com)。如果您已有啟用 Vertex AI API 的專案,可以改用該專案,不必建立新專案。

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API.

    Enable the API

  8. 前往下列任一 Model Garden 模型資訊卡,然後按一下「啟用」
  9. 對 DeepSeek 模型發出串流通話

    以下範例會對 DeepSeek 模型發出串流呼叫:

    REST

    設定環境後,即可使用 REST 測試文字提示。下列範例會將要求傳送至發布商模型端點。

    使用任何要求資料之前,請先替換以下項目:

    • LOCATION:支援 DeepSeek 模型的區域。
    • MODEL:您要使用的模型名稱
    • ROLE:與訊息相關聯的角色。您可以指定 userassistant。 第一則訊息必須使用 user 角色。模型會交替進行 userassistant 輪次。如果最終訊息使用 assistant 角色,回應內容會立即接續該訊息中的內容。您可以使用這項功能限制模型回覆的部分內容。
    • CONTENTuserassistant 訊息的內容,例如文字。
    • MAX_OUTPUT_TOKENS: 回覆內可以生成的權杖數量上限。一個詞元約為四個字元。100 個符記約等於 60 到 80 個字。

      如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。

    • STREAM:布林值,用於指定是否要串流傳輸回應。串流回應可縮短使用者感受到的延遲時間。設為 true 可串流回應,設為 false 則可一次傳回回應。

    HTTP 方法和網址:

    POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions

    JSON 要求主體:

    {
      "model": "deepseek-ai/MODEL",
      "messages": [
        {
          "role": "ROLE",
          "content": "CONTENT"
        }
      ],
      "max_tokens": MAX_OUTPUT_TOKENS,
      "stream": true
    }
    

    如要傳送要求,請選擇以下其中一個選項:

    curl

    將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions"

    PowerShell

    將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions" | Select-Object -Expand Content

    您應該會收到類似如下的 JSON 回應。

    對 DeepSeek 模型發出非串流呼叫

    以下範例會對 DeepSeek 模型發出非串流呼叫:

    REST

    設定環境後,即可使用 REST 測試文字提示。下列範例會將要求傳送至發布商模型端點。

    使用任何要求資料之前,請先替換以下項目:

    • LOCATION:支援 DeepSeek 模型的區域。
    • MODEL:您要使用的模型名稱
    • ROLE:與訊息相關聯的角色。您可以指定 userassistant。 第一則訊息必須使用 user 角色。模型會交替進行 userassistant 輪次。如果最終訊息使用 assistant 角色,回應內容會立即接續該訊息中的內容。您可以使用這項功能限制模型回覆的部分內容。
    • CONTENTuserassistant 訊息的內容,例如文字。
    • MAX_OUTPUT_TOKENS: 回覆內可以生成的權杖數量上限。一個詞元約為四個字元。100 個符記約等於 60 到 80 個字。

      如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。

    • STREAM:布林值,用於指定是否要串流傳輸回應。串流回應可縮短使用者感受到的延遲時間。設為 true 可串流回應,設為 false 則可一次傳回回應。

    HTTP 方法和網址:

    POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions

    JSON 要求主體:

    {
      "model": "deepseek-ai/MODEL",
      "messages": [
        {
          "role": "ROLE",
          "content": "CONTENT"
        }
      ],
      "max_tokens": MAX_OUTPUT_TOKENS,
      "stream": false
    }
    

    如要傳送要求,請選擇以下其中一個選項:

    curl

    將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions"

    PowerShell

    將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions" | Select-Object -Expand Content

    您應該會收到類似如下的 JSON 回應。

    DeepSeek 模型支援的區域和配額

    如果是 DeepSeek 模型,配額適用於模型可用的每個區域。配額以每分鐘查詢次數 (QPM) 為單位。

    模型 區域 配額 脈絡長度
    DeepSeek-V3.1
    us-west2
    163,840
    DeepSeek R1 (0528)
    us-central1
    • 每分鐘查詢次數:1000
    163,840

    如要增加任何 Vertex AI 的生成式 AI 配額,可以透過 Google Cloud 控制台申請提高配額。如要進一步瞭解配額,請參閱「使用配額」。