Skip to content

Commit bdbdc3c

Browse files
authored
feat: add code samples for video
feat: add code samples for video
2 parents ed9edb9 + 8194711 commit bdbdc3c

5 files changed

Lines changed: 237 additions & 13 deletions

File tree

packages/generators-v2/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ The generator reads configuration from a JSON file named json_for-docs_generatio
4949

5050
### Field Descriptions
5151

52-
| Field | Type | Required | Description |
53-
| ------------------ | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54-
| **name** | `string` | | Model name (required if using a ready-made code sample). |
55-
| **url** | `string` | | URL to the JSON documentation endpoint. |
56-
| **alias** | `string` | | The output filename (used when saving the generated schema). |
57-
| **category** | `string` | | The category under which the schema is grouped (e.g. `text-models-llm`). |
58-
| **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>• `responses` <br>• `hide` (if your want hide codeSample) <br>• `custom` (requires `customUrlApi` and `customParams`) |
52+
| Field | Type | Required | Description |
53+
| --------- | -------- | --------- | ------------- |
54+
| **name** | `string` || Model name (required if using a ready-made code sample).|
55+
| **url** | `string` || URL to the JSON documentation endpoint. |
56+
| **alias** | `string` || The output filename (used when saving the generated schema).|
57+
| **category** | `string` || The category under which the schema is grouped (e.g. `text-models-llm`).|
58+
| **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>• `image-models:prompt` <br>• `image-models:image_url` <br>• `image-models:image` <br>• `video:video` <br>• `video:lipsync` <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>• `responses` <br>• `hide` (если нужно скрыть пример кода) <br>• `custom` (требует указания `customUrlApi` и `customParams`) |
61+
| **codeSamples** | `string` || Необязательное поле. Определяет, какие предустановленные примеры кода будут добавлены. Возможные значения: <br>• `chat-completion` <br>• `chat-completion-audio` <br>• `image-models:prompt` <br>• `image-models:image_url` <br>• `image-models:image` <br>• `video:video` <br>• `video:lipsync` <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/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ 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'
7+
export * from './responses.sample.js';
8+
export * from './video.sample.js';
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
export const videoSample = (options, fullSchema) => {
2+
const params = {
3+
model: options.name,
4+
};
5+
const schema =
6+
fullSchema?.paths?.['/v2/video/generations']?.post?.requestBody?.content?.[
7+
'application/json'
8+
]?.schema;
9+
const requiredModelParams = schema?.required || [];
10+
const lengthRequiredParams = requiredModelParams?.length;
11+
12+
if (options.name?.includes('pixverse/lip-sync')) {
13+
Object.assign(params, {
14+
video_url:
15+
'https://storage.googleapis.com/falserverless/model_tests/kling/kling-v2.5-turbo-pro-text-to-video-output.mp4',
16+
lip_sync_tts_content: 'Hello World!',
17+
lip_sync_tts_speaker: 'Harper',
18+
});
19+
} else if (
20+
(options.name?.includes('transition') &&
21+
options.name?.includes('pixverse')) ||
22+
options.name?.includes('gen3a_turbo')
23+
) {
24+
Object.assign(params, {
25+
prompt:
26+
'The camera moves down, dives underwater and moves through a dark, moody world of greenish light and drifting plants. Giant white koi fish emerge from the shadows and turn curiously toward the camera as it passes, their scales shimmering faintly in the murky depths.',
27+
image_url:
28+
'https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/landscape.jpg',
29+
tail_image_url: 'https://cdn.aimlapi.com/assets/content/white-fish.png',
30+
});
31+
} else if (
32+
requiredModelParams?.includes('video_url') &&
33+
requiredModelParams?.includes('image_url') &&
34+
lengthRequiredParams === 3
35+
) {
36+
Object.assign(params, {
37+
video_url:
38+
'https://storage.googleapis.com/falserverless/example_inputs/wan_animate_input_video.mp4',
39+
image_url:
40+
'https://s2-111386.kwimgs.com/bs2/mmu-aiplatform-temp/kling/20240620/1.jpeg',
41+
});
42+
} else if (
43+
requiredModelParams?.includes('video_url') &&
44+
Boolean(schema?.properties?.prompt)
45+
) {
46+
Object.assign(params, {
47+
video_url:
48+
'https://zovi0.github.io/public_misc/kling-v2-master-t2v-racoon.mp4',
49+
prompt:
50+
'Add a small fairy as a rider on the raccoon’s back. She must have a black-and-golden face and a cloak in the colors of a dark emerald tropical butterfly with bright blue shimmering spots.',
51+
});
52+
} else if (
53+
requiredModelParams?.includes('character') &&
54+
requiredModelParams?.includes('reference')
55+
) {
56+
Object.assign(params, {
57+
character: {
58+
type: 'image',
59+
url: 'https://fs.tonkosti.ru/33/ol/33olc2eyzj6s4w8ksg8kkc0gg.jpg',
60+
},
61+
reference: {
62+
type: 'video',
63+
url: 'https://videos.pexels.com/video-files/3044160/3044160-uhd_2560_1440_24fps.mp4',
64+
},
65+
});
66+
} else if (
67+
requiredModelParams?.includes('effect_scene') &&
68+
requiredModelParams?.includes('image_url')
69+
) {
70+
Object.assign(params, {
71+
image_url: [
72+
'https://images.pexels.com/photos/733872/pexels-photo-733872.jpeg',
73+
'https://storage.googleapis.com/falserverless/juggernaut_examples/QEW5VrzccxGva7mPfEXjf.png',
74+
],
75+
effect_scene: 'heart_gesture',
76+
});
77+
} else if (
78+
requiredModelParams.includes('image_url') &&
79+
requiredModelParams.includes('audio_url') &&
80+
lengthRequiredParams === 3
81+
) {
82+
Object.assign(params, {
83+
image_url:
84+
'https://s2-111386.kwimgs.com/bs2/mmu-aiplatform-temp/kling/20240620/1.jpeg',
85+
audio_url:
86+
'https://storage.googleapis.com/falserverless/example_inputs/omnihuman_audio.mp3',
87+
});
88+
} else if (
89+
requiredModelParams.includes('image_url') &&
90+
requiredModelParams.includes('last_image_url') &&
91+
requiredModelParams.includes('prompt')
92+
) {
93+
Object.assign(params, {
94+
prompt: options.codeSamples.includes('lipsync')
95+
? "A woman looks into the camera, breathes in, then exclaims energetically, 'Hello world!'"
96+
: 'A woman looks into the camera and puts on a hat.',
97+
image_url:
98+
'https://storage.googleapis.com/falserverless/example_inputs/veo31-flf2v-input-1.jpeg',
99+
last_image_url:
100+
'https://storage.googleapis.com/falserverless/example_inputs/veo31-flf2v-input-2.jpeg',
101+
});
102+
} else if (
103+
requiredModelParams.includes('image_url') &&
104+
requiredModelParams.includes('tail_image_url') &&
105+
requiredModelParams.includes('prompt')
106+
) {
107+
Object.assign(params, {
108+
prompt: options.codeSamples.includes('lipsync')
109+
? "A woman looks into the camera, breathes in, then exclaims energetically, 'Hello world!'"
110+
: 'A woman looks into the camera and puts on a hat.',
111+
image_url:
112+
'https://storage.googleapis.com/falserverless/example_inputs/veo31-flf2v-input-1.jpeg',
113+
tail_image_url:
114+
'https://storage.googleapis.com/falserverless/example_inputs/veo31-flf2v-input-2.jpeg',
115+
});
116+
} else if (
117+
requiredModelParams.includes('image_urls') &&
118+
requiredModelParams.includes('prompt')
119+
) {
120+
Object.assign(params, {
121+
prompt:
122+
'A graceful ballerina dancing outside a circus tent on green grass, with colorful wildflowers swaying around her as she twirls and poses in the meadow.',
123+
image_urls: [
124+
'https://storage.googleapis.com/falserverless/example_inputs/veo31-r2v-input-1.png',
125+
'https://storage.googleapis.com/falserverless/example_inputs/veo31-r2v-input-2.png',
126+
'https://storage.googleapis.com/falserverless/example_inputs/veo31-r2v-input-3.png',
127+
],
128+
});
129+
} else if (
130+
requiredModelParams.includes('image_list') &&
131+
lengthRequiredParams === 2
132+
) {
133+
Object.assign(params, {
134+
image_list: [
135+
'https://storage.googleapis.com/falserverless/example_inputs/veo31-r2v-input-1.png',
136+
'https://storage.googleapis.com/falserverless/example_inputs/veo31-r2v-input-2.png',
137+
'https://storage.googleapis.com/falserverless/example_inputs/veo31-r2v-input-3.png',
138+
],
139+
});
140+
} else if (
141+
requiredModelParams.includes('image_url') &&
142+
Boolean(schema?.properties?.prompt)
143+
) {
144+
Object.assign(params, {
145+
prompt: options.codeSamples.includes('lipsync')
146+
? "A woman looks into the camera, breathes in, then exclaims energetically, 'Hello world!'"
147+
: 'Mona Lisa puts on glasses with her hands.',
148+
image_url:
149+
'https://s2-111386.kwimgs.com/bs2/mmu-aiplatform-temp/kling/20240620/1.jpeg',
150+
});
151+
} else if (
152+
lengthRequiredParams === 2 &&
153+
requiredModelParams.includes('prompt')
154+
) {
155+
Object.assign(params, {
156+
prompt: options.codeSamples.includes('lipsync')
157+
? 'A racoon is happily eating an ice cream. Suddenly, he pauses, looks directly into the camera, and says with full confidence: "Hello, two-legged!" His lip movements perfectly match the speech. Then, in a strong Irish accent, he adds: "Wanna some?" — while extending the half-eaten ice cream toward the camera.'
158+
: "A menacing evil dragon appears in a distance above the tallest mountain, then rushes toward the camera with its jaws open, revealing massive fangs. We see it's coming.",
159+
});
160+
} else {
161+
console.error(`Unable to generate code sample for model ${options.name}`);
162+
return;
163+
}
164+
165+
const jsonBody = JSON.stringify(params, null, 2);
166+
return [
167+
{
168+
lang: 'JavaScript',
169+
source: `async function main() {
170+
const response = await fetch('https://api.aimlapi.com/v2/video/generations', {
171+
method: 'POST',
172+
headers: {
173+
'Authorization': 'Bearer <YOUR_AIMLAPI_KEY>',
174+
'Content-Type': 'application/json',
175+
},
176+
body: JSON.stringify(${jsonBody.replace(/\n/g, '\n ')}),
177+
});
178+
179+
const data = await response.json();
180+
console.log(JSON.stringify(data, null, 2));
181+
}
182+
183+
main();`,
184+
},
185+
{
186+
lang: 'Python',
187+
source: `import requests
188+
189+
response = requests.post(
190+
"https://api.aimlapi.com/v2/video/generations",
191+
headers={
192+
"Content-Type": "application/json",
193+
"Authorization": "Bearer <YOUR_AIMLAPI_KEY>",
194+
},
195+
json=${jsonBody.replace(/\n/g, '\n ')}
196+
)
197+
198+
data = response.json()
199+
print(data)`,
200+
},
201+
{
202+
lang: 'cURL',
203+
source: `curl -L \\
204+
--request POST \\
205+
--url 'https://api.aimlapi.com/v2/video/generations' \\
206+
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \\
207+
--header 'Content-Type: application/json' \\
208+
--data '${jsonBody.replace(/'/g, "\\'").replace(/\n/g, '\n ')}'`,
209+
},
210+
{
211+
lang: 'HTTP',
212+
source: `POST / HTTP/1.1
213+
Host: test.com
214+
Authorization: Bearer <YOUR_AIMLAPI_KEY>
215+
Content-Type: application/json
216+
Accept: */*
217+
218+
${jsonBody}`,
219+
},
220+
];
221+
};

packages/generators-v2/src/transformer.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ export function transformSchema(schema, options) {
3939
codeSample = codeSamples.chatCompletionSample(options);
4040
} else if (options.codeSamples === 'chat-completion-audio') {
4141
codeSample = codeSamples.chatCompletionAudioSample(options);
42-
} else if (options.codeSamples === 'text-to-image') {
42+
} else if (options.codeSamples === 'image-models:prompt') {
4343
codeSample = codeSamples.textToImageSample(options);
44-
} else if (options.codeSamples === 'image-to-image') {
44+
} else if (options.codeSamples === 'image-models:image_url') {
4545
codeSample = codeSamples.imageToImageSample(options, schema);
46-
} else if (options.codeSamples === 'gpt-image-edit') {
46+
} else if (options.codeSamples === 'image-models:image') {
4747
codeSample = codeSamples.gptImageEditSample(options);
4848
} else if (options.codeSamples === 'responses') {
4949
codeSample = codeSamples.responsesSample(options);
50+
} else if (options.codeSamples.includes('video')) {
51+
codeSample = codeSamples.videoSample(options, schema);
5052
} else if (options.codeSamples === 'custom' && options.customParams) {
5153
codeSample = codeSamples.customSample(options);
5254
}

0 commit comments

Comments
 (0)