UNPKG

@teenth/sdk-tool

Version:

sdk-tool with R2 storage support

103 lines (102 loc) 3.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.replicateFlux = exports.tuziFlux = exports.grsaiFluxResult = exports.grsaiFlux = void 0; const request_1 = require("../request"); const grsai_secret = process.env.GRSAI_SECRET; const tuzi_secret = process.env.TUZI_SECRET; const urlPrefix = process.env.URL_PREFIX; if (!grsai_secret || !tuzi_secret || !urlPrefix) { throw new Error(`Missing environment variables: grsai_secret: ${grsai_secret}, tuzi_secret: ${tuzi_secret}, urlPrefix: ${urlPrefix}`); } const grsaiHeader = { "Content-Type": "application/json", Authorization: `Bearer ${grsai_secret}`, }; const tuziHeader = { "Content-Type": "application/json", Authorization: `Bearer ${tuzi_secret}`, }; async function grsaiFlux(req) { const response = await (0, request_1.post)("https://grsai.dakka.com.cn/v1/draw/flux", { method: "POST", headers: grsaiHeader, body: { model: req.model || "flux-kontext-pro", prompt: req.prompt, aspectRatio: req.aspectRatio, variants: 1, urls: req.userImg ? [req.userImg] : null, webHook: req.webHook, shutProgress: false, }, }); return response; } exports.grsaiFlux = grsaiFlux; async function grsaiFluxResult(id) { const response = await (0, request_1.post)(`https://grsai.dakka.com.cn/v1/draw/result`, { method: "POST", headers: grsaiHeader, body: { id, }, }); return response; } exports.grsaiFluxResult = grsaiFluxResult; async function tuziFlux(req) { const prompt = `${req.userImg}, ${req.prompt}`; const res = await fetch("https://api.tu-zi.com/v1/images/generations", { method: "POST", headers: tuziHeader, body: JSON.stringify({ model: "flux-kontext-pro", prompt, aspect_ratio: req.aspectRatio, output_format: "png", safety_tolerance: 2, prompt_upsampling: false, }), }); if (res.ok) { const data = await res.json(); return data; } else { const error = await res.text(); return { code: 500, data: null, message: error, }; } } exports.tuziFlux = tuziFlux; async function replicateFlux(req) { const prompt = `${req.userImg}, ${req.prompt}`; const res = await fetch("https://api.replicate.com/v1/models/black-forest-labs/flux-kontext-pro/predictions", { method: "POST", headers: tuziHeader, body: JSON.stringify({ model: "flux-kontext-pro", prompt, aspect_ratio: req.aspectRatio, output_format: "png", safety_tolerance: 2, prompt_upsampling: false, }), }); if (res.ok) { const data = await res.json(); return data; } else { const error = await res.text(); return { code: 500, data: null, message: error, }; } } exports.replicateFlux = replicateFlux;