|
| 1 | +export const responsesSample = (options) => { |
| 2 | + const params = { |
| 3 | + model: options.name, |
| 4 | + input: 'Hello', |
| 5 | + }; |
| 6 | + const jsonBody = JSON.stringify(params, null, 2); |
| 7 | + |
| 8 | + return [ |
| 9 | + { |
| 10 | + lang: 'JavaScript', |
| 11 | + source: `async function main() { |
| 12 | + const response = await fetch('https://api.aimlapi.com/v1/responses', { |
| 13 | + method: 'POST', |
| 14 | + headers: { |
| 15 | + 'Authorization': 'Bearer <YOUR_API_KEY>', |
| 16 | + 'Content-Type': 'application/json', |
| 17 | + }, |
| 18 | + body: JSON.stringify(${jsonBody.replace(/\n/g, '\n ')}), |
| 19 | + }); |
| 20 | +
|
| 21 | + const data = await response.json(); |
| 22 | + console.log(JSON.stringify(data, null, 2)); |
| 23 | +} |
| 24 | +
|
| 25 | +main();`, |
| 26 | + }, |
| 27 | + { |
| 28 | + lang: 'Python', |
| 29 | + source: `import requests |
| 30 | +
|
| 31 | +response = requests.post( |
| 32 | + "https://api.aimlapi.com/v1/responses", |
| 33 | + headers={ |
| 34 | + "Content-Type": "application/json", |
| 35 | + "Authorization": "Bearer <YOUR_API_KEY>", |
| 36 | + }, |
| 37 | + json=${jsonBody.replace(/\n/g, '\n ')} |
| 38 | +) |
| 39 | +
|
| 40 | +data = response.json() |
| 41 | +print(data)`, |
| 42 | + }, |
| 43 | + { |
| 44 | + lang: 'cURL', |
| 45 | + source: `curl -L \\ |
| 46 | + --request POST \\ |
| 47 | + --url 'https://api.aimlapi.com/v1/responses' \\ |
| 48 | + --header 'Authorization: Bearer <YOUR_API_KEY>' \\ |
| 49 | + --header 'Content-Type: application/json' \\ |
| 50 | + --data '${jsonBody.replace(/'/g, "\\'").replace(/\n/g, '\n ')}'`, |
| 51 | + }, |
| 52 | + { |
| 53 | + lang: 'HTTP', |
| 54 | + source: `POST / HTTP/1.1 |
| 55 | +Host: test.com |
| 56 | +Authorization: Bearer <YOUR_API_KEY> |
| 57 | +Content-Type: application/json |
| 58 | +Accept: */* |
| 59 | +
|
| 60 | +${jsonBody}`, |
| 61 | + }, |
| 62 | + ]; |
| 63 | +}; |
0 commit comments