

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

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

Bagian ini menjelaskan parameter permintaan dan bidang respons untuk Meta Llama model. Gunakan informasi ini untuk membuat panggilan inferensi ke Meta Llama model dengan operasi [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html)dan [InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html)(streaming). Bagian ini juga mencakup contoh Python kode yang menunjukkan cara memanggil Meta Llama model. Untuk menggunakan model dalam operasi inferensi, Anda memerlukan ID model untuk model tersebut. Untuk mendapatkan ID model, lihat[Model pondasi yang didukung di Amazon Bedrock](models-supported.md). Beberapa model juga bekerja dengan [ConverseAPI](conversation-inference.md). Untuk memeriksa apakah Meta Llama model tertentu mendukung fitur, lihat [sekilas model](model-cards.md). Untuk contoh kode lainnya, lihat[Contoh kode untuk Amazon Bedrock menggunakan AWS SDK](service_code_examples.md).

Model foundation di Amazon Bedrock mendukung modalitas input dan output, yang bervariasi dari model ke model. Untuk memeriksa modalitas yang didukung Meta Llama model, lihat. [Model pondasi yang didukung di Amazon Bedrock](models-supported.md) Untuk memeriksa Amazon Bedrock mana yang memiliki fitur dukungan Meta Llama model, lihat[Model pondasi yang didukung di Amazon Bedrock](models-supported.md). Untuk memeriksa AWS Wilayah mana Meta Llama model tersedia, lihat[Model pondasi yang didukung di Amazon Bedrock](models-supported.md).

Saat Anda melakukan panggilan inferensi dengan Meta Llama model, Anda menyertakan prompt untuk model tersebut. Untuk informasi umum tentang membuat prompt untuk model yang didukung Amazon Bedrock, lihat. [Konsep rekayasa yang cepat](prompt-engineering-guidelines.md) Untuk informasi prompt Meta Llama spesifik, lihat [panduan teknik yang MetaLlama cepat](https://ai.meta.com/llama/get-started/#prompting).

**catatan**  
Llama 3.2 Instructdan Llama 3.3 Instruct model menggunakan geofencing. Ini berarti bahwa model ini tidak dapat digunakan di luar AWS Wilayah yang tersedia untuk model ini yang tercantum dalam tabel Wilayah.

Bagian ini memberikan informasi untuk menggunakan model berikut dariMeta.
+ Llama 3 Instruct
+ Llama 3.1 Instruct
+ Llama 3.2 Instruct
+ Llama 3.3 Instruct
+ Llama 4 Instruct

**Topics**
+ [Permintaan dan tanggapan](#model-parameters-meta-request-response)
+ [Contoh kode](#api-inference-examples-meta-llama)

## Permintaan dan tanggapan
<a name="model-parameters-meta-request-response"></a>

Badan permintaan diteruskan di `body` bidang permintaan ke [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html)atau [InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html).

**catatan**  
Anda tidak dapat menggunakan operasi [InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html)atau [ConverseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html)(streaming) denganLlama 4 Instruct.

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

Llama 4 InstructModel Llama 3 InstructLlama 3.1 Instruct,Llama 3.2 Instruct, dan memiliki parameter inferensi berikut: 

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

CATATAN: Llama 3.2 dan model yang lebih baru `images` menambah struktur permintaan, yang merupakan daftar string. Contoh: `images: Optional[List[str]]` 

Berikut ini adalah parameter yang diperlukan:
+  **prompt** - (Wajib) Prompt yang ingin Anda lewatkan ke model. Untuk hasil yang optimal, format percakapan dengan templat berikut.

  ```
  <|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|>
  ```

  **Contoh template dengan prompt sistem**

  Berikut ini adalah contoh prompt yang mencakup prompt sistem.

  ```
  <|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|>
  ```

  **Multi-turn contoh percakapan**

  Berikut ini adalah contoh prompt dari percakapan multi-putaran.

  ```
  <|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|>
  ```

  **Contoh template dengan prompt sistem**

  Untuk informasi selengkapnya, lihat [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).

Berikut ini adalah parameter opsional:
+ **suhu** — Gunakan nilai yang lebih rendah untuk mengurangi keacakan dalam respons.    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/id_id/bedrock/latest/userguide/model-parameters-meta.html)
+ **top\_p** — Gunakan nilai yang lebih rendah untuk mengabaikan opsi yang kurang mungkin. Setel ke 1.0 untuk menonaktifkan.    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/id_id/bedrock/latest/userguide/model-parameters-meta.html)
+ **max\_gen\_len** — Tentukan jumlah maksimum token yang akan digunakan dalam respons yang dihasilkan. Model memotong respons setelah teks yang dihasilkan melebihi. `max_gen_len`     
[See the AWS documentation website for more details](http://docs.aws.amazon.com/id_id/bedrock/latest/userguide/model-parameters-meta.html)

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

Llama 3 InstructModel mengembalikan bidang berikut untuk panggilan inferensi penyelesaian teks. 

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

Informasi lebih lanjut tentang setiap bidang disediakan di bawah ini.
+ **Generasi** - Teks yang dihasilkan.
+ **prompt\_token\_count — Jumlah** token dalam prompt.
+ **generation\_token\_count — Jumlah** token dalam teks yang dihasilkan.
+ **stop\_reason** — Alasan mengapa respon berhenti menghasilkan teks. Kemungkinan nilainya adalah:
  + **stop** — Model telah selesai menghasilkan teks untuk prompt input.
  + **panjang** — Panjang token untuk teks yang dihasilkan melebihi nilai `max_gen_len` dalam panggilan ke `InvokeModel` (`InvokeModelWithResponseStream`, jika Anda streaming output). Respons terpotong menjadi token. `max_gen_len` Pertimbangkan untuk meningkatkan nilai `max_gen_len` dan mencoba lagi.

------

## Contoh kode
<a name="api-inference-examples-meta-llama"></a>

Contoh ini menunjukkan cara memanggil *Llama 3 Instruct*model.

```
# 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)
```

Contoh ini menunjukkan cara mengontrol panjang generasi menggunakan Llama 3 Instruct model. Untuk tanggapan atau ringkasan terperinci, sesuaikan `max\_gen\_len` dan sertakan instruksi khusus dalam prompt Anda.