|
| 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 | +}; |
0 commit comments