Skip to content

Commit ed6693b

Browse files
authored
feat: add responses snippets
feat: add responses snippets
2 parents 8fdef21 + 0b89ed4 commit ed6693b

7 files changed

Lines changed: 72 additions & 6 deletions

File tree

packages/generators-v2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The generator reads configuration from a JSON file named json_for-docs_generatio
5656
| **alias** | `string` || The output filename (used when saving the generated schema). |
5757
| **category** | `string` || The category under which the schema is grouped (e.g. `text-models-llm`). |
5858
| **vendor** | `string` || Model vendor name (e.g. `OpenAI`). |
59-
| **codeSamples** | `string` || Optional. Determines which predefined code samples to include. Options: <br>• `chat-completion` <br>• `chat-completion-audio` <br>• `text-to-image` <br>• `image-to-image` <br>• `gpt-image-edit` <br>• `hide` (if your want hide codeSample) <br>• `custom` (requires `customUrlApi` and `customParams`) |
59+
| **codeSamples** | `string` || Optional. Determines which predefined code samples to include. Options: <br>• `chat-completion` <br>• `chat-completion-audio` <br>• `text-to-image` <br>• `image-to-image` <br>• `gpt-image-edit` <br>• `responses` <br>• `hide` (if your want hide codeSample) <br>• `custom` (requires `customUrlApi` and `customParams`) |
6060
| **customUrlApi** | `string` || Used when `codeSamples` is set to `"custom"`. Specifies a custom API endpoint. |
6161
| **customParams** | `object` || Custom parameters for the API request. Supports simple, object, array, and object-array formats. |
6262
| **hideTryItPanel** | `boolean` || If set to true, hides the “Try It” panel in the generated documentation. Useful for endpoints that are not meant to be interactive. |

packages/generators-v2/README_ru.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ npm run generate --prefix packages/generators-v2
5858
| **alias** | `string` || Имя выходного файла (используется при сохранении сгенерированной схемы). |
5959
| **category** | `string` || Категория, к которой относится схема (например, `text-models-llm`). |
6060
| **vendor** | `string` || Название поставщика модели (например, `OpenAI`). |
61-
| **codeSamples** | `string` || Необязательное поле. Определяет, какие предустановленные примеры кода будут добавлены. Возможные значения: <br>• `chat-completion` <br>• `chat-completion-audio` <br>• `text-to-image` <br>• `image-to-image` <br>• `gpt-image-edit` <br>• `hide` (если нужно скрыть пример кода) <br>• `custom` (требует указания `customUrlApi` и `customParams`) |
61+
| **codeSamples** | `string` || Необязательное поле. Определяет, какие предустановленные примеры кода будут добавлены. Возможные значения: <br>• `chat-completion` <br>• `chat-completion-audio` <br>• `text-to-image` <br>• `image-to-image` <br>• `gpt-image-edit` <br>• `responses` <br>• `hide` (если нужно скрыть пример кода) <br>• `custom` (требует указания `customUrlApi` и `customParams`) |
6262
| **customUrlApi** | `string` || Используется, если codeSamples имеет значение `"custom"`. Указывает кастомный API endpoint. |
6363
| **customParams** | `object` || Кастомные параметры для запроса к API. Поддерживаются простые значения, объекты, массивы и массивы объектов. |
6464
| **hideTryItPanel** | `boolean` || Если установлено в `true`, скрывает панель “Try It” в сгенерированной документации. Полезно для эндпоинтов, которые не предназначены для интерактивного использования. |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ print(data)`,
6565
"messages": [
6666
{
6767
"role": "user",
68-
"content": "hi"
68+
"content": "Hello"
6969
}
7070
],
7171
"modalities": ["text", "audio"],
@@ -86,7 +86,7 @@ Content-Length: 59
8686
"messages": [
8787
{
8888
"role": "user",
89-
"content": "hi"
89+
"content": "Hello"
9090
}
9191
],
9292
"modalities": ["text", "audio"],

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ print(data)`,
6161
"messages": [
6262
{
6363
"role": "user",
64-
"content": "hi"
64+
"content": "Hello"
6565
}
6666
]
6767
}'`,
@@ -80,7 +80,7 @@ Content-Length: 59
8080
"messages": [
8181
{
8282
"role": "user",
83-
"content": "hi"
83+
"content": "Hello"
8484
}
8585
]
8686
}`,

packages/generators-v2/src/code-samples/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './text-to-image.sample.js';
44
export * from './image-to-image.sample.js';
55
export * from './gpt-image-edit.sample.js';
66
export * from './custom.sample.js';
7+
export * from './responses.sample.js'
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
};

packages/generators-v2/src/transformer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export function transformSchema(schema, options) {
4444
codeSample = codeSamples.imageToImageSample(options, schema);
4545
} else if (options.codeSamples === 'gpt-image-edit') {
4646
codeSample = codeSamples.gptImageEditSample(options);
47+
} else if (options.codeSamples === 'responses') {
48+
codeSample = codeSamples.responsesSample(options);
4749
} else if (options.codeSamples === 'custom' && options.customParams) {
4850
codeSample = codeSamples.customSample(options);
4951
}

0 commit comments

Comments
 (0)