Skip to content

Commit 37084d2

Browse files
committed
Update pxt.json, python/hai2025/wood1_test.md
1 parent 2ac7861 commit 37084d2

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

pxt.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@
119119
"blocks/hai2025/protection2.md",
120120
"blocks/hai2025/comfort1.md",
121121
"blocks/hai2025/comfort2.md",
122-
"blocks/hai2025/allcontrols.md"
122+
"blocks/hai2025/allcontrols.md",
123+
"python/hai2025/wood1_test.md"
123124
],
124125
"testFiles": [],
125126
"targetVersions": {

python/hai2025/wood1_test.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
### @flyoutOnly true
2+
### @hideIteration true
3+
### @explicitHints true
4+
5+
# Classifying Materials
6+
7+
## Step 1
8+
Before we're able to train the agent's AI, we'll need to learn how to access its Application Programming Interface (API). The first step is to define the API's endpoint (what part of the API you're accessing) and authentication parameters
9+
10+
```python
11+
api_url = 'minecraft://agent.ai/'
12+
api_endpoint = 'classify'
13+
api_key = "dsf3sSFssf42"
14+
```
15+
16+
## Step 2
17+
Now that we've defined the API's endpoint we want to use, we'll want to write a function that takes an input and sends it to the API endpoint.
18+
19+
```python
20+
def make_classify_api_request(resource, data):
21+
client = MinecraftAI(
22+
url = api_url,
23+
endpoint= api_endpoint,
24+
key = api_key
25+
)
26+
27+
try:
28+
response = client.chat.completions.create(
29+
messages=[
30+
{resource : data}
31+
]
32+
)
33+
ai_message = response.content
34+
print("AI Response")
35+
print(ai_message)
36+
37+
except Exception as e:
38+
print("An error occurred: {e}")
39+
40+
```
41+
42+
## Step 3
43+
Now we need to call the function when the code is run.
44+
45+
```python
46+
make_classify_api_request("oak log","wood")
47+
```
48+
49+
## Step 4
50+
When we put it all together it looks like this
51+
52+
```python
53+
api_url = 'minecraft://agent.ai/'
54+
api_endpoint = 'classify'
55+
api_key = "dsf3sSFssf42"
56+
57+
def make_classify_api_request(resource, data):
58+
client = MinecraftAI(
59+
url = api_url,
60+
endpoint= api_endpoint,
61+
key = api_key
62+
)
63+
64+
try:
65+
response = client.chat.completions.create(
66+
messages=[
67+
{resource : data}
68+
]
69+
)
70+
ai_message = response.content
71+
print("AI Response")
72+
print(ai_message)
73+
74+
except Exception as e:
75+
print("An error occurred: {e}")
76+
77+
make_classify_api_request("oak log","wood")
78+
```

0 commit comments

Comments
 (0)