Mistral AI聊天完成 - Amazon Bedrock

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Mistral AI聊天完成

Mistral AI聊天完成 API 可讓您建立交談式應用程式。

提示

您可以將Mistral AI聊天完成 API 與基本推論作業 (InvokeModelInvokeModelWithResponse串流) 搭配使用。但是,我們建議您使用 Converse API 在應用程序中實現消息。Converse API 提供了一組統一的參數,可在支持消息的所有模型中工作。如需詳細資訊,請參閱 使用匡威 API

Mistral AI模型可根據 Apache 2.0 許可證提供。如需有關使用Mistral AI模型的詳細資訊,請參閱Mistral AI文件

支援的型號

您可以使用以下Mistral AI型號。

  • Mistral Large

您需要您想要使用的模型的模型 ID。若要取得模型 ID,請參閱Amazon 基岩模型 ID

請求與回應

Request

這些Mistral AI模型具有以下推論參數。

{ "messages": [ { "role": "system"|"user"|"assistant", "content": str }, { "role": "assistant", "content": "", "tool_calls": [ { "id": str, "function": { "name": str, "arguments": str } } ] }, { "role": "tool", "tool_call_id": str, "content": str } ], "tools": [ { "type": "function", "function": { "name": str, "description": str, "parameters": dict } } ], "tool_choice": "auto"|"any"|"none", "max_tokens": int, "top_p": float, "temperature": float }

下列是必要的參數。

  • message — (必要) 您要傳遞給模型的訊息。

    • role — 訊息的角色。有效的 值如下:

      • system — 設定交談中模型的行為和前後關聯。

      • user — 要傳送至模型的使用者訊息。

      • 助理-來自模型的響應。

    • 內容 — 訊息的內容。

    [ { "role": "user", "content": "What is the most popular song on WZPZ?" } ]

    若要傳遞工具結果,請在下列欄位中使用 JSON。

    • role — 訊息的角色。該值必須是tool

    • 工具請求的識別碼 — 工具請求的識別碼。您可以從上一個請求的響應中的tool_calls字段中獲取 ID。

    • 內容 — 工具的結果。

    以下示例是從一個工具獲得廣播電台上最受歡迎的歌曲的結果。

    { "role": "tool", "tool_call_id": "v6RMMiRlT7ygYkT4uULjtg", "content": "{\"song\": \"Elemental Hotel\", \"artist\": \"8 Storey Hike\"}" }

以下是選用參數。

  • tools-模型可能使用的工具的定義。

    如果您tools在請求中包含,模型可能會在消息中返回一個tool_calls字段,表示模型對這些工具的使用。然後,您可以使用模型產生的工具輸入來執行這些工具,然後選擇性地使用tool_result內容區塊將結果傳回模型。

    以下示例適用於獲取廣播電台上最受歡迎歌曲的工具。

    [ { "type": "function", "function": { "name": "top_song", "description": "Get the most popular song played on a radio station.", "parameters": { "type": "object", "properties": { "sign": { "type": "string", "description": "The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKRP." } }, "required": [ "sign" ] } } } ]
  • 工具選擇 — 指定如何呼叫函數。如果設置為none該模型將不會調用函數,並將生成一條消息。如果設置為auto模型,則可以選擇生成消息或調用函數。如果設置為any模型,則強制調用一個函數。

  • max_token — 指定要在產生的回應中使用的記號數目上限。一旦產生的文字超過 max_tokens,模型就會截斷回應。

    預設 下限 最大

    Mistral Large— 8,192

    1

    Mistral Large— 8,192

  • 溫度 — 控制模型所做預測的隨機性。如需詳細資訊,請參閱 推論參數

    預設 下限 最大

    Mistral Large— 0.7

    0

    1

  • top_p — 透過設定模型考慮用於下一個標記的最有可能候選人的百分比來控制模型產生的文字多樣性。如需詳細資訊,請參閱 推論參數

    預設 下限 最大

    Mistral Large— 1

    0

    1

Response

來自對 InvokeModel 的呼叫的 body 回應如下:

{ "choices": [ { "index": 0, "message": { "role": "assistant", "content": str, "tool_calls": [...] }, "stop_reason": "stop"|"length"|"tool_calls" } ] }

body 回應具有以下欄位:

  • 選擇 — 來自模型的輸出。字段。

    • 索引 — 訊息的索引。

    • 訊息 — 來自模型的訊息。

      • role — 訊息的角色。

      • 內容 — 訊息的內容。

      • tool_ call — 如果的值stop_reasontool_calls,則此欄位會包含模型要求您執行的工具請求清單。

        • id — 工具請求的 ID。

        • 函數-該模型正在請求的函數。

          • 名稱 — 函數的名稱。

          • 引數 — 要傳遞給工具的引數

        以下是一個工具的示例請求,該工具可以獲取廣播電台上的頂級歌曲。

        [ { "id": "v6RMMiRlT7ygYkT4uULjtg", "function": { "name": "top_song", "arguments": "{\"sign\": \"WZPZ\"}" } } ]
    • stop_reason — 響應停止生成文本的原因。可能值為:

      • stop — 模型已完成產生輸入提示的文字。模型停止,因為它沒有更多的產生內容,或者如果模型產生了您在 stop request 參數中定義的停止序列之一,所以停止。

      • length — 產生文字的標記長度超過的值max_tokens。回應會截斷為 max_tokens 記號。

      • 工具呼叫 — 模型要求您執行工具。