Skip to content

Commit 775c955

Browse files
authored
feat: update autogenerated codes
feat: update autogenerated codes
2 parents a93f3b6 + ca20ebb commit 775c955

1 file changed

Lines changed: 155 additions & 55 deletions

File tree

packages/generators/src/utils/generate-code-sample.js

Lines changed: 155 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ function generateCodeSample(fetchedModels, modelName) {
1111
js: `,
1212
modalities: ['text', 'audio'],
1313
audio: { voice: 'alloy', format: 'pcm16' },`,
14+
curl: `,
15+
"modalities": ["text", "audio"],
16+
"audio": {"voice": "alloy", "format": "pcm16"}`,
17+
http: `,
18+
"modalities": ["text", "audio"],
19+
"audio": {"voice": "alloy", "format": "pcm16"}`,
1420
},
1521
textToImage: {
1622
python: `,
1723
"prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses."`,
1824
js: `,
19-
prompt: 'A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses.',`,
25+
prompt: 'A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses.',`,
26+
curl: `,
27+
"prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses."`,
28+
http: `,
29+
"prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses."`,
2030
},
2131
imageToImage: {
2232
python: `,
@@ -27,12 +37,26 @@ function generateCodeSample(fetchedModels, modelName) {
2737
: 'image'
2838
}": "https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/t-rex.png"`,
2939
js: `,
30-
prompt: "Add a crown to the T-rex's head.",
31-
${
32-
modelName.includes('image-to-image') || modelName === 'triposr'
33-
? 'image_url'
34-
: 'image'
35-
}: 'https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/t-rex.png',`,
40+
prompt: "Add a crown to the T-rex's head.",
41+
${
42+
modelName.includes('image-to-image') || modelName === 'triposr'
43+
? 'image_url'
44+
: 'image'
45+
}: 'https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/t-rex.png',`,
46+
curl: `,
47+
"prompt": "Add a crown to the T-rexs head.",
48+
"${
49+
modelName.includes('image-to-image') || modelName === 'triposr'
50+
? 'image_url'
51+
: 'image'
52+
}": "https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/t-rex.png"`,
53+
http: `,
54+
"prompt": "Add a crown to the T-rex's head.",
55+
"${
56+
modelName.includes('image-to-image') || modelName === 'triposr'
57+
? 'image_url'
58+
: 'image'
59+
}": "https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/t-rex.png"`,
3660
},
3761
};
3862
let additionalParamKey;
@@ -48,34 +72,25 @@ function generateCodeSample(fetchedModels, modelName) {
4872
{
4973
lang: 'JavaScript',
5074
source: `async function main() {
51-
try {
52-
const response = await fetch('https://api.aimlapi.com/v1/chat/completions', {
53-
method: 'POST',
54-
headers: {
55-
'Authorization': 'Bearer <YOUR_AIMLAPI_KEY>',
56-
'Content-Type': 'application/json',
57-
},
58-
body: JSON.stringify({
59-
model: '${modelName}',
60-
messages:[
61-
{
62-
role:'user',
63-
content: 'Hello'
64-
}
65-
]${additionalParamKey ? additionalParamsMap[additionalParamKey].js : ''}
66-
}),
67-
});
68-
69-
if (!response.ok) {
70-
throw new Error('HTTP error!');
71-
}
72-
73-
const data = await response.json();
74-
console.log(JSON.stringify(data, null, 2));
75+
const response = await fetch('https://api.aimlapi.com/v1/chat/completions', {
76+
method: 'POST',
77+
headers: {
78+
'Authorization': 'Bearer <YOUR_AIMLAPI_KEY>',
79+
'Content-Type': 'application/json',
80+
},
81+
body: JSON.stringify({
82+
model: '${modelName}',
83+
messages:[
84+
{
85+
role:'user',
86+
content: 'Hello'
87+
}
88+
]${additionalParamKey ? additionalParamsMap[additionalParamKey].js : ''}
89+
}),
90+
});
7591
76-
} catch (error) {
77-
console.error('Error', error);
78-
}
92+
const data = await response.json();
93+
console.log(JSON.stringify(data, null, 2));
7994
}
8095
8196
main();`,
@@ -108,6 +123,42 @@ response = requests.post(
108123
data = response.json()
109124
print(data)`,
110125
},
126+
{
127+
lang: 'cURL',
128+
source: `curl -L \\
129+
--request POST \\
130+
--url 'https://api.aimlapi.com/v1/chat/completions' \\
131+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
132+
--header 'Content-Type: application/json' \\
133+
--data '{
134+
"model": "${modelName}",
135+
"messages": [
136+
{
137+
"role": "user",
138+
"content": "hi"
139+
}
140+
]${additionalParamKey ? additionalParamsMap[additionalParamKey].curl : ''}
141+
}'`,
142+
},
143+
{
144+
lang: 'HTTP',
145+
source: `POST /v1/chat/completions HTTP/1.1
146+
Host: api.aimlapi.com
147+
Authorization: Bearer <YOUR_AIMLAPI_KEY>
148+
Content-Type: application/json
149+
Accept: */*
150+
Content-Length: 59
151+
152+
{
153+
"model": "${modelName}",
154+
"messages": [
155+
{
156+
"role": "user",
157+
"content": "hi"
158+
}
159+
]${additionalParamKey ? additionalParamsMap[additionalParamKey].http : ''}
160+
}`,
161+
},
111162
];
112163
} else if (modelName === 'openai/gpt-image-1') {
113164
return [
@@ -161,36 +212,58 @@ with open("<YOUR_IMAGE_PATH.png>", "rb") as file:
161212
data = response.json()
162213
print(data)`,
163214
},
215+
{
216+
lang: 'cURL',
217+
source: `curl -L \\
218+
--request POST \\
219+
--url 'https://api.aimlapi.com/v1/images/edits' \\
220+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
221+
--form "prompt=Add a crown to the T-rex's head." \\
222+
--form "image=@<YOUR_IMAGE_PATH.png>;type=image/png;filename=<IMAGE_NAME>"`,
223+
},
224+
{
225+
lang: 'HTTP',
226+
source: `POST /v1/images/edits HTTP/1.1
227+
Host: api.aimlapi.com
228+
Authorization: Bearer <YOUR_AIMLAPI_KEY>
229+
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
230+
231+
------WebKitFormBoundary7MA4YWxkTrZu0gW
232+
Content-Disposition: form-data; name="model"
233+
234+
${modelName}
235+
------WebKitFormBoundary7MA4YWxkTrZu0gW
236+
Content-Disposition: form-data; name="prompt"
237+
238+
Add a crown to the T-rex's head.
239+
------WebKitFormBoundary7MA4YWxkTrZu0gW
240+
Content-Disposition: form-data; name="image"; filename="<IMAGE_NAME>"
241+
Content-Type: image/png
242+
243+
(data)
244+
------WebKitFormBoundary7MA4YWxkTrZu0gW--`,
245+
},
164246
];
165247
} else if (model.category === 'image-models') {
166248
return [
167249
{
168250
lang: 'JavaScript',
169251
source: `async function main() {
170-
try {
171-
const response = await fetch('https://api.aimlapi.com/v1/images/generations', {
172-
method: 'POST',
173-
headers: {
174-
'Authorization': 'Bearer <YOUR_AIMLAPI_KEY>',
175-
'Content-Type': 'application/json',
176-
},
177-
body: JSON.stringify({
178-
model: '${modelName}'${
252+
const response = await fetch('https://api.aimlapi.com/v1/images/generations', {
253+
method: 'POST',
254+
headers: {
255+
'Authorization': 'Bearer <YOUR_AIMLAPI_KEY>',
256+
'Content-Type': 'application/json',
257+
},
258+
body: JSON.stringify({
259+
model: '${modelName}'${
179260
additionalParamKey ? additionalParamsMap[additionalParamKey].js : ''
180261
}
181-
}),
182-
});
183-
184-
if (!response.ok) {
185-
throw new Error('HTTP error!');
186-
}
187-
188-
const data = await response.json();
189-
console.log(JSON.stringify(data, null, 2));
262+
}),
263+
});
190264
191-
} catch (error) {
192-
console.error('Error', error);
193-
}
265+
const data = await response.json();
266+
console.log(JSON.stringify(data, null, 2));
194267
}
195268
196269
main();`,
@@ -217,6 +290,33 @@ response = requests.post(
217290
data = response.json()
218291
print(data)`,
219292
},
293+
{
294+
lang: 'cURL',
295+
source: `curl -L \\
296+
--request POST \\
297+
--url 'https://api.aimlapi.com/v1/images/generations' \\
298+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
299+
--header 'Content-Type: application/json' \\
300+
--data '{
301+
"model": "${modelName}"${
302+
additionalParamKey ? additionalParamsMap[additionalParamKey].curl : ''
303+
}
304+
}'`,
305+
},
306+
{
307+
lang: 'HTTP',
308+
source: `POST /v1/images/generations HTTP/1.1
309+
Host: api.aimlapi.com
310+
Authorization: Bearer <YOUR_AIMLAPI_KEY>
311+
Content-Type: application/json
312+
Accept: */*
313+
314+
{
315+
"model": "${modelName}"${
316+
additionalParamKey ? additionalParamsMap[additionalParamKey].http : ''
317+
}
318+
}`,
319+
},
220320
];
221321
}
222322
}

0 commit comments

Comments
 (0)