翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
Meta Llama モデル
このセクションでは、 のリクエストパラメータとレスポンスフィールドについて説明します。Meta Llama モデル。この情報を使用して に推論呼び出しを行う Meta Llama InvokeModel および InvokeModelWithResponseStream (ストリーミング) オペレーションを使用する モデル。このセクションには、 も含まれます。Python を呼び出す方法を示すコード例 Meta Llama モデル。推論オペレーションでモデルを使用するには、そのモデルのモデル ID が必要です。モデル ID を取得するには、「Amazon Bedrock でサポートされている基盤モデル」を参照してください。一部のモデルは、 Converse API。 をチェックするには Converse API が特定の をサポート Meta Llama モデルについては、「」を参照してくださいサポートされているモデルとモデルの機能。コード例については、「AWS SDKsコード例」を参照してください。
Amazon Bedrock の基盤モデルは、モデルごとに異なる入出力モダリティをサポートしています。のモダリティを確認するには Meta Llama モデルのサポートについては、「」を参照してくださいAmazon Bedrock でサポートされている基盤モデル。がどの Amazon Bedrock で機能しているかを確認するには Meta Llama モデルのサポートについては、「」を参照してくださいAmazon Bedrock でサポートされている基盤モデル。その AWS リージョンを確認するには Meta Llama モデルは で使用できます。「」を参照してくださいAmazon Bedrock でサポートされている基盤モデル。
で推論呼び出しを行う場合 Meta Llama モデルには、モデルのプロンプトを含めます。Amazon Bedrock がサポートするモデルのプロンプト作成に関する一般情報については、「 プロンプトエンジニアリングの概念」を参照してください。[ Meta Llama 特定のプロンプト情報については、「」を参照してください。 Meta Llama プロンプトエンジニアリングガイド
注記
Llama 3.2 Instruct and Llama 3.3 Instruct モデルはジオフェンシングを使用します。つまり、これらのモデルは、「 AWS リージョン」表にリストされているこれらのモデルで使用できる リージョン以外では使用できません。
このセクションでは、 から次のモデルを使用する方法について説明します。Meta.
Llama 3 Instruct
Llama 3.1 Instruct
Llama 3.2 Instruct
Llama 3.3 Instruct
リクエストとレスポンス
リクエスト本文は、 InvokeModelまたは へのリクエストの body
フィールドで渡されますInvokeModelWithResponseStream。
サンプルのコード
この例では、 を呼び出す方法を示します。 Meta Llama 2 Chat 13B モデル。
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Shows how to generate text with Meta Llama 2 Chat (on demand). """ import json import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) def generate_text(model_id, body): """ Generate an image using Meta Llama 2 Chat on demand. Args: model_id (str): The model ID to use. body (str) : The request body to use. Returns: response (JSON): The text that the model generated, token information, and the reason the model stopped generating text. """ logger.info("Generating image with Meta Llama 2 Chat model %s", model_id) bedrock = boto3.client(service_name='bedrock-runtime') response = bedrock.invoke_model( body=body, modelId=model_id) response_body = json.loads(response.get('body').read()) return response_body def main(): """ Entrypoint for Meta Llama 2 Chat example. """ logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") model_id = "meta.llama2-13b-chat-v1" prompt = """<s>[INST] <<SYS>> You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. <</SYS>> There's a llama in my garden What should I do? [/INST]""" max_gen_len = 128 temperature = 0.1 top_p = 0.9 # Create request body. body = json.dumps({ "prompt": prompt, "max_gen_len": max_gen_len, "temperature": temperature, "top_p": top_p }) try: response = generate_text(model_id, body) print(f"Generated Text: {response['generation']}") print(f"Prompt Token count: {response['prompt_token_count']}") print(f"Generation Token count: {response['generation_token_count']}") print(f"Stop reason: {response['stop_reason']}") except ClientError as err: message = err.response["Error"]["Message"] logger.error("A client error occurred: %s", message) print("A client error occured: " + format(message)) else: print( f"Finished generating text with Meta Llama 2 Chat model {model_id}.") if __name__ == "__main__": main()