Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

AWS Logo
Menu

Get Started with Claude 3 Opus on Amazon Bedrock Quickly through real-world Use Cases

Utilize Claude 3 Opus on Amazon Bedrock to develop a web game in an HTML (Sample code provided)

Published May 2, 2024
AWS announced the availability of Anthropic’s Claude 3 Opus, the most advanced and intelligent model in the Claude 3 Family, on Amazon Bedrock. Do you know how to get started with Opus quickly through a real-world use case?
1️⃣ Explore Prompt Examples for Various AI Model Providers
You can use the prompt examples provided by Amazon Bedrock on the service homepage to learn, build and practice the examples specific to Claude 3 Opus. You also can try totally 49 different examples covering the models from Amazon Titan、Anthropic Claude、AI21、Cohere、Meta Llama、Mistral AI、Stability AI. You can check all supported foundation models in Amazon Bedrock at https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html?icmpid=docs_bedrock_help_panel_examples
2️⃣ Opus-related examples on Amazon Bedrock
Bedrock currently offers three Opus-related examples, including analyzing a quarterly report, building a website, and creating a side-scrolling game. Each example provides the sampled API syntax, example prompt, the expected response, and inference configuration parameter settings. You can implement them in your code easily to seamlessly integrate Amazon Bedrock with your cloud service and business.
3️⃣ Hands-on demos: Utilize Opus to develop a web game in an HTML
I have used the Opus example "creating a side-scrolling game" to develop a web game in an HTML file using the Message API (Shown in the below screenshot), and the game is quite impressive and interesting!

 You can use my following sample code to create the web game yourself. let's get it!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import boto3
import json
import re

# Define the prompt
prompt = "[{\"type\":\"text\",\"text\":\"Write me a fully complete web app as a single HTML file. The app should contain a simple side-scrolling game where I use WASD to move around. When moving around the world, occasionally the character/sprite will encounter words. When a word is encountered, the player must correctly type the word as fast as possible.The faster the word is successfully typed, the more point the player gets. We should have a counter in the top-right to keep track of points. Words should be random and highly variable to keep the game interesting. \\n\\nYou should make the website very aesthetic and use Tailwind.\"}]"

# Initialize the Bedrock client
bedrock = boto3.client(service_name="bedrock-runtime",region_name="us-west-2")

#Define Claude 3 Message API
body = json.dumps({
"max_tokens": 4096,
"messages": [{"role": "user", "content": prompt}],
"anthropic_version": "bedrock-2023-05-31"
})

#Invoke Claude 3 Opus on the Amazon Bendrcok
response = bedrock.invoke_model(contentType="application/json", body=body, modelId="anthropic.claude-3-opus-20240229-v1:0")

#Extract API Response
response_body = json.loads(response.get("body").read())
content = response_body.get("content")[0].get('text', '')

#Get the HTML code from the response
pattern = r'```html(.*?)```'
match = re.search(pattern, content, re.DOTALL)
content_html = match.group(1).strip()

# Write the code into game.html
with open('game.html', 'w') as file:
file.write(content_html)
 

Comments

Log in to comment