logo
Menu
Play Minecraft with an AI! | S03 E05 | Build On Generative AI

Play Minecraft with an AI! | S03 E05 | Build On Generative AI

Let's discover how you can play Minecraft with a bot controlled by an AI!

Tiffany Souterre
Amazon Employee
Published Mar 4, 2024
In this episode Tiffany Souterre is showing us how to connect Claude to a bot through the Bedrock API. We first discover the Mineflayer library which allows you to create a bot inside the game. We can interact with the bot through a chat window.
A bot in Minecraft
Then we see how to connect the bot to Bedrock through with the SDK for python (Boto3).
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
33
34
35
36
def invoke_claude(self, prompt):
"""
Invokes the Anthropic Claude 2 model to run an inference using the input
provided in the request body.

:param prompt: The prompt that you want Claude to complete.
:return: Inference response from the model.
"""


try:
# The different model providers have individual request and response formats.
# For the format, ranges, and default values for Anthropic Claude, refer to:
# https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html

# Claude requires you to enclose the prompt as follows:
enclosed_prompt = "Human: " + prompt + "\n\nAssistant:"

body = {
"prompt": enclosed_prompt,
"max_tokens_to_sample": 200,
"temperature": 0.5,
"stop_sequences": ["\n\nHuman:"],
}

response = self.bedrock_runtime_client.invoke_model(
modelId="anthropic.claude-v2", body=json.dumps(body)
)

response_body = json.loads(response["body"].read())
completion = response_body["completion"]

return completion

except ClientError:
logger.error("Couldn't invoke Anthropic Claude")
raise
Now whenever we talk to the bot through the chat, the message is sent to Claude via Bedrock and sends the response back.
With a little prompt engineering, it is possible to not just make it answer something but also make it act upon what you say in the chat.
In following episodes we'll see how we can use prompt engineering to make more than just having a conversation with the bot. Stay tuned!
Check out the recording here:
Loading...

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.