Skip to content

Commit 52d3245

Browse files
committed
add Python request conversational
1 parent 8562523 commit 52d3245

File tree

9 files changed

+116
-0
lines changed

9 files changed

+116
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def query(payload):
2+
response = requests.post(API_URL, headers=headers, json=payload)
3+
return response.json()
4+
5+
response = query({
6+
"model": "{{ providerModelId }}",
7+
{{ inputs.asJsonString }}
8+
})
9+
10+
print(response["choices"][0]["message"])
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import requests
2+
3+
API_URL = "https://router.huggingface.co/hf-inference/models/meta-llama/Llama-3.1-8B-Instruct/v1/chat/completions"
4+
headers = {"Authorization": "Bearer api_token"}
5+
6+
def query(payload):
7+
response = requests.post(API_URL, headers=headers, json=payload)
8+
return response.json()
9+
10+
response = query({
11+
"model": "meta-llama/Llama-3.1-8B-Instruct",
12+
"messages": [
13+
{
14+
"role": "user",
15+
"content": "What is the capital of France?"
16+
}
17+
],
18+
"max_tokens": 500
19+
})
20+
21+
print(response["choices"][0]["message"])
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import requests
2+
3+
API_URL = "https://api.together.xyz/v1/chat/completions"
4+
headers = {"Authorization": "Bearer api_token"}
5+
6+
def query(payload):
7+
response = requests.post(API_URL, headers=headers, json=payload)
8+
return response.json()
9+
10+
response = query({
11+
"model": "<together alias for meta-llama/Llama-3.1-8B-Instruct>",
12+
"messages": [
13+
{
14+
"role": "user",
15+
"content": "What is the capital of France?"
16+
}
17+
],
18+
"max_tokens": 500
19+
})
20+
21+
print(response["choices"][0]["message"])
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import requests
2+
3+
API_URL = "https://api.fireworks.ai/inference/v1/chat/completions"
4+
headers = {"Authorization": "Bearer api_token"}
5+
6+
def query(payload):
7+
response = requests.post(API_URL, headers=headers, json=payload)
8+
return response.json()
9+
10+
response = query({
11+
"model": "<fireworks-ai alias for meta-llama/Llama-3.2-11B-Vision-Instruct>",
12+
"messages": [
13+
{
14+
"role": "user",
15+
"content": [
16+
{
17+
"type": "text",
18+
"text": "Describe this image in one sentence."
19+
},
20+
{
21+
"type": "image_url",
22+
"image_url": {
23+
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
24+
}
25+
}
26+
]
27+
}
28+
],
29+
"max_tokens": 500
30+
})
31+
32+
print(response["choices"][0]["message"])
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import requests
2+
3+
API_URL = "https://router.huggingface.co/hf-inference/models/meta-llama/Llama-3.2-11B-Vision-Instruct/v1/chat/completions"
4+
headers = {"Authorization": "Bearer api_token"}
5+
6+
def query(payload):
7+
response = requests.post(API_URL, headers=headers, json=payload)
8+
return response.json()
9+
10+
response = query({
11+
"model": "meta-llama/Llama-3.2-11B-Vision-Instruct",
12+
"messages": [
13+
{
14+
"role": "user",
15+
"content": [
16+
{
17+
"type": "text",
18+
"text": "Describe this image in one sentence."
19+
},
20+
{
21+
"type": "image_url",
22+
"image_url": {
23+
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
24+
}
25+
}
26+
]
27+
}
28+
],
29+
"max_tokens": 500
30+
})
31+
32+
print(response["choices"][0]["message"])

0 commit comments

Comments
 (0)