Skip to content

Commit 22c56ca

Browse files
committed
feat: update code samples
1 parent e0429b5 commit 22c56ca

8 files changed

Lines changed: 93 additions & 199 deletions

File tree

packages/generators-v2/src/code-samples/chat-completion-audio.sample.js

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
export const chatCompletionAudioSample = (options) => [
2+
{
3+
lang: 'cURL',
4+
source: `curl -L \\
5+
--request POST \\
6+
--url 'https://api.aimlapi.com/v1/chat/completions' \\
7+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
8+
--header 'Content-Type: application/json' \\
9+
--data '{
10+
"model": "${options.name}",
11+
"messages": [
12+
{
13+
"role": "user",
14+
"content": "Hello"
15+
}
16+
],
17+
"modalities": ["text", "audio"],
18+
"audio": {"voice": "alloy", "format": "pcm16"}
19+
}'`,
20+
},
221
{
322
lang: 'JavaScript',
423
source: `async function main() {
@@ -53,42 +72,4 @@ response = requests.post(
5372
data = response.json()
5473
print(data)`,
5574
},
56-
{
57-
lang: 'cURL',
58-
source: `curl -L \\
59-
--request POST \\
60-
--url 'https://api.aimlapi.com/v1/chat/completions' \\
61-
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
62-
--header 'Content-Type: application/json' \\
63-
--data '{
64-
"model": "${options.name}",
65-
"messages": [
66-
{
67-
"role": "user",
68-
"content": "Hello"
69-
}
70-
],
71-
"modalities": ["text", "audio"],
72-
"audio": {"voice": "alloy", "format": "pcm16"}
73-
}'`,
74-
},
75-
{
76-
lang: 'HTTP',
77-
source: `POST /v1/chat/completions HTTP/1.1
78-
Host: api.aimlapi.com
79-
Authorization: Bearer <YOUR_AIMLAPI_KEY>
80-
Content-Type: application/json
81-
82-
{
83-
"model": "${options.name}",
84-
"messages": [
85-
{
86-
"role": "user",
87-
"content": "Hello"
88-
}
89-
],
90-
"modalities": ["text", "audio"],
91-
"audio": {"voice": "alloy", "format": "pcm16"}
92-
}`,
93-
},
9475
];

packages/generators-v2/src/code-samples/chat-completion.sample.js

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
export const chatCompletionSample = (options) => [
2+
{
3+
lang: 'cURL',
4+
source: `curl -L \\
5+
--request POST \\
6+
--url 'https://api.aimlapi.com/v1/chat/completions' \\
7+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
8+
--header 'Content-Type: application/json' \\
9+
--data '{
10+
"model": "${options.name}",
11+
"messages": [
12+
{
13+
"role": "user",
14+
"content": "Hello"
15+
}
16+
]
17+
}'`,
18+
},
219
{
320
lang: 'JavaScript',
421
source: `async function main() {
@@ -49,38 +66,4 @@ response = requests.post(
4966
data = response.json()
5067
print(data)`,
5168
},
52-
{
53-
lang: 'cURL',
54-
source: `curl -L \\
55-
--request POST \\
56-
--url 'https://api.aimlapi.com/v1/chat/completions' \\
57-
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
58-
--header 'Content-Type: application/json' \\
59-
--data '{
60-
"model": "${options.name}",
61-
"messages": [
62-
{
63-
"role": "user",
64-
"content": "Hello"
65-
}
66-
]
67-
}'`,
68-
},
69-
{
70-
lang: 'HTTP',
71-
source: `POST /v1/chat/completions HTTP/1.1
72-
Host: api.aimlapi.com
73-
Authorization: Bearer <YOUR_AIMLAPI_KEY>
74-
Content-Type: application/json
75-
76-
{
77-
"model": "${options.name}",
78-
"messages": [
79-
{
80-
"role": "user",
81-
"content": "Hello"
82-
}
83-
]
84-
}`,
85-
},
8669
];

packages/generators-v2/src/code-samples/custom.sample.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ export const customSample = (options) => {
22
const jsonBody = JSON.stringify(options.customParams, null, 2);
33

44
return [
5+
{
6+
lang: 'cURL',
7+
source: `curl -L \\
8+
--request POST \\
9+
--url '${options.customUrlApi}' \\
10+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
11+
--header 'Content-Type: application/json' \\
12+
--data '${jsonBody.replace(/'/g, "\\'").replace(/\n/g, '\n ')}'`,
13+
},
514
{
615
lang: 'JavaScript',
716
source: `async function main() {
@@ -36,23 +45,5 @@ response = requests.post(
3645
data = response.json()
3746
print(data)`,
3847
},
39-
{
40-
lang: 'cURL',
41-
source: `curl -L \\
42-
--request POST \\
43-
--url '${options.customUrlApi}' \\
44-
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
45-
--header 'Content-Type: application/json' \\
46-
--data '${jsonBody.replace(/'/g, "\\'").replace(/\n/g, '\n ')}'`,
47-
},
48-
{
49-
lang: 'HTTP',
50-
source: `POST ${options.customUrlApi?.replace('https://api.aimlapi.com', '')} HTTP/1.1
51-
Host: api.aimlapi.com
52-
Authorization: Bearer <YOUR_AIMLAPI_KEY>
53-
Content-Type: application/json
54-
55-
${jsonBody}`,
56-
},
5748
];
5849
};

packages/generators-v2/src/code-samples/gpt-image-edit.sample.js

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
export const gptImageEditSample = (options) => [
2+
{
3+
lang: 'cURL',
4+
source: `curl -L \\
5+
--request POST \\
6+
--url 'https://api.aimlapi.com/v1/images/edits' \\
7+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
8+
--form "prompt=Add a crown to the T-rex’s head." \\
9+
--form "image=@<YOUR_IMAGE_PATH.png>;type=image/png;filename=<IMAGE_NAME>"`,
10+
},
211
{
312
lang: 'JavaScript',
413
source: `import fs from 'fs';
@@ -49,35 +58,4 @@ with open("<YOUR_IMAGE_PATH.png>", "rb") as file:
4958
data = response.json()
5059
print(data)`,
5160
},
52-
{
53-
lang: 'cURL',
54-
source: `curl -L \\
55-
--request POST \\
56-
--url 'https://api.aimlapi.com/v1/images/edits' \\
57-
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
58-
--form "prompt=Add a crown to the T-rex’s head." \\
59-
--form "image=@<YOUR_IMAGE_PATH.png>;type=image/png;filename=<IMAGE_NAME>"`,
60-
},
61-
{
62-
lang: 'HTTP',
63-
source: `POST /v1/images/edits HTTP/1.1
64-
Host: api.aimlapi.com
65-
Authorization: Bearer <YOUR_AIMLAPI_KEY>
66-
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
67-
68-
------WebKitFormBoundary7MA4YWxkTrZu0gW
69-
Content-Disposition: form-data; name="model"
70-
71-
${options.name}
72-
------WebKitFormBoundary7MA4YWxkTrZu0gW
73-
Content-Disposition: form-data; name="prompt"
74-
75-
Add a crown to the T-rex's head.
76-
------WebKitFormBoundary7MA4YWxkTrZu0gW
77-
Content-Disposition: form-data; name="image"; filename="<IMAGE_NAME>"
78-
Content-Type: image/png
79-
80-
(data)
81-
------WebKitFormBoundary7MA4YWxkTrZu0gW--`,
82-
},
8361
];

packages/generators-v2/src/code-samples/image-to-image.sample.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ export const imageToImageSample = (options, schema) => {
3333
2
3434
);
3535
return [
36+
{
37+
lang: 'cURL',
38+
source: `curl -L \\
39+
--request POST \\
40+
--url 'https://api.aimlapi.com/v1/images/generations' \\
41+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
42+
--header 'Content-Type: application/json' \\
43+
--data '${jsonBody.replace(/'/g, "\\'").replace(/\n/g, '\n ')}'`,
44+
},
3645
{
3746
lang: 'JavaScript',
3847
source: `async function main() {
@@ -67,23 +76,5 @@ response = requests.post(
6776
data = response.json()
6877
print(data)`,
6978
},
70-
{
71-
lang: 'cURL',
72-
source: `curl -L \\
73-
--request POST \\
74-
--url 'https://api.aimlapi.com/v1/images/generations' \\
75-
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
76-
--header 'Content-Type: application/json' \\
77-
--data '${jsonBody.replace(/'/g, "\\'").replace(/\n/g, '\n ')}'`,
78-
},
79-
{
80-
lang: 'HTTP',
81-
source: `POST /v1/images/generations HTTP/1.1
82-
Host: api.aimlapi.com
83-
Authorization: Bearer <YOUR_AIMLAPI_KEY>
84-
Content-Type: application/json
85-
86-
${jsonBody}`,
87-
},
8879
];
8980
};

packages/generators-v2/src/code-samples/responses.sample.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ export const responsesSample = (options) => {
66
const jsonBody = JSON.stringify(params, null, 2);
77

88
return [
9+
{
10+
lang: 'cURL',
11+
source: `curl -L \\
12+
--request POST \\
13+
--url 'https://api.aimlapi.com/v1/responses' \\
14+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
15+
--header 'Content-Type: application/json' \\
16+
--data '${jsonBody.replace(/'/g, "\\'").replace(/\n/g, '\n ')}'`,
17+
},
918
{
1019
lang: 'JavaScript',
1120
source: `async function main() {
@@ -40,23 +49,5 @@ response = requests.post(
4049
data = response.json()
4150
print(data)`,
4251
},
43-
{
44-
lang: 'cURL',
45-
source: `curl -L \\
46-
--request POST \\
47-
--url 'https://api.aimlapi.com/v1/responses' \\
48-
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
49-
--header 'Content-Type: application/json' \\
50-
--data '${jsonBody.replace(/'/g, "\\'").replace(/\n/g, '\n ')}'`,
51-
},
52-
{
53-
lang: 'HTTP',
54-
source: `POST /v1/responses HTTP/1.1
55-
Host: api.aimlapi.com
56-
Authorization: Bearer <YOUR_AIMLAPI_KEY>
57-
Content-Type: application/json
58-
59-
${jsonBody}`,
60-
},
6152
];
6253
};

packages/generators-v2/src/code-samples/text-to-image.sample.js

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
export const textToImageSample = (options) => [
2+
{
3+
lang: 'cURL',
4+
source: `curl -L \\
5+
--request POST \\
6+
--url 'https://api.aimlapi.com/v1/images/generations' \\
7+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
8+
--header 'Content-Type: application/json' \\
9+
--data '{
10+
"model": "${options.name}",
11+
"prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses."
12+
}'`,
13+
},
214
{
315
lang: 'JavaScript',
416
source: `async function main() {
@@ -39,28 +51,4 @@ response = requests.post(
3951
data = response.json()
4052
print(data)`,
4153
},
42-
{
43-
lang: 'cURL',
44-
source: `curl -L \\
45-
--request POST \\
46-
--url 'https://api.aimlapi.com/v1/images/generations' \\
47-
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
48-
--header 'Content-Type: application/json' \\
49-
--data '{
50-
"model": "${options.name}",
51-
"prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses."
52-
}'`,
53-
},
54-
{
55-
lang: 'HTTP',
56-
source: `POST /v1/images/generations HTTP/1.1
57-
Host: api.aimlapi.com
58-
Authorization: Bearer <YOUR_AIMLAPI_KEY>
59-
Content-Type: application/json
60-
61-
{
62-
"model": "${options.name}",
63-
"prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses."
64-
}`,
65-
},
6654
];

packages/generators-v2/src/code-samples/video.sample.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ export const videoSample = (options, fullSchema) => {
186186

187187
const jsonBody = JSON.stringify(params, null, 2);
188188
return [
189+
{
190+
lang: 'cURL',
191+
source: `curl -L \\
192+
--request POST \\
193+
--url 'https://api.aimlapi.com/v2/video/generations' \\
194+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
195+
--header 'Content-Type: application/json' \\
196+
--data '${jsonBody.replace(/'/g, "\\'").replace(/\n/g, '\n ')}'`,
197+
},
189198
{
190199
lang: 'JavaScript',
191200
source: `async function main() {
@@ -220,23 +229,5 @@ response = requests.post(
220229
data = response.json()
221230
print(data)`,
222231
},
223-
{
224-
lang: 'cURL',
225-
source: `curl -L \\
226-
--request POST \\
227-
--url 'https://api.aimlapi.com/v2/video/generations' \\
228-
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
229-
--header 'Content-Type: application/json' \\
230-
--data '${jsonBody.replace(/'/g, "\\'").replace(/\n/g, '\n ')}'`,
231-
},
232-
{
233-
lang: 'HTTP',
234-
source: `POST /v2/video/generations HTTP/1.1
235-
Host: api.aimlapi.com
236-
Authorization: Bearer <YOUR_AIMLAPI_KEY>
237-
Content-Type: application/json
238-
239-
${jsonBody}`,
240-
},
241232
];
242233
};

0 commit comments

Comments
 (0)