分享方式:


如何使用 Meta Llama 系列模型

重要

本文所述的部分功能可能僅適用於預覽版。 此預覽版本沒有服務等級協定,不建議將其用於生產工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

在本文中,您將了解 Meta Llama 系列模型以及如何使用它們。 Meta Llama 模型和工具是經過預先訓練和微調的生成式 AI 文字和影像推理模型的集合 - 規模從用於裝置上和邊緣推理的 SLM (1B、3B Base 和 Instruct 模型) 到中型 LLM (7B、8B 和 70B Base 和 Instruct 模型),以及用於合成資料生成和蒸餾使用案例的高效能模型 (例如 Meta Llama 3.1 405B Instruct)。

提示

請透過 Meta 的部落格Microsoft 技術社群部落格來查看我們在 Azure AI 模型目錄上發佈的 Meta Llama 3.2 系列模型的公告。

Meta Llama 系列模型

Meta Llama 系列模型包含下列模型:

Llama 3.2 系列集合的 SLM 和影像推理模型現已推出。 即將推出的 Llama 3.2 11B Vision Instruct 和 Llama 3.2 90B Vision Instruct 將透過「模型即服務」作為無伺服器 API 端點來提供。 從今天開始,以下模型將可透過受控計算來進行部署:

  • Llama 3.2 1B
  • Llama 3.2 3B
  • Llama 3.2 1B Instruct
  • Llama 3.2 3B Instruct
  • Llama Guard 3 1B
  • Llama Guard 11B Vision
  • Llama 3.2 11B Vision Instruct
  • Llama 3.2 90B Vision Instruct 可用於受控計算部署。

必要條件

若要搭配 Azure AI Studio 使用 Meta Llama 模型,您需要下列必要條件:

模型部署

部署至無伺服器 API

您可以透過隨用隨付計費,將 Meta Llama 模型部署至無伺服器 API 端點。 這種部署可讓您以 API 的形式取用模型,而不必在您的訂用帳戶上裝載模型,同時讓組織保持所需的企業安全性和合規性。

部署至無伺服器 API 端點不需要您訂用帳戶的配額。 如果您的模型尚未部署,請使用 Azure AI Studio、適用於 Python 的 Azure Machine Learning SDK、Azure CLI 或 ARM 範本來將模型部署為無伺服器 API (英文)。

部署至自我裝載的受控計算

Meta Llama 模型可以部署至我們自我裝載的受控推斷解決方案,其可讓您自訂和控制提供模型之方式的所有詳細資料。

若要部署至自我裝載的受控計算,您的訂用帳戶必須具有足夠的配額。 如果您沒有足夠的可用配額,您可以透過選取 [我想要使用共用配額且我了解此端點將會在 168 小時後刪除] 選項,來使用我們的臨時配額存取。

[將模型部署至受控計算]

已安裝推斷套件

您可以透過使用 azure-ai-inference 套件搭配 Python,從此模型取用預測。 若要安裝此套件,您需要下列先決條件:

  • 已安裝 Python 3.8 或更新版本,包括 pip。
  • 端點 URL。 若要建構用戶端程式庫,您必須傳遞端點 URL。 端點 URL 具有 https://your-host-name.your-azure-region.inference.ai.azure.com 的形式,其中 your-host-name 是您唯一的模型部署主機名稱,且 your-azure-region 是模型所部署的 Azure 區域 (例如 eastus2)。
  • 視您的模型部署和驗證喜好設定而定,您需要金鑰來針對服務進行驗證,或是 Microsoft Entra ID 認證。 金鑰是 32 個字元的字串。

具備這些先決條件之後,請使用下列命令安裝 Azure AI 推斷套件:

pip install azure-ai-inference

深入了解 [Azure AI 推斷套件和參考]

使用聊天完成

在本節中,您會使用 [Azure AI 模型推斷 API] 搭配聊天完成模型來用於聊天。

提示

Azure AI 模型推斷 API (英文) 可讓您使用相同的程式碼和結構與 Azure AI Studio 中部署的大部分模型進行交談,包括 Meta Llama Instruct 模型 (純文字或影像推理模型)。

建立用戶端以取用模型

首先,建立用戶端以取用模型。 下列程式碼會使用儲存在環境變數中的端點 URL 和金鑰。

import os
from azure.ai.inference import ChatCompletionsClient
from azure.core.credentials import AzureKeyCredential

client = ChatCompletionsClient(
    endpoint=os.environ["AZURE_INFERENCE_ENDPOINT"],
    credential=AzureKeyCredential(os.environ["AZURE_INFERENCE_CREDENTIAL"]),
)

當您將模型部署至具有 Microsoft Entra ID 支援的自我裝載線上端點時,您可以使用下列程式碼片段來建立用戶端。

import os
from azure.ai.inference import ChatCompletionsClient
from azure.identity import DefaultAzureCredential

client = ChatCompletionsClient(
    endpoint=os.environ["AZURE_INFERENCE_ENDPOINT"],
    credential=DefaultAzureCredential(),
)

注意

目前,無伺服器 API 端點不支援使用 Microsoft Entra ID 進行驗證。

取得模型的功能

/info 路由會傳回部署至端點之模型的相關資訊。 透過呼叫下列方法,以傳回模型的資訊:

model_info = client.get_model_info()

回應如下:

print("Model name:", model_info.model_name)
print("Model type:", model_info.model_type)
print("Model provider name:", model_info.model_provider_name)
Model name: Meta-Llama-3.1-405B-Instruct
Model type: chat-completions
Model provider name: Meta

建立聊天完成要求

下列範例示範如何針對模型建立基本聊天完成要求。

from azure.ai.inference.models import SystemMessage, UserMessage

response = client.complete(
    messages=[
        SystemMessage(content="You are a helpful assistant."),
        UserMessage(content="How many languages are in the world?"),
    ],
)

回應如下,您可以在其中查看模型的使用量統計資料:

print("Response:", response.choices[0].message.content)
print("Model:", response.model)
print("Usage:")
print("\tPrompt tokens:", response.usage.prompt_tokens)
print("\tTotal tokens:", response.usage.total_tokens)
print("\tCompletion tokens:", response.usage.completion_tokens)
Response: As of now, it's estimated that there are about 7,000 languages spoken around the world. However, this number can vary as some languages become extinct and new ones develop. It's also important to note that the number of speakers can greatly vary between languages, with some having millions of speakers and others only a few hundred.
Model: Meta-Llama-3.1-405B-Instruct
Usage: 
  Prompt tokens: 19
  Total tokens: 91
  Completion tokens: 72

檢查回應中的 usage 區段,以查看提示所使用的權杖數目、產生的權杖總數,以及用於完成文字的權杖數目。

串流內容

根據預設,完成 API 會在單一回應中傳回整個產生的內容。 如果您正在產生的完成很長,則等候回應可能需要數秒鐘的時間。

您可以 [串流] 內容,以在內容產生期間取得它。 串流內容可讓您在內容變成可用時立即開始處理完成。 此模式會傳回以 [僅限資料的伺服器傳送事件] 形式將回應串流回來的物件。 從差異欄位擷取區塊,而不是訊息欄位。

result = client.complete(
    messages=[
        SystemMessage(content="You are a helpful assistant."),
        UserMessage(content="How many languages are in the world?"),
    ],
    temperature=0,
    top_p=1,
    max_tokens=2048,
    stream=True,
)

若要串流完成,請在呼叫模型時設定 stream=True

若要將輸出視覺化,請定義協助程式函式來列印串流。

def print_stream(result):
    """
    Prints the chat completion with streaming.
    """
    import time
    for update in result:
        if update.choices:
            print(update.choices[0].delta.content, end="")

您可以將串流產生內容的方式視覺化:

print_stream(result)

探索推斷用戶端支援的更多參數

探索您可以在推斷用戶端中指定的其他參數。 如需所有支援參數及其對應文件的完整清單,請參閱 [Azure AI 模型推斷 API 參考]

from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
    messages=[
        SystemMessage(content="You are a helpful assistant."),
        UserMessage(content="How many languages are in the world?"),
    ],
    presence_penalty=0.1,
    frequency_penalty=0.8,
    max_tokens=2048,
    stop=["<|endoftext|>"],
    temperature=0,
    top_p=1,
    response_format={ "type": ChatCompletionsResponseFormatText() },
)

警告

Meta Llama 模型不支援 JSON 輸出格式化 (response_format = { "type": "json_object" })。 您隨時都可以提示模型產生 JSON 輸出。 不過,這類輸出不保證為有效的 JSON。

如果您想要傳遞不在所支援參數清單中的參數,您可以使用 [額外的參數] 將其傳遞至基礎模型。 請參閱 [將額外的參數傳遞至模型]

將額外的參數傳遞至模型

Azure AI 模型推斷 API 可讓您將額外的參數傳遞至模型。 下列程式碼範例示範如何將額外的參數 logprobs 傳遞至模型。

將額外的參數傳遞至 Azure AI 模型推斷 API 之前,請確定您的模型支援那些額外的參數。 對基礎模型提出要求時,會將標頭 extra-parameters 傳遞至具有 pass-through 值的模型。 這個值會告訴端點將額外的參數傳遞至模型。 搭配模型使用額外的參數,不保證模型實際上可以處理這些參數。 請參閱模型的文件,以了解支援哪些額外的參數。

response = client.complete(
    messages=[
        SystemMessage(content="You are a helpful assistant."),
        UserMessage(content="How many languages are in the world?"),
    ],
    model_extras={
        "logprobs": True
    }
)

下列額外參數可以傳遞至 Meta Llama 模型:

名稱 描述 類型
n 每個提示要產生的完成項數量。 注意:因為此參數會產生許多完成項,所以會快速消耗權杖配額。 integer
best_of 產生 best_of 完成伺服器端,並傳回「最佳」(每個權杖都具有最低對數機率的 best_of)。 結果不能串流。 搭配 n 使用時,best_of 控制待選完成項的數目,而 n 會指定傳回的數目,best_of 必須大於 n。 注意:因為此參數會產生許多完成項,所以會快速消耗權杖配額。 integer
logprobs 一個數字,指出包括最可能是權杖之 logprobs 的對數機率及所選權杖。 例如,如果 logprobs 為 10,則 API 會傳回 10 個最可能的權杖清單。 API 一律會傳回取樣權杖的 logprob,因此,回應中可能包含多達 logprobs+1 個元素。 integer
ignore_eos 是否要忽略 EOS 權杖,並在產生 EOS 權杖之後繼續產生權杖。 boolean
use_beam_search 是否要使用集束搜尋而不是取樣。 在這種情況下,best_of 必須大於 1 且 temperature 必須是 0。 boolean
stop_token_ids 產生時會停止進一步產生權杖之權杖的識別碼清單。 傳回的輸出包含停止權杖,除非停止權杖是特殊權杖。 array
skip_special_tokens 是否要在輸出中跳過特殊權杖。 boolean

套用內容安全

Azure AI 模型推斷 API 支援 Azure AI 內容安全。 當您使用已開啟 Azure AI 內容安全的部署時,輸入和輸出都會通過旨在偵測及防止有害內容輸出的一組分類模型。 內容篩選系統會偵測並針對輸入提示和輸出完成中的特定類別的潛在有害內容採取動作。

下列範例示範當模型偵測到輸入提示中的有害內容並啟用內容安全時,如何處理事件。

from azure.ai.inference.models import AssistantMessage, UserMessage, SystemMessage

try:
    response = client.complete(
        messages=[
            SystemMessage(content="You are an AI assistant that helps people find information."),
            UserMessage(content="Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."),
        ]
    )

    print(response.choices[0].message.content)

except HttpResponseError as ex:
    if ex.status_code == 400:
        response = ex.response.json()
        if isinstance(response, dict) and "error" in response:
            print(f"Your request triggered an {response['error']['code']} error:\n\t {response['error']['message']}")
        else:
            raise
    raise

提示

若要深入了解如何設定及控制 Azure AI 內容安全設定,請參閱 Azure AI 內容安全文件

注意

Azure AI 內容安全僅適用於部署為無伺服器 API 端點的模型。

Meta Llama 模型

Meta Llama 模型包含下列模型:

Meta Llama 3.1 的多語系大型語言模型 (LLM) 集合是經過預先訓練和指令微調的生成式模型集合,大小有 8B、70B 和 405B (文字輸入/文字輸出)。 Llama 3.1 經過指令微調的純文字模型 (8B、70B、405B) 已針對多語系對話使用案例進行最佳化,並且在通用產業基準上優於許多可用的開放原始碼和封閉式聊天模型。

有下列模型可用:

必要條件

若要搭配 Azure AI Studio 使用 Meta Llama 模型,您需要下列必要條件:

模型部署

部署至無伺服器 API

您可以透過隨用隨付計費,將 Meta Llama 模型部署至無伺服器 API 端點。 這種部署可讓您以 API 的形式取用模型,而不必在您的訂用帳戶上裝載模型,同時讓組織保持所需的企業安全性和合規性。

部署至無伺服器 API 端點不需要您訂用帳戶的配額。 如果您的模型尚未部署,請使用 Azure AI Studio、適用於 Python 的 Azure Machine Learning SDK、Azure CLI 或 ARM 範本來將模型部署為無伺服器 API (英文)。

部署至自我裝載的受控計算

Meta Llama 模型可以部署至我們自我裝載的受控推斷解決方案,其可讓您自訂和控制提供模型之方式的所有詳細資料。

若要部署至自我裝載的受控計算,您的訂用帳戶必須具有足夠的配額。 如果您沒有足夠的可用配額,您可以透過選取 [我想要使用共用配額且我了解此端點將會在 168 小時後刪除] 選項,來使用我們的臨時配額存取。

[將模型部署至受控計算]

已安裝推斷套件

您可以使用 npm@azure-rest/ai-inference 套件來取用此模型的預測。 若要安裝此套件,您需要下列先決條件:

  • 具有 npmNode.js LTS 版本。
  • 端點 URL。 若要建構用戶端程式庫,您必須傳遞端點 URL。 端點 URL 具有 https://your-host-name.your-azure-region.inference.ai.azure.com 的形式,其中 your-host-name 是您唯一的模型部署主機名稱,且 your-azure-region 是模型所部署的 Azure 區域 (例如 eastus2)。
  • 視您的模型部署和驗證喜好設定而定,您需要金鑰來針對服務進行驗證,或是 Microsoft Entra ID 認證。 金鑰是 32 個字元的字串。

具備這些先決條件之後,使用下列命令來安裝適用於 JavaScript 的 Azure 推斷程式庫:

npm install @azure-rest/ai-inference

使用聊天完成

在本節中,您會使用 [Azure AI 模型推斷 API] 搭配聊天完成模型來用於聊天。

提示

Azure AI 模型推斷 API (英文) 可讓您與在 Azure AI Studio 中部署、具有相同程式碼和結構相同的大部分模型交談,包括 Meta Llama 模型。

建立用戶端以取用模型

首先,建立用戶端以取用模型。 下列程式碼會使用儲存在環境變數中的端點 URL 和金鑰。

import ModelClient from "@azure-rest/ai-inference";
import { isUnexpected } from "@azure-rest/ai-inference";
import { AzureKeyCredential } from "@azure/core-auth";

const client = new ModelClient(
    process.env.AZURE_INFERENCE_ENDPOINT, 
    new AzureKeyCredential(process.env.AZURE_INFERENCE_CREDENTIAL)
);

當您將模型部署至具有 Microsoft Entra ID 支援的自我裝載線上端點時,您可以使用下列程式碼片段來建立用戶端。

import ModelClient from "@azure-rest/ai-inference";
import { isUnexpected } from "@azure-rest/ai-inference";
import { DefaultAzureCredential }  from "@azure/identity";

const client = new ModelClient(
    process.env.AZURE_INFERENCE_ENDPOINT, 
    new DefaultAzureCredential()
);

注意

目前,無伺服器 API 端點不支援使用 Microsoft Entra ID 進行驗證。

取得模型的功能

/info 路由會傳回部署至端點之模型的相關資訊。 透過呼叫下列方法,以傳回模型的資訊:

var model_info = await client.path("/info").get()

回應如下:

console.log("Model name: ", model_info.body.model_name)
console.log("Model type: ", model_info.body.model_type)
console.log("Model provider name: ", model_info.body.model_provider_name)
Model name: Meta-Llama-3.1-405B-Instruct
Model type: chat-completions
Model provider name: Meta

建立聊天完成要求

下列範例示範如何針對模型建立基本聊天完成要求。

var messages = [
    { role: "system", content: "You are a helpful assistant" },
    { role: "user", content: "How many languages are in the world?" },
];

var response = await client.path("/chat/completions").post({
    body: {
        messages: messages,
    }
});

回應如下,您可以在其中查看模型的使用量統計資料:

if (isUnexpected(response)) {
    throw response.body.error;
}

console.log("Response: ", response.body.choices[0].message.content);
console.log("Model: ", response.body.model);
console.log("Usage:");
console.log("\tPrompt tokens:", response.body.usage.prompt_tokens);
console.log("\tTotal tokens:", response.body.usage.total_tokens);
console.log("\tCompletion tokens:", response.body.usage.completion_tokens);
Response: As of now, it's estimated that there are about 7,000 languages spoken around the world. However, this number can vary as some languages become extinct and new ones develop. It's also important to note that the number of speakers can greatly vary between languages, with some having millions of speakers and others only a few hundred.
Model: Meta-Llama-3.1-405B-Instruct
Usage: 
  Prompt tokens: 19
  Total tokens: 91
  Completion tokens: 72

檢查回應中的 usage 區段,以查看提示所使用的權杖數目、產生的權杖總數,以及用於完成文字的權杖數目。

串流內容

根據預設,完成 API 會在單一回應中傳回整個產生的內容。 如果您正在產生的完成很長,則等候回應可能需要數秒鐘的時間。

您可以 [串流] 內容,以在內容產生期間取得它。 串流內容可讓您在內容變成可用時立即開始處理完成。 此模式會傳回以 [僅限資料的伺服器傳送事件] 形式將回應串流回來的物件。 從差異欄位擷取區塊,而不是訊息欄位。

var messages = [
    { role: "system", content: "You are a helpful assistant" },
    { role: "user", content: "How many languages are in the world?" },
];

var response = await client.path("/chat/completions").post({
    body: {
        messages: messages,
    }
}).asNodeStream();

若要串流完成,在呼叫模型時使用 .asNodeStream()

您可以將串流產生內容的方式視覺化:

var stream = response.body;
if (!stream) {
    stream.destroy();
    throw new Error(`Failed to get chat completions with status: ${response.status}`);
}

if (response.status !== "200") {
    throw new Error(`Failed to get chat completions: ${response.body.error}`);
}

var sses = createSseStream(stream);

for await (const event of sses) {
    if (event.data === "[DONE]") {
        return;
    }
    for (const choice of (JSON.parse(event.data)).choices) {
        console.log(choice.delta?.content ?? "");
    }
}

探索推斷用戶端支援的更多參數

探索您可以在推斷用戶端中指定的其他參數。 如需所有支援參數及其對應文件的完整清單,請參閱 [Azure AI 模型推斷 API 參考]

var messages = [
    { role: "system", content: "You are a helpful assistant" },
    { role: "user", content: "How many languages are in the world?" },
];

var response = await client.path("/chat/completions").post({
    body: {
        messages: messages,
        presence_penalty: "0.1",
        frequency_penalty: "0.8",
        max_tokens: 2048,
        stop: ["<|endoftext|>"],
        temperature: 0,
        top_p: 1,
        response_format: { type: "text" },
    }
});

警告

Meta Llama 模型不支援 JSON 輸出格式化 (response_format = { "type": "json_object" })。 您隨時都可以提示模型產生 JSON 輸出。 不過,這類輸出不保證為有效的 JSON。

如果您想要傳遞不在所支援參數清單中的參數,您可以使用 [額外的參數] 將其傳遞至基礎模型。 請參閱 [將額外的參數傳遞至模型]

將額外的參數傳遞至模型

Azure AI 模型推斷 API 可讓您將額外的參數傳遞至模型。 下列程式碼範例示範如何將額外的參數 logprobs 傳遞至模型。

將額外的參數傳遞至 Azure AI 模型推斷 API 之前,請確定您的模型支援那些額外的參數。 對基礎模型提出要求時,會將標頭 extra-parameters 傳遞至具有 pass-through 值的模型。 這個值會告訴端點將額外的參數傳遞至模型。 搭配模型使用額外的參數,不保證模型實際上可以處理這些參數。 請參閱模型的文件,以了解支援哪些額外的參數。

var messages = [
    { role: "system", content: "You are a helpful assistant" },
    { role: "user", content: "How many languages are in the world?" },
];

var response = await client.path("/chat/completions").post({
    headers: {
        "extra-params": "pass-through"
    },
    body: {
        messages: messages,
        logprobs: true
    }
});

下列額外參數可以傳遞至 Meta Llama 模型:

名稱 描述 類型
n 每個提示要產生的完成項數量。 注意:因為此參數會產生許多完成項,所以會快速消耗權杖配額。 integer
best_of 產生 best_of 完成伺服器端,並傳回「最佳」(每個權杖都具有最低對數機率的 best_of)。 結果不能串流。 搭配 n 使用時,best_of 控制待選完成項的數目,而 n 會指定傳回的數目,best_of 必須大於 n。 注意:因為此參數會產生許多完成項,所以會快速消耗權杖配額。 integer
logprobs 一個數字,指出包括最可能是權杖之 logprobs 的對數機率及所選權杖。 例如,如果 logprobs 為 10,則 API 會傳回 10 個最可能的權杖清單。 API 一律會傳回取樣權杖的 logprob,因此,回應中可能包含多達 logprobs+1 個元素。 integer
ignore_eos 是否要忽略 EOS 權杖,並在產生 EOS 權杖之後繼續產生權杖。 boolean
use_beam_search 是否要使用集束搜尋而不是取樣。 在這種情況下,best_of 必須大於 1 且 temperature 必須是 0。 boolean
stop_token_ids 產生時會停止進一步產生權杖之權杖的識別碼清單。 傳回的輸出包含停止權杖,除非停止權杖是特殊權杖。 array
skip_special_tokens 是否要在輸出中跳過特殊權杖。 boolean

套用內容安全

Azure AI 模型推斷 API 支援 Azure AI 內容安全。 當您使用已開啟 Azure AI 內容安全的部署時,輸入和輸出都會通過旨在偵測及防止有害內容輸出的一組分類模型。 內容篩選系統會偵測並針對輸入提示和輸出完成中的特定類別的潛在有害內容採取動作。

下列範例示範當模型偵測到輸入提示中的有害內容並啟用內容安全時,如何處理事件。

try {
    var messages = [
        { role: "system", content: "You are an AI assistant that helps people find information." },
        { role: "user", content: "Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills." },
    ];

    var response = await client.path("/chat/completions").post({
        body: {
            messages: messages,
        }
    });

    console.log(response.body.choices[0].message.content);
}
catch (error) {
    if (error.status_code == 400) {
        var response = JSON.parse(error.response._content);
        if (response.error) {
            console.log(`Your request triggered an ${response.error.code} error:\n\t ${response.error.message}`);
        }
        else
        {
            throw error;
        }
    }
}

提示

若要深入了解如何設定及控制 Azure AI 內容安全設定,請參閱 Azure AI 內容安全文件

注意

Azure AI 內容安全僅適用於部署為無伺服器 API 端點的模型。

Meta Llama 模型

Meta Llama 模型包含下列模型:

Meta Llama 3.1 的多語系大型語言模型 (LLM) 集合是經過預先訓練和指令微調的生成式模型集合,大小有 8B、70B 和 405B (文字輸入/文字輸出)。 Llama 3.1 經過指令微調的純文字模型 (8B、70B、405B) 已針對多語系對話使用案例進行最佳化,並且在通用產業基準上優於許多可用的開放原始碼和封閉式模型。

有下列模型可用:

必要條件

若要搭配 Azure AI Studio 使用 Meta Llama 模型,您需要下列必要條件:

模型部署

部署至無伺服器 API

您可以透過隨用隨付計費,將 Meta Llama 模型部署至無伺服器 API 端點。 這種部署可讓您以 API 的形式取用模型,而不必在您的訂用帳戶上裝載模型,同時讓組織保持所需的企業安全性和合規性。

部署至無伺服器 API 端點不需要您訂用帳戶的配額。 如果您的模型尚未部署,請使用 Azure AI Studio、適用於 Python 的 Azure Machine Learning SDK、Azure CLI 或 ARM 範本來將模型部署為無伺服器 API (英文)。

部署至自我裝載的受控計算

Meta Llama 模型可以部署至我們自我裝載的受控推斷解決方案,其可讓您自訂和控制提供模型之方式的所有詳細資料。

若要部署至自我裝載的受控計算,您的訂用帳戶必須具有足夠的配額。 如果您沒有足夠的可用配額,您可以透過選取 [我想要使用共用配額且我了解此端點將會在 168 小時後刪除] 選項,來使用我們的臨時配額存取。

[將模型部署至受控計算]

已安裝推斷套件

您可以從 [NuGet] 使用 Azure.AI.Inference 套件來取用此模型的預測。 若要安裝此套件,您需要下列先決條件:

  • 端點 URL。 若要建構用戶端程式庫,您必須傳遞端點 URL。 端點 URL 具有 https://your-host-name.your-azure-region.inference.ai.azure.com 的形式,其中 your-host-name 是您唯一的模型部署主機名稱,且 your-azure-region 是模型所部署的 Azure 區域 (例如 eastus2)。
  • 視您的模型部署和驗證喜好設定而定,您需要金鑰來針對服務進行驗證,或是 Microsoft Entra ID 認證。 金鑰是 32 個字元的字串。

具備這些先決條件之後,使用下列命令來安裝 Azure AI 推斷程式庫:

dotnet add package Azure.AI.Inference --prerelease

您也可以使用 Microsoft Entra ID (先前稱為 Azure Active Directory) 進行驗證。 若要使用 Azure SDK 所提供的認證提供者,請安裝 Azure.Identity 套件:

dotnet add package Azure.Identity

匯入下列命名空間:

using Azure;
using Azure.Identity;
using Azure.AI.Inference;

此範例也會使用下列命名空間,但您可能不一定需要它們:

using System.Text.Json;
using System.Text.Json.Serialization;
using System.Reflection;

使用聊天完成

在本節中,您會使用 [Azure AI 模型推斷 API] 搭配聊天完成模型來用於聊天。

提示

Azure AI 模型推斷 API (英文) 可讓您與在 Azure AI Studio 中部署、具有相同程式碼和結構相同的大部分模型交談,包括 Meta Llama 聊天模型。

建立用戶端以取用模型

首先,建立用戶端以取用模型。 下列程式碼會使用儲存在環境變數中的端點 URL 和金鑰。

ChatCompletionsClient client = new ChatCompletionsClient(
    new Uri(Environment.GetEnvironmentVariable("AZURE_INFERENCE_ENDPOINT")),
    new AzureKeyCredential(Environment.GetEnvironmentVariable("AZURE_INFERENCE_CREDENTIAL"))
);

當您將模型部署至具有 Microsoft Entra ID 支援的自我裝載線上端點時,您可以使用下列程式碼片段來建立用戶端。

client = new ChatCompletionsClient(
    new Uri(Environment.GetEnvironmentVariable("AZURE_INFERENCE_ENDPOINT")),
    new DefaultAzureCredential(includeInteractiveCredentials: true)
);

注意

目前,無伺服器 API 端點不支援使用 Microsoft Entra ID 進行驗證。

取得模型的功能

/info 路由會傳回部署至端點之模型的相關資訊。 透過呼叫下列方法,以傳回模型的資訊:

Response<ModelInfo> modelInfo = client.GetModelInfo();

回應如下:

Console.WriteLine($"Model name: {modelInfo.Value.ModelName}");
Console.WriteLine($"Model type: {modelInfo.Value.ModelType}");
Console.WriteLine($"Model provider name: {modelInfo.Value.ModelProviderName}");
Model name: Meta-Llama-3.1-405B-Instruct
Model type: chat-completions
Model provider name: Meta

建立聊天完成要求

下列範例示範如何針對模型建立基本聊天完成要求。

ChatCompletionsOptions requestOptions = new ChatCompletionsOptions()
{
    Messages = {
        new ChatRequestSystemMessage("You are a helpful assistant."),
        new ChatRequestUserMessage("How many languages are in the world?")
    },
};

Response<ChatCompletions> response = client.Complete(requestOptions);

回應如下,您可以在其中查看模型的使用量統計資料:

Console.WriteLine($"Response: {response.Value.Choices[0].Message.Content}");
Console.WriteLine($"Model: {response.Value.Model}");
Console.WriteLine("Usage:");
Console.WriteLine($"\tPrompt tokens: {response.Value.Usage.PromptTokens}");
Console.WriteLine($"\tTotal tokens: {response.Value.Usage.TotalTokens}");
Console.WriteLine($"\tCompletion tokens: {response.Value.Usage.CompletionTokens}");
Response: As of now, it's estimated that there are about 7,000 languages spoken around the world. However, this number can vary as some languages become extinct and new ones develop. It's also important to note that the number of speakers can greatly vary between languages, with some having millions of speakers and others only a few hundred.
Model: Meta-Llama-3.1-405B-Instruct
Usage: 
  Prompt tokens: 19
  Total tokens: 91
  Completion tokens: 72

檢查回應中的 usage 區段,以查看提示所使用的權杖數目、產生的權杖總數,以及用於完成文字的權杖數目。

串流內容

根據預設,完成 API 會在單一回應中傳回整個產生的內容。 如果您正在產生的完成很長,則等候回應可能需要數秒鐘的時間。

您可以 [串流] 內容,以在內容產生期間取得它。 串流內容可讓您在內容變成可用時立即開始處理完成。 此模式會傳回以 [僅限資料的伺服器傳送事件] 形式將回應串流回來的物件。 從差異欄位擷取區塊,而不是訊息欄位。

static async Task StreamMessageAsync(ChatCompletionsClient client)
{
    ChatCompletionsOptions requestOptions = new ChatCompletionsOptions()
    {
        Messages = {
            new ChatRequestSystemMessage("You are a helpful assistant."),
            new ChatRequestUserMessage("How many languages are in the world? Write an essay about it.")
        },
        MaxTokens=4096
    };

    StreamingResponse<StreamingChatCompletionsUpdate> streamResponse = await client.CompleteStreamingAsync(requestOptions);

    await PrintStream(streamResponse);
}

若要串流完成,在呼叫模型時使用 CompleteStreamingAsync 方法。 請注意,在此範例中,呼叫會包裝在非同步方法中。

若要將輸出視覺化,請定義非同步方法,以在主控台中列印串流。

static async Task PrintStream(StreamingResponse<StreamingChatCompletionsUpdate> response)
{
    await foreach (StreamingChatCompletionsUpdate chatUpdate in response)
    {
        if (chatUpdate.Role.HasValue)
        {
            Console.Write($"{chatUpdate.Role.Value.ToString().ToUpperInvariant()}: ");
        }
        if (!string.IsNullOrEmpty(chatUpdate.ContentUpdate))
        {
            Console.Write(chatUpdate.ContentUpdate);
        }
    }
}

您可以將串流產生內容的方式視覺化:

StreamMessageAsync(client).GetAwaiter().GetResult();

探索推斷用戶端支援的更多參數

探索您可以在推斷用戶端中指定的其他參數。 如需所有支援參數及其對應文件的完整清單,請參閱 [Azure AI 模型推斷 API 參考]

requestOptions = new ChatCompletionsOptions()
{
    Messages = {
        new ChatRequestSystemMessage("You are a helpful assistant."),
        new ChatRequestUserMessage("How many languages are in the world?")
    },
    PresencePenalty = 0.1f,
    FrequencyPenalty = 0.8f,
    MaxTokens = 2048,
    StopSequences = { "<|endoftext|>" },
    Temperature = 0,
    NucleusSamplingFactor = 1,
    ResponseFormat = new ChatCompletionsResponseFormatText()
};

response = client.Complete(requestOptions);
Console.WriteLine($"Response: {response.Value.Choices[0].Message.Content}");

警告

Meta Llama 模型不支援 JSON 輸出格式化 (response_format = { "type": "json_object" })。 您隨時都可以提示模型產生 JSON 輸出。 不過,這類輸出不保證為有效的 JSON。

如果您想要傳遞不在所支援參數清單中的參數,您可以使用 [額外的參數] 將其傳遞至基礎模型。 請參閱 [將額外的參數傳遞至模型]

將額外的參數傳遞至模型

Azure AI 模型推斷 API 可讓您將額外的參數傳遞至模型。 下列程式碼範例示範如何將額外的參數 logprobs 傳遞至模型。

將額外的參數傳遞至 Azure AI 模型推斷 API 之前,請確定您的模型支援那些額外的參數。 對基礎模型提出要求時,會將標頭 extra-parameters 傳遞至具有 pass-through 值的模型。 這個值會告訴端點將額外的參數傳遞至模型。 搭配模型使用額外的參數,不保證模型實際上可以處理這些參數。 請參閱模型的文件,以了解支援哪些額外的參數。

requestOptions = new ChatCompletionsOptions()
{
    Messages = {
        new ChatRequestSystemMessage("You are a helpful assistant."),
        new ChatRequestUserMessage("How many languages are in the world?")
    },
    AdditionalProperties = { { "logprobs", BinaryData.FromString("true") } },
};

response = client.Complete(requestOptions, extraParams: ExtraParameters.PassThrough);
Console.WriteLine($"Response: {response.Value.Choices[0].Message.Content}");

下列額外參數可以傳遞至 Meta Llama 模型:

名稱 描述 類型
n 每個提示要產生的完成項數量。 注意:因為此參數會產生許多完成項,所以會快速消耗權杖配額。 integer
best_of 產生 best_of 完成伺服器端,並傳回「最佳」(每個權杖都具有最低對數機率的 best_of)。 結果不能串流。 搭配 n 使用時,best_of 控制待選完成項的數目,而 n 會指定傳回的數目,best_of 必須大於 n。 注意:因為此參數會產生許多完成項,所以會快速消耗權杖配額。 integer
logprobs 一個數字,指出包括最可能是權杖之 logprobs 的對數機率及所選權杖。 例如,如果 logprobs 為 10,則 API 會傳回 10 個最可能的權杖清單。 API 一律會傳回取樣權杖的 logprob,因此,回應中可能包含多達 logprobs+1 個元素。 integer
ignore_eos 是否要忽略 EOS 權杖,並在產生 EOS 權杖之後繼續產生權杖。 boolean
use_beam_search 是否要使用集束搜尋而不是取樣。 在這種情況下,best_of 必須大於 1 且 temperature 必須是 0。 boolean
stop_token_ids 產生時會停止進一步產生權杖之權杖的識別碼清單。 傳回的輸出包含停止權杖,除非停止權杖是特殊權杖。 array
skip_special_tokens 是否要在輸出中跳過特殊權杖。 boolean

套用內容安全

Azure AI 模型推斷 API 支援 Azure AI 內容安全。 當您使用已開啟 Azure AI 內容安全的部署時,輸入和輸出都會通過旨在偵測及防止有害內容輸出的一組分類模型。 內容篩選系統會偵測並針對輸入提示和輸出完成中的特定類別的潛在有害內容採取動作。

下列範例示範當模型偵測到輸入提示中的有害內容並啟用內容安全時,如何處理事件。

try
{
    requestOptions = new ChatCompletionsOptions()
    {
        Messages = {
            new ChatRequestSystemMessage("You are an AI assistant that helps people find information."),
            new ChatRequestUserMessage(
                "Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."
            ),
        },
    };

    response = client.Complete(requestOptions);
    Console.WriteLine(response.Value.Choices[0].Message.Content);
}
catch (RequestFailedException ex)
{
    if (ex.ErrorCode == "content_filter")
    {
        Console.WriteLine($"Your query has trigger Azure Content Safety: {ex.Message}");
    }
    else
    {
        throw;
    }
}

提示

若要深入了解如何設定及控制 Azure AI 內容安全設定,請參閱 Azure AI 內容安全文件

注意

Azure AI 內容安全僅適用於部署為無伺服器 API 端點的模型。

Meta Llama 聊天模型

Meta Llama 聊天模型包含下列模型:

Meta Llama 3.1 的多語系大型語言模型 (LLM) 集合是經過預先訓練和指令微調的生成式模型集合,大小有 8B、70B 和 405B (文字輸入/文字輸出)。 Llama 3.1 經過指令微調的純文字模型 (8B、70B、405B) 已針對多語系對話使用案例進行最佳化,並且在通用產業基準上優於許多可用的開放原始碼和封閉式聊天模型。

有下列模型可用:

必要條件

若要搭配 Azure AI Studio 使用 Meta Llama 模型,您需要下列必要條件:

模型部署

部署至無伺服器 API

您可以透過隨用隨付計費,將 Meta Llama 聊天模型部署至無伺服器 API 端點。 這種部署可讓您以 API 的形式取用模型,而不必在您的訂用帳戶上裝載模型,同時讓組織保持所需的企業安全性和合規性。

部署至無伺服器 API 端點不需要您訂用帳戶的配額。 如果您的模型尚未部署,請使用 Azure AI Studio、適用於 Python 的 Azure Machine Learning SDK、Azure CLI 或 ARM 範本來將模型部署為無伺服器 API (英文)。

部署至自我裝載的受控計算

Meta Llama 模型可以部署至我們自我裝載的受控推斷解決方案,其可讓您自訂和控制提供模型之方式的所有詳細資料。

若要部署至自我裝載的受控計算,您的訂用帳戶必須具有足夠的配額。 如果您沒有足夠的可用配額,您可以透過選取 [我想要使用共用配額且我了解此端點將會在 168 小時後刪除] 選項,來使用我們的臨時配額存取。

[將模型部署至受控計算]

REST 用戶端

使用 [Azure AI 模型推斷 API] 部署的模型,可以使用任何 REST 用戶端來取用。 若要使用 REST 用戶端,您需要下列先決條件:

  • 若要建構要求,您必須傳入端點 URL。 端點 URL 具有 https://your-host-name.your-azure-region.inference.ai.azure.com 形式,其中 your-host-name`` is your unique model deployment host name and your-azure-region`` 是模型部署所在的 Azure 區域 (例如 eastus2)。
  • 視您的模型部署和驗證喜好設定而定,您需要金鑰來針對服務進行驗證,或是 Microsoft Entra ID 認證。 金鑰是 32 個字元的字串。

使用聊天完成

在本節中,您會使用 [Azure AI 模型推斷 API] 搭配聊天完成模型來用於聊天。

提示

Azure AI 模型推斷 API (英文) 可讓您與在 Azure AI Studio 中部署、具有相同程式碼和結構相同的大部分模型交談,包括 Meta Llama 聊天模型。

建立用戶端以取用模型

首先,建立用戶端以取用模型。 下列程式碼會使用儲存在環境變數中的端點 URL 和金鑰。

當您將模型部署至具有 Microsoft Entra ID 支援的自我裝載線上端點時,您可以使用下列程式碼片段來建立用戶端。

注意

目前,無伺服器 API 端點不支援使用 Microsoft Entra ID 進行驗證。

取得模型的功能

/info 路由會傳回部署至端點之模型的相關資訊。 透過呼叫下列方法,以傳回模型的資訊:

GET /info HTTP/1.1
Host: <ENDPOINT_URI>
Authorization: Bearer <TOKEN>
Content-Type: application/json

回應如下:

{
    "model_name": "Meta-Llama-3.1-405B-Instruct",
    "model_type": "chat-completions",
    "model_provider_name": "Meta"
}

建立聊天完成要求

下列範例示範如何針對模型建立基本聊天完成要求。

{
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "How many languages are in the world?"
        }
    ]
}

回應如下,您可以在其中查看模型的使用量統計資料:

{
    "id": "0a1234b5de6789f01gh2i345j6789klm",
    "object": "chat.completion",
    "created": 1718726686,
    "model": "Meta-Llama-3.1-405B-Instruct",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "As of now, it's estimated that there are about 7,000 languages spoken around the world. However, this number can vary as some languages become extinct and new ones develop. It's also important to note that the number of speakers can greatly vary between languages, with some having millions of speakers and others only a few hundred.",
                "tool_calls": null
            },
            "finish_reason": "stop",
            "logprobs": null
        }
    ],
    "usage": {
        "prompt_tokens": 19,
        "total_tokens": 91,
        "completion_tokens": 72
    }
}

檢查回應中的 usage 區段,以查看提示所使用的權杖數目、產生的權杖總數,以及用於完成文字的權杖數目。

串流內容

根據預設,完成 API 會在單一回應中傳回整個產生的內容。 如果您正在產生的完成很長,則等候回應可能需要數秒鐘的時間。

您可以 [串流] 內容,以在內容產生期間取得它。 串流內容可讓您在內容變成可用時立即開始處理完成。 此模式會傳回以 [僅限資料的伺服器傳送事件] 形式將回應串流回來的物件。 從差異欄位擷取區塊,而不是訊息欄位。

{
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "How many languages are in the world?"
        }
    ],
    "stream": true,
    "temperature": 0,
    "top_p": 1,
    "max_tokens": 2048
}

您可以將串流產生內容的方式視覺化:

{
    "id": "23b54589eba14564ad8a2e6978775a39",
    "object": "chat.completion.chunk",
    "created": 1718726371,
    "model": "Meta-Llama-3.1-405B-Instruct",
    "choices": [
        {
            "index": 0,
            "delta": {
                "role": "assistant",
                "content": ""
            },
            "finish_reason": null,
            "logprobs": null
        }
    ]
}

串流中的最後一則訊息已設定 finish_reason,其會指出產生流程停止的原因。

{
    "id": "23b54589eba14564ad8a2e6978775a39",
    "object": "chat.completion.chunk",
    "created": 1718726371,
    "model": "Meta-Llama-3.1-405B-Instruct",
    "choices": [
        {
            "index": 0,
            "delta": {
                "content": ""
            },
            "finish_reason": "stop",
            "logprobs": null
        }
    ],
    "usage": {
        "prompt_tokens": 19,
        "total_tokens": 91,
        "completion_tokens": 72
    }
}

探索推斷用戶端支援的更多參數

探索您可以在推斷用戶端中指定的其他參數。 如需所有支援參數及其對應文件的完整清單,請參閱 [Azure AI 模型推斷 API 參考]

{
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "How many languages are in the world?"
        }
    ],
    "presence_penalty": 0.1,
    "frequency_penalty": 0.8,
    "max_tokens": 2048,
    "stop": ["<|endoftext|>"],
    "temperature" :0,
    "top_p": 1,
    "response_format": { "type": "text" }
}
{
    "id": "0a1234b5de6789f01gh2i345j6789klm",
    "object": "chat.completion",
    "created": 1718726686,
    "model": "Meta-Llama-3.1-405B-Instruct",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "As of now, it's estimated that there are about 7,000 languages spoken around the world. However, this number can vary as some languages become extinct and new ones develop. It's also important to note that the number of speakers can greatly vary between languages, with some having millions of speakers and others only a few hundred.",
                "tool_calls": null
            },
            "finish_reason": "stop",
            "logprobs": null
        }
    ],
    "usage": {
        "prompt_tokens": 19,
        "total_tokens": 91,
        "completion_tokens": 72
    }
}

警告

Meta Llama 模型不支援 JSON 輸出格式化 (response_format = { "type": "json_object" })。 您隨時都可以提示模型產生 JSON 輸出。 不過,這類輸出不保證為有效的 JSON。

如果您想要傳遞不在所支援參數清單中的參數,您可以使用 [額外的參數] 將其傳遞至基礎模型。 請參閱 [將額外的參數傳遞至模型]

將額外的參數傳遞至模型

Azure AI 模型推斷 API 可讓您將額外的參數傳遞至模型。 下列程式碼範例示範如何將額外的參數 logprobs 傳遞至模型。

將額外的參數傳遞至 Azure AI 模型推斷 API 之前,請確定您的模型支援那些額外的參數。 對基礎模型提出要求時,會將標頭 extra-parameters 傳遞至具有 pass-through 值的模型。 這個值會告訴端點將額外的參數傳遞至模型。 搭配模型使用額外的參數,不保證模型實際上可以處理這些參數。 請參閱模型的文件,以了解支援哪些額外的參數。

POST /chat/completions HTTP/1.1
Host: <ENDPOINT_URI>
Authorization: Bearer <TOKEN>
Content-Type: application/json
extra-parameters: pass-through
{
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "How many languages are in the world?"
        }
    ],
    "logprobs": true
}

下列額外參數可以傳遞至 Meta Llama 聊天模型:

名稱 描述 類型
n 每個提示要產生的完成項數量。 注意:因為此參數會產生許多完成項,所以會快速消耗權杖配額。 integer
best_of 產生 best_of 完成伺服器端,並傳回「最佳」(每個權杖都具有最低對數機率的 best_of)。 結果不能串流。 搭配 n 使用時,best_of 控制待選完成項的數目,而 n 會指定傳回的數目,best_of 必須大於 n。 注意:因為此參數會產生許多完成項,所以會快速消耗權杖配額。 integer
logprobs 一個數字,指出包括最可能是權杖之 logprobs 的對數機率及所選權杖。 例如,如果 logprobs 為 10,則 API 會傳回 10 個最可能的權杖清單。 API 一律會傳回取樣權杖的 logprob,因此,回應中可能包含多達 logprobs+1 個元素。 integer
ignore_eos 是否要忽略 EOS 權杖,並在產生 EOS 權杖之後繼續產生權杖。 boolean
use_beam_search 是否要使用集束搜尋而不是取樣。 在這種情況下,best_of 必須大於 1 且 temperature 必須是 0。 boolean
stop_token_ids 產生時會停止進一步產生權杖之權杖的識別碼清單。 傳回的輸出包含停止權杖,除非停止權杖是特殊權杖。 array
skip_special_tokens 是否要在輸出中跳過特殊權杖。 boolean

套用內容安全

Azure AI 模型推斷 API 支援 Azure AI 內容安全。 當您使用已開啟 Azure AI 內容安全的部署時,輸入和輸出都會通過旨在偵測及防止有害內容輸出的一組分類模型。 內容篩選系統會偵測並針對輸入提示和輸出完成中的特定類別的潛在有害內容採取動作。

下列範例示範當模型偵測到輸入提示中的有害內容並啟用內容安全時,如何處理事件。

{
    "messages": [
        {
            "role": "system",
            "content": "You are an AI assistant that helps people find information."
        },
                {
            "role": "user",
            "content": "Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."
        }
    ]
}
{
    "error": {
        "message": "The response was filtered due to the prompt triggering Microsoft's content management policy. Please modify your prompt and retry.",
        "type": null,
        "param": "prompt",
        "code": "content_filter",
        "status": 400
    }
}

提示

若要深入了解如何設定及控制 Azure AI 內容安全設定,請參閱 Azure AI 內容安全文件

注意

Azure AI 內容安全僅適用於部署為無伺服器 API 端點的模型。

更多推斷範例

如需如何使用 Meta Llama 模型的更多範例,請參閱下列範例和教學課程:

描述 語言 範例
CURL 要求 Bash 連結
適用於 JavaScript 的 Azure AI 推斷套件 JavaScript 連結
適用於 Python 的 Azure AI 推斷套件 Python 連結
Python Web 要求 Python 連結
OpenAI SDK (實驗性) Python 連結
LangChain Python 連結
LiteLLM Python 連結

部署為無伺服器 API 端點的 Meta Llama 模型的成本和配額考量

配額會根據每個部署管理。 每個部署的速率限制為每分鐘 200,000 個權杖,每分鐘 1,000 個 API 要求。 不過,我們目前限制每個專案的每個模型為一個部署。 如果目前的速率限制無法滿足您的情節,請連絡 Microsoft Azure 支援。

部署為無伺服器 API 的 Meta Llama 模型是由 Meta 透過 Azure Marketplace 提供,並與 Azure AI Studio 整合以供使用。 您可以在部署模型時找到 Azure Marketplace 價格。

每次專案訂閱來自 Azure Marketplace 的指定供應項目時,都會建立新的資源,以便追蹤與其使用量相關聯的成本。 使用相同的資源來追蹤與推斷相關聯的成本;不過,可以使用多個計量獨立追蹤每個案例。

如需如何追蹤成本的詳細資訊,請參閱監視透過 Azure Marketplace 提供的模型成本 (部分機器翻譯)。

部署至受控計算之 Meta Llama 模型的成本和配額考量

部署至受控計算的 Meta Llama 模型會根據相關聯計算執行個體的核心時數計費。 計算執行個體的成本取決於執行個體的大小、執行的執行個體數目,以及執行持續時間。

最好從少量的執行個體開始,並視需要擴大。 您可以在 Azure 入口網站中監視計算執行個體的成本。