

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Meta Llama 모델
<a name="model-parameters-meta"></a>

이 섹션에서는 Meta Llama 모델에 대한 요청 파라미터 및 응답 필드에 대해 설명합니다. 이 정보를 사용하여 [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) 및 [InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html)(스트리밍) 작업으로 Meta Llama 모델에 대한 추론 직접 호출을 수행합니다. 이 섹션에는 Meta Llama 모델을 직접 호출하는 방법을 보여주는 Python 코드 예제도 포함되어 있습니다. 추론 작업에서 모델을 사용하려면 해당 모델의 모델 ID가 필요합니다. 모델 ID를 가져오려면 [Amazon Bedrock에서 지원되는 파운데이션 모델](models-supported.md) 섹션을 참조하세요. 일부 모델은 [Converse API](conversation-inference.md)에서도 작동합니다. Converse API가 특정 Meta Llama 모델을 지원하는지 확인하려면 [지원되는 모델 및 모델 기능](conversation-inference-supported-models-features.md) 섹션을 참조하세요. 더 많은 코드 예제는 [AWS SDKs를 사용하는 Amazon Bedrock의 코드 예제](service_code_examples.md) 섹션을 참조하세요.

Amazon Bedrock의 파운데이션 모델은 모델마다 다른 입력 및 출력 양식을 지원합니다. Meta Llama 모델이 지원하는 양식을 확인하려면 [Amazon Bedrock에서 지원되는 파운데이션 모델](models-supported.md) 섹션을 참조하세요. Meta Llama 모델이 지원하는 Amazon Bedrock 기능을 확인하려면 [Amazon Bedrock에서 지원되는 파운데이션 모델](models-supported.md) 섹션을 참조하세요. Meta Llama 모델을 사용할 수 있는 AWS 리전을 확인하려면 [Amazon Bedrock에서 지원되는 파운데이션 모델](models-supported.md) 섹션을 참조하세요.

Meta Llama 모델로 추론 직접 호출을 수행할 때 모델에 대한 프롬프트를 포함해야 합니다. Amazon Bedrock이 지원하는 모델에 대한 프롬프트를 만드는 방법의 일반적인 내용은 [프롬프트 엔지니어링 개념](prompt-engineering-guidelines.md) 섹션을 참조하세요. Meta Llama 한정 프롬프트 정보는 [MetaLlama 프롬프트 엔지니어링 안내서](https://ai.meta.com/llama/get-started/#prompting)를 참조하세요.

**참고**  
Llama 3.2 Instruct 및 Llama 3.3 Instruct 모델은 지오펜싱을 사용합니다. 즉, 이러한 모델은 리전 테이블에 나열된 모델을 사용할 수 있는 AWS 리전 외부에서는 사용할 수 없습니다.

이 섹션에서는 Meta에서 다음 모델을 사용하는 방법에 대한 정보를 제공합니다.
+ Llama 3 Instruct
+ Llama 3.1 Instruct
+ Llama 3.2 Instruct
+ Llama 3.3 Instruct
+ Llama 4 Instruct

**Topics**
+ [요청 및 응답](#model-parameters-meta-request-response)
+ [예제 코드](#api-inference-examples-meta-llama)

## 요청 및 응답
<a name="model-parameters-meta-request-response"></a>

요청 본문이 [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) 또는 [InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html)에 대한 요청의 `body` 필드에 전달됩니다.

**참고**  
또한 Llama 4 Instruct를 통해 [InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html) 또는 [ConverseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html)(스트리밍) 작업을 사용할 수 없습니다.

------
#### [ Request ]

Llama 3 Instruct, Llama 3.1 Instruct, Llama 3.2 Instruct 및 Llama 4 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|>
  ```

  **시스템 프롬프트가 있는 예제 템플릿**

  자세한 내용은 [https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3](https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3) 섹션을 참조하세요.

다음 파라미터는 선택 사항입니다.
+ **temperature** - 낮은 값을 사용하면 응답의 무작위성을 줄일 수 있습니다.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/bedrock/latest/userguide/model-parameters-meta.html)
+ **top\$1p** - 낮은 값을 사용하면 확률이 낮은 옵션을 무시할 수 있습니다. 비활성화하려면 0 또는 1.0으로 설정합니다.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/bedrock/latest/userguide/model-parameters-meta.html)
+ **max\$1gen\$1len** - 생성된 응답에서 사용할 최대 토큰 수를 지정합니다. 생성된 텍스트가 `max_gen_len`을 초과하면 모델은 응답을 잘라냅니다.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/bedrock/latest/userguide/model-parameters-meta.html)

------
#### [ Response ]

Llama 3 Instruct 모델은 Text Completion 추론 직접 호출에 대해 다음 필드를 반환합니다.

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

각 필드에 대한 자세한 내용은 아래에 나와 있습니다.
+ **generation** - 생성된 텍스트입니다.
+ **prompt\$1token\$1count** - 프롬프트의 토큰 수입니다.
+ **generation\$1token\$1count** - 생성된 텍스트의 토큰 수입니다.
+ **stop\$1reason** – 응답이 텍스트 생성을 중지한 이유입니다. 가능한 값은 다음과 같습니다.
  + **중지** - 모델이 입력 프롬프트에 대한 텍스트 생성을 완료했습니다.
  + **길이** - 생성된 텍스트의 토큰 길이가 `InvokeModel`(`InvokeModelWithResponseStream`, 출력을 스트리밍하는 경우)에 대한 호출에서 `max_gen_len`의 값을 초과합니다. 응답은 `max_gen_len` 토큰 수로 잘립니다. `max_gen_len`의 값을 높인 후에 다시 시도합니다.

------

## 예제 코드
<a name="api-inference-examples-meta-llama"></a>

이 예제는 *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 리전 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)
```

이 예제에서는 Llama 3 Instruct 모델을 사용하여 생성 길이를 제어하는 방법을 보여줍니다. 자세한 응답 또는 요약을 보려면 `max\$1gen\$1len`을 조정하고 프롬프트에 특정 지침을 포함합니다.