Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT SWIFT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST

AWS Amazon Titan


Amazon Titan

When it comes to Amazon Titan, the format of the prompt depends on the intended purpose. As you will recall from a previous lesson, the basic elements of a prompt are as follows:

  • Instruction: Describes what you are asking of the model, such as summarization or question answering.
  • Context: Sets the scene for the model, such as making suggestions like this one: "The following data is a medical text."
  • Input: Provides the actual input text for summaries or retrieval tasks.
  • Output indicator: Constrains the output from the model. For example, you may want the model to limit the output to a certain number of words or sentences while summarizing a passage.

Review the following best practices for using Amazon Titan.


Specify output length

Be specific about the number of sentences, bullet points, and paragraphs you want the model to generate in the output. Instead of asking for a response with a certain number of words, instruct the model to return, for example, "a summary in exactly three sentences" or "a list with four bullet points." Clearly stating these format requirements will help achieve more consistent and controlled results from Amazon Titan and other language models.


Provide simple, clear, and complete instructions

Amazon Titan generates the best responses when you include an unambiguous expectation of the task in your prompt.

U
The most common cause of color blindness is an inherited problem or variation in the functionality of one or more of the three classes of cone cells in the retina, which mediate color vision.

What is the above text about?
a) biology
b) history
c) geology
AI
a) biology

Add context to the prompt for more detailed answers

You achieve better results when you add context and provide the instruction or output indicator at the end of the prompt. The following example demonstrates this approach.

U
Use the following requirements to prepare a dessert:
  • Serving size: 10
  • Ingredients: no egg
Generate one recommendation and explain.
Include a recipe.
AI
Based on the ingredients and serving size, I recommend baking an eggless chocolate cake. Here is a recipe for eggless chocolate cake:

Ingredients:
  • 1 1/2 cups all-purpose flour
  • 1 cup granulated sugar
  • 1/2 cup unsweetened cocoa powder
  • 1 tsp baking powder
  • 1/2 tsp baking soda
  • 1/2 tsp salt
  • 1 cup milk
  • 1/2 cup vegetable oil
  • 2 tsp vanilla extract
  • 1 cup boiling water
Instructions:
  1. Preheat the oven to 350°F (175°C). Grease a 9-inch cake pan with butter or oil and dust with flour.
  2. In a large bowl, whisk together the flour, sugar, cocoa powder, baking powder, baking soda, and salt until well combined.
  3. In a separate bowl, mix together the milk, vegetable oil, and vanilla extract until well combined.
  4. Add the boiling water to the milk mixture and stir until combined.
  5. Add the wet ingredients to the dry ingredients and mix until just combined. The batter may be thin and runny.
  6. Pour the batter into the prepared cake pan and spread evenly.
  7. Bake for 30–35 minutes, or until a toothpick inserted into the center of the cake comes out clean.
  8. Remove the cake from the oven and let it cool in the pan for 10 minutes.
  9. Carefully remove the cake from the pan and let it cool completely on a wire rack.
  10. Serve and enjoy your delicious eggless chocolate cake!

Provide default output when necessary

You can provide default output for the model to present if it's unsure about how to answer.

This prevents the model from returning answers that sound correct but might not answer the question.

The following is an example.

U
Provide a proof of the Riemann hypothesis.
If you don't know a proof, respond by saying "I don't know."
AI
I don't know.

Use separator characters for API calls

For Amazon Titan models, adding \n (new line character) at the end of a prompt will likely improve the model's performance. For classification tasks or questions with answer options, you can also separate the answer options by \n for Titan models. The following example shows how newline characters between choices and at the end of a prompt help you produce the desired response with Amazon Titan.

U
Terry Whitlock was a physicist, engineer, astronomer, and inventor. Although few details of his life are known, he is regarded as one of the leading scientists of modern times.

Who was Terry Whitlock?

Choose one of the options below.
a) physicist
b) farmer
c) sailor
AI
a) physicist

Personalize responses

You can personalize responses by including a role in your prompt. This technique helps you generate personalized responses. The following example demonstrates this approach.

U
Please write an email in the voice of a friend congratulating someone on a new job.
AI
Hey [Name],

I just found out about your new job, and I'm so happy for you! Congratulations! You deserve this opportunity since you worked so hard to get it. I know you'll do great and make a positive impact on your team. I'm here to support you every step of the way. Wishing you all the best in this exciting new chapter of your life!

Cheers,
[Your Name]

Generate code

You can generate code samples, such as SQL, Python, HTML, or Java. The following example shows this capability.

U
Write a python function to download a S3 file to local disk.
AI
The following code can be used to download an s3 file to the local disk:
# Python
import boto3
# Creates a boto3 client object
s3 = boto3.client('s3')
def download_file(bucket_name, object_key, file_path):
    try:
        # Downloads the S3 file to the specified file path
        s3.download_file(bucket_name, object_key, file_path)
    except Exception as ex:
        print(ex)

# Specifies the values of bucket_name, object_key, and file_path
bucket_name = "samplebucketname"
object_key = "sampleobjectkey"
file_path = "/samplefilepath"
download_file(bucket_name, object_key, file_path)
The given code uses the download_file function to download an S3 file to the local disk. The download_file function takes the bucket name, object key, and file path as input parameters. The bucket name is the name of the S3 bucket where the file is stored, the object key is the file identifier of the file within the bucket, and the file path is the destination path on the local disk to save the file when downloaded. The function uses the download_file method of the S3 client to download the file from the specified bucket and write it to the specified file path.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.