選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

MetaLlama模型

焦點模式
MetaLlama模型 - Amazon Bedrock

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

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

本節說明 MetaLlama 模型的請求參數和回應欄位。使用此資訊來使用 InvokeModelInvokeModelWithResponseStream (串流) 操作對MetaLlama模型進行推論呼叫。本節也包含Python程式碼範例,示範如何呼叫MetaLlama模型。若要在推論操作中使用模型,您需要模型的模型 ID。若要取得模型 ID,請參閱 Amazon Bedrock 中支援的基礎模型。某些模型也可以使用 Converse API。若要檢查 Converse API 是否支援特定MetaLlama模型,請參閱 支援的模型和模型功能。如需更多程式碼範例,請參閱 使用 AWS SDKs Amazon Bedrock 程式碼範例

Amazon Bedrock 中的基礎模型支援輸入和輸出模態,因模型而異。若要檢查MetaLlama模型支援的模態,請參閱 Amazon Bedrock 中支援的基礎模型。若要檢查MetaLlama模型支援的 Amazon Bedrock 功能,請參閱 Amazon Bedrock 中支援的基礎模型。若要檢查哪些 AWS 區域提供MetaLlama模型,請參閱 Amazon Bedrock 中支援的基礎模型

當您使用MetaLlama模型進行推論呼叫時,您會包含模型的提示。如需為 Amazon Bedrock 支援的模型建立提示的一般資訊,請參閱 提示工程概念。如需MetaLlama特定提示資訊,請參閱MetaLlama提示工程指南

注意

Llama 3.2 Instruct 和 Llama 3.3 Instruct模型使用 geofencing。這表示這些模型不能在 AWS 區域資料表中列出的這些模型可用的區域之外使用。

本節提供從 使用以下模型的資訊Meta。

  • Llama 3 Instruct

  • Llama 3.1 Instruct

  • Llama 3.2 Instruct

  • Llama 3.3 Instruct

請求和回應

請求本文在請求 body 欄位中傳遞到 InvokeModelInvokeModelWithResponseStream

Request

Llama 3 Instruct、 Llama 3.1 Instruct和 Llama 3.2 Instruct模型具有下列推論參數。

{ "prompt": string, "temperature": float, "top_p": float, "max_gen_len": int }

注意:Llama 3.2 模型會images新增至請求結構,這是字串清單。範例:images: Optional[List[str]]

下列是必要的參數。

  • prompt – (必要) 您要傳遞給模型的提示。為了獲得最佳結果,請使用下列範本格式化對話。

    <|begin_of_text|><|start_header_id|>user<|end_header_id|> What can you help me with?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

    範例範本與系統提示

    以下是包含系統提示的範例提示。

    <|begin_of_text|><|start_header_id|>system<|end_header_id|> You are a helpful AI assistant for travel tips and recommendations<|eot_id|><|start_header_id|>user<|end_header_id|> What can you help me with?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

    多轉對話範例

    以下是多轉對話的範例提示。

    <|begin_of_text|><|start_header_id|>user<|end_header_id|> What is the capital of France?<|eot_id|><|start_header_id|>assistant<|end_header_id|> The capital of France is Paris!<|eot_id|><|start_header_id|>user<|end_header_id|> What is the weather like in Paris?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

    範例範本與系統提示

    如需更多詳細資訊,請參閱 MetaLlama 3

以下是選用參數。

  • temperature – 使用較低的值來降低回應中的隨機性。

    預設 下限 最大

    0.5

    0

    1

  • top_p – 使用較低的值來忽略可能性較低的選項。設定為 0 或 1.0 以停用。

    預設 下限 最大

    0.9

    0

    1

  • max_gen_len – 指定要在產生的回應中使用的字符數量上限。一旦產生的文字超過 max_gen_len,模型就會截斷回應。

    預設 下限 最大

    512

    1

    2048

Response

Llama 3 Instruct 模型會傳回下列欄位,以進行文字完成推論呼叫。

{ "generation": "\n\n<response>", "prompt_token_count": int, "generation_token_count": int, "stop_reason" : string }

下方提供有關每個欄位的詳細資訊。

  • generation – 產生的文字。

  • prompt_token_count – 提示中的字符數量。

  • generation_token_count – 產生的文字中的字符數量。

  • stop_reason – 回應停止產生文字的原因。可能值為:

    • stop — 模型已完成產生輸入提示的文字。

    • length — 產生文字的記號長度超出對 InvokeModel 呼叫之 max_gen_len 的值 (如果您正在串流輸出則為 InvokeModelWithResponseStream)。回應會截斷為 max_gen_len 記號。請考慮增加 max_gen_len 的值,然後再試一次。

Llama 3 Instruct、 Llama 3.1 Instruct和 Llama 3.2 Instruct模型具有下列推論參數。

{ "prompt": string, "temperature": float, "top_p": float, "max_gen_len": int }

注意:Llama 3.2 模型會images新增至請求結構,這是字串清單。範例:images: Optional[List[str]]

下列是必要的參數。

  • prompt – (必要) 您要傳遞給模型的提示。為了獲得最佳結果,請使用下列範本格式化對話。

    <|begin_of_text|><|start_header_id|>user<|end_header_id|> What can you help me with?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

    範例範本與系統提示

    以下是包含系統提示的範例提示。

    <|begin_of_text|><|start_header_id|>system<|end_header_id|> You are a helpful AI assistant for travel tips and recommendations<|eot_id|><|start_header_id|>user<|end_header_id|> What can you help me with?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

    多轉對話範例

    以下是多轉對話的範例提示。

    <|begin_of_text|><|start_header_id|>user<|end_header_id|> What is the capital of France?<|eot_id|><|start_header_id|>assistant<|end_header_id|> The capital of France is Paris!<|eot_id|><|start_header_id|>user<|end_header_id|> What is the weather like in Paris?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

    範例範本與系統提示

    如需更多詳細資訊,請參閱 MetaLlama 3

以下是選用參數。

  • temperature – 使用較低的值來降低回應中的隨機性。

    預設 下限 最大

    0.5

    0

    1

  • top_p – 使用較低的值來忽略可能性較低的選項。設定為 0 或 1.0 以停用。

    預設 下限 最大

    0.9

    0

    1

  • max_gen_len – 指定要在產生的回應中使用的字符數量上限。一旦產生的文字超過 max_gen_len,模型就會截斷回應。

    預設 下限 最大

    512

    1

    2048

範例程式碼

此範例示範如何呼叫Llama 3 Instruct模型。

# Use the native inference API to send a text message to Meta Llama 3. import boto3 import json from botocore.exceptions import ClientError # Create a Bedrock Runtime client in the AWS Region of your choice. client = boto3.client("bedrock-runtime", region_name="us-west-2") # Set the model ID, e.g., Llama 3 70b Instruct. model_id = "meta.llama3-70b-instruct-v1:0" # Define the prompt for the model. prompt = "Describe the purpose of a 'hello world' program in one line." # Embed the prompt in Llama 3's instruction format. formatted_prompt = f""" <|begin_of_text|><|start_header_id|>user<|end_header_id|> {prompt} <|eot_id|> <|start_header_id|>assistant<|end_header_id|> """ # Format the request payload using the model's native structure. native_request = { "prompt": formatted_prompt, "max_gen_len": 512, "temperature": 0.5, } # Convert the native request to JSON. request = json.dumps(native_request) try: # Invoke the model with the request. response = client.invoke_model(modelId=model_id, body=request) except (ClientError, Exception) as e: print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}") exit(1) # Decode the response body. model_response = json.loads(response["body"].read()) # Extract and print the response text. response_text = model_response["generation"] print(response_text)

下一個主題:

Mistral AI 模型

上一個主題:

Luma AI 模型
隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。