Node-Packages / replicate.yaml
mypiper's picture
Update replicate.yaml
2fb6354 verified
_id: replicate
author: Anton Breslavskii | https://github.com/breslavsky
description: Provides features to use AI models from Replicate AI
title: Replicate AI
url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/replicate.yaml
version: 7
nodes:
generate_on_flux_replicate:
_id: generate_on_flux_replicate
arrange:
x: 300
y: 120
category:
_id: generate_images
title: en=Generate images;ru=Генерация изображений
environment:
REPLICATE_TOKEN:
title: Replicate token
description: Go to [Replicate](https://replicate.com/account/api-tokens) to take a keys
type: string
scope: global
inputs:
prompt:
order: 1
title: en=Prompt;ru=Подсказка
type: string
required: true
multiline: true
default: walking cat at the moon
imagesCount:
order: 2
title: en=Images count;ru=Кол-во
type: integer
required: true
min: 1
max: 4
step: 1
default: 1
aspectRatio:
order: 3
title: en=Aspect ratio;ru=Размер
type: string
default: 1:1
enum:
- 1:1
- 21:9
- 16:9
- 3:2
- 2:3
- 4:5
- 5:4
- 3:4
- 4:3
- 9:21
- 9:16
outputs:
images:
title: Images
type: image[]
image1:
title: Image 1
type: image
image2:
title: Image 2
type: image
image3:
title: Image 3
type: image
image4:
title: Image 4
type: image
package: replicate
script: |
export async function run({ inputs, state }) {
const { RepeatNode, NextNode, FatalError } = DEFINITIONS;
const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
if (!REPLICATE_TOKEN) {
throw new FatalError('Please, set your API token for Replicate AI');
}
const { prompt, imagesCount, aspectRatio } = inputs;
if (!state) {
const { data: { id: task } } = await httpClient({
method: 'post',
url: 'https://api.replicate.com/v1/models/black-forest-labs/flux-schnell/predictions',
data: {
input: {
prompt,
num_outputs: imagesCount,
aspect_ratio: aspectRatio
}
},
headers: {
'Authorization': `Bearer ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json',
'Prefer': 'wait',
}
});
return RepeatNode.from({ state: { task }, delay: 2000 });
} else {
const { task } = state;
const { data } = await httpClient({
method: 'get',
url: `https://api.replicate.com/v1/predictions/${task}`,
headers: {
'Authorization': `Bearer ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
}
});
const { status, error } = data;
switch (status) {
case 'processing':
return RepeatNode.from({ state: { task }, delay: 3000 });
case 'failed':
error.fatal(error);
case 'succeeded':
const { output: images } = data;
const [image1, image2, image3, image4] = images;
return NextNode.from({ outputs: { images, image1, image2, image3, image4 } });
}
}
}
source: catalog
title: en=Generate on Flux;ru=Генерация Flux
version: 5
execution: regular
kling_1_6_replicate:
_id: kling_1_6_replicate
arrange:
x: 460
y: 330
category:
_id: generate_videos
title: en=Generate video;ru=Генерация видео
environment:
REPLICATE_TOKEN:
title: Replicate token
description: Go to [Replicate](https://replicate.com/account/api-tokens) to get API key
type: string
scope: global
execution: regular
inputs:
image:
order: 1
title: en=Image;ru=Изображение
type: image
required: true
prompt:
order: 2
title: en=Prompt;ru=Подсказка
type: string
required: true
multiline: true
negativePrompt:
order: 3
title: en=Negative prompt;ru=Негативная подсказка
type: string
multiline: true
aspectRatio:
order: 4
title: en=Aspect ratio;ru=Соотношение сторон
type: string
default: 16:9
enum:
- 1:1
- 16:9
- 9:16
cfgScale:
order: 5
title: en=Creativity (CFG scale);ru=Креативность (CFG)
type: float
min: 0
max: 1
step: 0.1
default: 0.5
duration:
order: 6
title: en=Duration;ru=Длина
type: integer
min: 5
max: 10
step: 5
default: 5
outputs:
video:
title: en=Video;ru=Видео
type: video
package: replicate
script: |
export async function costs({ inputs }) {
const duration = Number(inputs?.duration || 5);
return Number((duration * 0.05).toFixed(3));
}
const MAX_RETRIES = 100;
export async function run({ inputs, state }) {
const { RepeatNode, NextNode, FatalError } = DEFINITIONS;
const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
if (!REPLICATE_TOKEN) {
throw new FatalError('Please, set your API token for Replicate AI');
}
const { image, prompt, negativePrompt, aspectRatio, cfgScale, duration } = inputs;
if (!state) {
const { data: { id: task } } = await httpClient({
method: 'post',
url: 'https://api.replicate.com/v1/models/kwaivgi/kling-v1.6-standard/predictions',
data: {
input: {
start_image: image,
prompt,
negative_prompt: negativePrompt,
aspect_ratio: aspectRatio,
cfg_scale: cfgScale,
duration
}
},
headers: {
'Authorization': `Bearer ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
}
});
return RepeatNode.from({
state: {
task,
retries: 0
},
delay: 10000
});
} else {
const { task, retries } = state;
const { data } = await httpClient({
method: 'get',
url: `https://api.replicate.com/v1/predictions/${task}`,
headers: {
'Authorization': `Bearer ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
}
});
const { status, error } = data;
switch (status) {
case 'starting':
case 'processing':
if (state.retries > MAX_RETRIES) {
throw new FatalError('Generation timeout exceeded');
}
return RepeatNode.from({
state: {
...state,
retries: retries + 1
},
progress: {
total: MAX_RETRIES,
processed: retries
},
delay: 5000
});
case 'failed':
throw new FatalError(error || 'Generation failed');
case 'succeeded':
const { output: video } = data;
return NextNode.from({ outputs: { video }, costs: await costs({ inputs }) });
default:
throw new FatalError(`Unknown status: ${status}`);
}
}
}
source: catalog
title: en=Generate video Kling 1.6;ru=Генерация видео Kling 1.6
version: 1
florence_vision_replicate:
_id: florence_vision_replicate
arrange:
x: 140
y: 80
category:
_id: computer_vision
title: Computer vision
environment:
REPLICATE_TOKEN:
title: Replicate token
description: Get your token from https://replicate.com/account/api-tokens
type: string
scope: global
execution: regular
inputs:
image:
order: 1
title: Image
type: image
required: true
mode:
order: 2
title: Mode
type: string
required: true
default: detailed_caption
enum:
- caption|Caption
- detailed_caption|Detailed caption
outputs:
caption:
title: Caption
type: string
package: replicate
script: |
export async function run({ inputs, state }) {
const { RepeatNode, NextNode, FatalError } = DEFINITIONS;
const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
if (!REPLICATE_TOKEN) {
throw new FatalError('Please, set REPLICATE_TOKEN environment variable');
}
const { image, mode } = inputs;
if (!state) {
const { data: { id: task } } = await httpClient({
method: 'post',
url: 'https://api.replicate.com/v1/predictions',
data: {
version: 'da53547e17d45b9cfb48174b2f18af8b83ca020fa76db62136bf9c6616762595',
input: {
image: image,
task_input: mode === 'caption' ? 'Caption' : 'Detailed Caption'
}
},
headers: {
'Authorization': `Token ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
},
timeout: 10000
});
return RepeatNode.from({
state: {
task,
retries: 0
},
delay: 2000
});
} else {
const { data } = await httpClient({
method: 'get',
url: `https://api.replicate.com/v1/predictions/${state.task}`,
headers: {
'Authorization': `Token ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
},
timeout: 5000
});
const { status, error } = data;
switch (status) {
case 'processing':
case 'starting':
if (state.retries > 30) {
throw new FatalError('Task timeout exceeded');
}
return RepeatNode.from({
state: {
...state,
retries: state.retries + 1
},
delay: 3000
});
case 'failed':
throw new FatalError(error || 'Task failed');
case 'succeeded':
let caption = data.output?.text ||
data.output?.['<CAPTION>'] ||
data.output?.['<DETAILED_CAPTION>'] ||
'No caption generated';
// Удаляем метки CAPTION/DETAILED_CAPTION если они есть в тексте
caption = String(caption)
.replace(/^[\s{:]*['']?<CAPTION>['']?|[''}]\s*$/gi, '')
.replace(/^[\s{:]*['']?<DETAILED_CAPTION>['']?|[''}]\s*$/gi, '')
.replace(/^[\s:]*['']+|['']+\s*$/g, '')
.trim();
return NextNode.from({
outputs: {
caption
}
});
default:
throw new FatalError(`Unknown status: ${status}`);
}
}
}
source: catalog
title: Florence-2 Vision
version: 5
generate_on_flux_fill_pro_replicate:
_id: generate_on_flux_fill_pro_replicate
arrange:
x: 1730
y: 90
category:
_id: generate_images
title: en=Generate images;ru=Генерация изображений
environment:
REPLICATE_TOKEN:
title: Replicate token
description: Go to [Replicate](https://replicate.com/account/api-tokens) to take a keys
type: string
scope: global
execution: regular
inputs:
prompt:
order: 2
title: en=Prompt;ru=Подсказка
description: |-
Text prompt for image generation
--- ru ---
Текстовая подсказка для генерации изображения
type: string
required: true
multiline: true
seed:
order: 5
title: en=Seed;ru=Начальный шум
description: |-
Seed "-1" is a random value, otherwise a fixed value
--- ru ---
Значение "-1" - случайное число, иначе фиксированное
type: integer
default: -1
guidance:
order: 8
title: en=Guidance;ru=Креативность
description: |-
Controls the balance between adherence to the text prompt and image quality/diversity. Higher values make the output more closely match the prompt but may reduce overall image quality. Lower values allow for more creative freedom but might produce results less relevant to the prompt
--- ru ---
Контролирует баланс между соответствием текстовой подсказке и качеством/разнообразием изображения. Более высокие значения делают вывод более соответствующим подсказке, но могут снизить общее качество изображения. Более низкие значения позволяют большую творческую свободу, но могут давать результаты, менее соответствующие подсказке
type: integer
min: 2
max: 100
step: 1
default: 60
output_format:
order: 10
title: en=Output Format;ru=Формат вывода
description: |-
Format of the output images
--- ru ---
Формат выходных изображений
type: string
default: jpg
enum:
- jpg
- png
image:
order: 1
title: en=Image;ru=Изображение
description: |-
The image to inpaint. Can contain an alpha mask. Must be jpeg, png, gif, or webp
--- ru ---
Изображение для дорисовки. Может содержать альфа-маску. Должно быть в формате jpeg, png, gif или webp
type: image
required: true
extensions:
- id: draw-mask
params:
mask: mask
mask:
order: 3
title: en=Mask;ru=Маска
description: |-
A black-and-white image that describes the part of the image to inpaint. Black areas will be preserved while white areas will be inpainted. Must have the same size as image. Optional if you provide an alpha mask in the original image
--- ru ---
Черно-белое изображение, описывающее часть изображения для дорисовки. Черные области будут сохранены, а белые области будут дорисованы. Должно иметь тот же размер, что и изображение. Необязательно, если вы предоставляете альфа-маску в исходном изображении
type: image
outpaint:
order: 4
title: en=Outpaint;ru=Расширение
description: |-
Outpainting an input image. Mask will be ignored
--- ru ---
Outpaint - расширения входного изображения. Маска будет проигнорирована
type: string
default: None
enum:
- None|en=None;ru=Ничего
- Zoom out 1.5x|en=Zoom out 1.5x;ru=Отдалить в 1,5 раза
- Zoom out 2x|en=Zoom out 2x;ru=Отдалить в 2 раза
- Make square|en=Make square;ru=Сделать квадратным
- Left outpaint|en=Left outpaint;ru=Расширить слева
- Right outpaint|en=Right outpaint;ru=Расширить справа
- Top outpaint|en=Top outpaint;ru=Расширить сверху
- Bottom outpaint|en=Bottom outpaint;ru=Расширить снизу
steps:
order: 6
title: en=Steps;ru=Шаги
description: |-
Range 15-50 (more=slower)
--- ru ---
Диапазон 15-50 (больше=медленнее)
type: integer
min: 15
max: 50
step: 1
default: 50
prompt_upsampling:
order: 7
title: en=Prompt Upsampling;ru=Улучшение подсказки
description: |-
Automatically modify the prompt for more creative generation
--- ru ---
Автоматически изменять подсказку для более креативной генерации
type: boolean
default: false
safety_tolerance:
order: 9
title: en=Safety Tolerance;ru=Цензура
description: |-
Safety tolerance, 1 is most strict and 6 is most permissive
--- ru ---
Цензура от 1 (строгая) до 6 (свободная)
type: integer
min: 1
max: 6
step: 1
default: 2
outputs:
image:
title: en=Image;ru=Изображение
type: image
package: replicate
script: |
export async function run({ inputs, state }) {
const { RepeatNode, NextNode, FatalError } = DEFINITIONS;
const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
if (!REPLICATE_TOKEN) {
throw new FatalError('Please, set your API token for Replicate AI');
}
const {
prompt,
image,
mask,
outpaint = 'None',
seed = -1,
steps = 50,
prompt_upsampling = false,
guidance = 60,
safety_tolerance = 2,
output_format = 'jpg'
} = inputs;
if (!state) {
const { data: { id: task } } = await httpClient({
method: 'post',
url: 'https://api.replicate.com/v1/models/black-forest-labs/flux-fill-pro/predictions',
data: {
input: {
prompt,
image,
mask,
outpaint,
seed,
steps,
prompt_upsampling,
guidance,
safety_tolerance,
output_format
}
},
headers: {
'Authorization': `Bearer ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
},
timeout: 10000 // Увеличенный таймаут для старта
});
return RepeatNode.from({
state: {
task,
retries: 0
},
delay: 2000
});
} else {
const { data } = await httpClient({
method: 'get',
url: `https://api.replicate.com/v1/predictions/${state.task}`,
headers: {
'Authorization': `Bearer ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
},
timeout: 5000 // Таймаут для проверки статуса
});
const { status, error } = data;
switch (status) {
case 'starting':
case 'processing':
if (state.retries > 30) { // Увеличенный лимит попыток
throw new FatalError('Generation timeout exceeded');
}
return RepeatNode.from({
state: {
...state,
retries: state.retries + 1
},
delay: 3000
});
case 'failed':
throw new FatalError(error || 'Generation failed');
case 'succeeded':
const imageOutput = data.output;
return NextNode.from({
outputs: {
image: imageOutput
}
});
default:
throw new FatalError(`Unknown status: ${status}`);
}
}
}
source: catalog
title: en=Generate Flux Fill;ru=Генерация Flux Fill
version: 1
generate_on_flux_redux_replicate:
_id: generate_on_flux_redux_replicate
arrange:
x: 1430
y: 90
category:
_id: generate_images
title: en=Generate images;ru=Генерация изображений
environment:
REPLICATE_TOKEN:
title: Replicate token
description: Go to [Replicate](https://replicate.com/account/api-tokens) to take a keys
type: string
scope: global
execution: regular
inputs:
seed:
order: 6
title: en=Seed;ru=Начальный шум
description: |-
Seed "-1" is a random value, otherwise a fixed value
--- ru ---
Значение "-1" - случайное число, иначе фиксированное
type: integer
default: -1
num_outputs:
order: 3
title: en=Images count;ru=Кол-во изображений
description: |-
Number of outputs to generate
--- ru ---
Количество изображений для генерации
type: integer
min: 1
max: 4
step: 1
default: 1
guidance:
order: 5
title: en=Guidance;ru=Креативность
description: |-
The larger the value, the greater the strength of the prompt (1-10)
--- ru ---
Чем больше значение, тем сильнее влияет подсказка (1-10)
type: integer
min: 1
max: 10
step: 0.5
default: 3.5
num_inference_steps:
order: 4
title: en=Generation steps;ru=Шагов генерации
description: |-
Range 15-50 (more=slower)
--- ru ---
Диапазон 15-50 (больше=медленнее)
type: integer
min: 15
max: 50
step: 1
default: 28
megapixels:
order: 9
title: en=Megapixels;ru=Мегапиксели
description: |-
Approximate number of megapixels for generated image
--- ru ---
Приблизительное количество мегапикселей для сгенерированного изображения
type: string
default: "1"
enum:
- "1"
- "0.25"
output_format:
order: 7
title: en=Output Format;ru=Формат вывода
description: |-
Format of the output images
--- ru ---
Формат выходного изображения
type: string
default: png
enum:
- webp
- jpg
- png
output_quality:
order: 8
title: en=Quality;ru=Качество
description: |-
Quality when saving the output images, from 0 to 100. 100 is best quality, 0 is lowest quality. Not relevant for .png outputs
--- ru ---
Качество при сохранении изображений, от 0 до 100. 100 - наилучшее качество, 0 - наименьшее. Не актуально для выходных изображений в формате .png
type: integer
min: 0
max: 100
step: 1
default: 80
disable_safety_checker:
order: 10
title: en=Disable Safety Checker;ru=Отключить проверку
description: |-
Disable safety checker for generated images
--- ru ---
Отключить проверку безопасности для сгенерированных изображений
type: boolean
default: false
redux_image:
order: 1
title: en=Image;ru=Изображение
type: image
required: true
aspect_ratio:
order: 2
title: en=Aspect Ratio;ru=Соотношение сторон
description: |-
Aspect ratio for the generated image
--- ru ---
Соотношение сторон для сгенерированного изображения
type: string
default: 1:1
enum:
- 1:1
- 16:9
- 21:9
- 3:2
- 2:3
- 4:5
- 5:4
- 3:4
- 4:3
- 9:16
- 9:21
outputs:
images:
title: Images
type: image[]
image1:
title: Image 1
type: image
image2:
title: Image 2
type: image
image3:
title: Image 3
type: image
image4:
title: Image 4
type: image
package: replicate
script: |
export async function run({ inputs, state }) {
const { RepeatNode, NextNode, FatalError } = DEFINITIONS;
const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
if (!REPLICATE_TOKEN) {
throw new FatalError('Please, set your API token for Replicate AI');
}
const {
redux_image,
aspect_ratio = '1:1',
num_outputs = 1,
num_inference_steps = 28,
guidance = 3,
seed = -1,
output_format = 'webp',
output_quality = 80,
megapixels = '1',
disable_safety_checker = false
} = inputs;
if (!state) {
const { data: { id: task } } = await httpClient({
method: 'post',
url: 'https://api.replicate.com/v1/models/black-forest-labs/flux-redux-dev/predictions',
data: {
input: {
redux_image,
aspect_ratio,
num_outputs,
num_inference_steps,
guidance,
seed,
output_format,
output_quality,
megapixels,
disable_safety_checker
}
},
headers: {
'Authorization': `Bearer ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
},
timeout: 10000
});
return RepeatNode.from({
state: {
task,
retries: 0
},
delay: 2000
});
} else {
const { data } = await httpClient({
method: 'get',
url: `https://api.replicate.com/v1/predictions/${state.task}`,
headers: {
'Authorization': `Bearer ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
},
timeout: 5000
});
const { status, error } = data;
switch (status) {
case 'starting':
case 'processing':
if (state.retries > 20) {
throw new FatalError('Generation timeout exceeded');
}
return RepeatNode.from({
state: {
...state,
retries: state.retries + 1
},
delay: 3000
});
case 'failed':
throw new FatalError(error || 'Generation failed');
case 'succeeded':
const { output: images } = data;
const [image1, image2, image3, image4] = images;
return NextNode.from({
outputs: {
images,
image1,
image2,
image3,
image4
}
});
default:
throw new FatalError(`Unknown status: ${status}`);
}
}
}
source: catalog
title: en=Generate Flux Redux;ru=Генерация Flux Redux
version: 1
llava_1_5_13b_replicate:
_id: llava_1_5_13b_replicate
arrange:
x: 130
y: 420
category:
_id: computer_vision
title: Computer vision
environment:
REPLICATE_TOKEN:
title: Replicate token
description: Get your token from https://replicate.com/account/api-tokens
type: string
scope: global
execution: regular
inputs:
image:
order: 1
title: Image
type: image
required: true
prompt:
order: 2
title: Prompt
type: string
required: true
multiline: true
default: describe this image
maxTokens:
order: 4
title: Max tokens
type: integer
required: true
default: 1024
temperature:
order: 3
title: Temperature
type: float
required: true
min: 0
max: 1
step: 0.1
default: 0.2
topP:
order: 3
title: Nucleus sampling
type: float
required: true
min: 0
max: 1
step: 0.1
default: 1
outputs:
description:
title: Description
type: string
package: replicate
script: |
export async function run({ inputs, state }) {
const { RepeatNode, NextNode, FatalError } = DEFINITIONS;
const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
if (!REPLICATE_TOKEN) {
throw new FatalError('Please, set REPLICATE_TOKEN environment variable');
}
const { image, prompt = 'describe this image', topP, temperature, maxTokens } = inputs;
if (!state) {
const { data: { id: task } } = await httpClient({
method: 'post',
url: 'https://api.replicate.com/v1/predictions',
data: {
version: '80537f9eead1a5bfa72d5ac6ea6414379be41d4d4f6679fd776e9535d1eb58bb',
"stream": false,
input: {
image,
prompt,
top_p: topP,
temperature,
max_tokens: maxTokens
}
},
headers: {
'Authorization': `Token ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
},
timeout: 10000
});
return RepeatNode.from({
state: {
task,
retries: 0
},
delay: 2000
});
} else {
const { data } = await httpClient({
method: 'get',
url: `https://api.replicate.com/v1/predictions/${state.task}`,
headers: {
'Authorization': `Token ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
},
timeout: 5000
});
const { status, error } = data;
switch (status) {
case 'processing':
case 'starting':
if (state.retries > 30) {
throw new FatalError('Task timeout exceeded');
}
return RepeatNode.from({
state: {
...state,
retries: state.retries + 1
},
delay: 3000
});
case 'failed':
throw new FatalError(error || 'Task failed');
case 'succeeded':
let description = data.output.join('');
return NextNode.from({
outputs: {
description
}
});
default:
throw new FatalError(`Unknown status: ${status}`);
}
}
}
source: catalog
title: LLaVA-1.5-13B
version: 1
kling_2_1_replicate:
_id: kling_2_1_replicate
arrange:
x: 460
y: 610
category:
_id: generate_videos
title: en=Generate video;ru=Генерация видео
environment:
REPLICATE_TOKEN:
title: Replicate token
description: Go to [Replicate](https://replicate.com/account/api-tokens) to get API key
type: string
scope: global
execution: regular
inputs:
image:
order: 1
title: en=Image;ru=Изображение
type: image
required: true
prompt:
order: 2
title: en=Prompt;ru=Подсказка
type: string
required: true
multiline: true
negativePrompt:
order: 3
title: en=Negative prompt;ru=Негативная подсказка
type: string
multiline: true
duration:
order: 5
title: en=Duration;ru=Длина
type: integer
min: 5
max: 10
step: 5
default: 5
mode:
order: 4
title: en=Mode;ru=Режим
type: string
default: standard
enum:
- standard
- pro
outputs:
video:
title: en=Video;ru=Видео
type: video
package: replicate
script: |
export async function costs({ inputs }) {
const duration = Number(inputs?.duration || 5);
return Number((duration * 0.1).toFixed(3));
}
const MAX_RETRIES = 100;
export async function run({ inputs, state }) {
const { RepeatNode, NextNode, FatalError } = DEFINITIONS;
const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
if (!REPLICATE_TOKEN) {
throw new FatalError('Please, set your API token for Replicate AI');
}
const { image, prompt, negativePrompt, mode, duration } = inputs;
if (!state) {
const { data: { id: task } } = await httpClient({
method: 'post',
url: 'https://api.replicate.com/v1/models/kwaivgi/kling-v2.1/predictions',
data: {
input: {
start_image: image,
prompt,
negative_prompt: negativePrompt,
mode,
duration
}
},
headers: {
'Authorization': `Bearer ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
}
});
return RepeatNode.from({
state: {
task,
retries: 0
},
delay: 10000
});
} else {
const { task, retries } = state;
const { data } = await httpClient({
method: 'get',
url: `https://api.replicate.com/v1/predictions/${task}`,
headers: {
'Authorization': `Bearer ${REPLICATE_TOKEN}`,
'Content-Type': 'application/json'
}
});
const { status, error } = data;
switch (status) {
case 'starting':
case 'processing':
if (state.retries > MAX_RETRIES) {
throw new FatalError('Generation timeout exceeded');
}
return RepeatNode.from({
state: {
...state,
retries: retries + 1
},
progress: {
total: MAX_RETRIES,
processed: retries
},
delay: 5000
});
case 'failed':
throw new FatalError(error || 'Generation failed');
case 'succeeded':
const { output: video } = data;
return NextNode.from({ outputs: { video }, costs: await costs({ inputs }) });
default:
throw new FatalError(`Unknown status: ${status}`);
}
}
}
source: catalog
title: en=Generate video Kling 2.1;ru=Генерация видео Kling 2.1
version: 1