From 3d2ee427f92ace4e95799b52648dfdf593b4a07b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 02:41:06 +0200 Subject: [PATCH] ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.401.2 (#17) Co-authored-by: speakeasybot --- .speakeasy/gen.lock | 12 +- .speakeasy/gen.yaml | 2 +- .speakeasy/workflow.lock | 12 +- RELEASES.md | 12 +- docs/models/components/bodygenimagetoimage.md | 1 + docs/models/components/imageresponse.md | 4 +- docs/models/components/loc.md | 2 +- docs/models/components/media.md | 4 +- docs/models/components/texttoimageparams.md | 25 ++-- docs/models/components/validationerror.md | 2 +- docs/models/components/videoresponse.md | 4 +- .../operations/genaudiototextresponse.md | 2 +- .../operations/genimagetoimageresponse.md | 2 +- .../operations/genimagetovideoresponse.md | 2 +- .../operations/gensegmentanything2response.md | 2 +- docs/models/operations/genupscaleresponse.md | 2 +- jsr.json | 2 +- package-lock.json | 4 +- package.json | 2 +- src/funcs/generateAudioToText.ts | 92 ++++++------ src/funcs/generateImageToImage.ts | 132 +++++++++--------- src/funcs/generateImageToVideo.ts | 124 ++++++++-------- src/funcs/generateSegmentAnything2.ts | 120 ++++++++-------- src/funcs/generateTextToImage.ts | 74 +++++----- src/funcs/generateUpscale.ts | 106 +++++++------- src/lib/config.ts | 6 +- src/lib/sdks.ts | 48 +++---- src/models/components/bodygenaudiototext.ts | 6 +- src/models/components/bodygenimagetoimage.ts | 13 +- src/models/components/bodygenimagetovideo.ts | 6 +- .../components/bodygensegmentanything2.ts | 6 +- src/models/components/bodygenupscale.ts | 6 +- src/models/components/texttoimageparams.ts | 7 + src/sdk/sdk.ts | 2 +- 34 files changed, 441 insertions(+), 405 deletions(-) diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index f2bc84f..6c12f23 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 8bd6d3b6-cae6-4e55-b72f-6fdc1dbce9a1 management: - docChecksum: 5649b2692e9b9f3c1065851a47fbba06 + docChecksum: 4a28bceb165adf1c1dd97bbc8fe41a27 docVersion: v0.5.0 - speakeasyVersion: 1.398.1 - generationVersion: 2.415.8 - releaseVersion: 0.3.3 - configChecksum: eefe05e12f05c605ef3a39485c1596c1 + speakeasyVersion: 1.401.2 + generationVersion: 2.421.3 + releaseVersion: 0.3.4 + configChecksum: 2f966a11db44fc8cc16835f471c700a8 repoURL: https://github.com/livepeer/livepeer-ai-js.git installationURL: https://github.com/livepeer/livepeer-ai-js published: true @@ -14,7 +14,7 @@ features: typescript: additionalDependencies: 0.1.0 constsAndDefaults: 0.1.11 - core: 3.17.3 + core: 3.17.6 defaultEnabledRetries: 0.1.0 envVarSecurityUsage: 0.1.1 globalSecurity: 2.82.11 diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 7273bc4..46bd378 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -11,7 +11,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: false typescript: - version: 0.3.3 + version: 0.3.4 additionalDependencies: dependencies: jest: ^29.7.0 diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 63b04f9..55cc725 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,9 +1,9 @@ -speakeasyVersion: 1.398.1 +speakeasyVersion: 1.401.2 sources: livepeer-ai-OAS: sourceNamespace: livepeer-ai-oas - sourceRevisionDigest: sha256:ecb4cf674e1ac45f4116cd5eebcfabd9446312c5f5a6fc6ff95c8e0b6d3ab3f0 - sourceBlobDigest: sha256:84962d1cdd2b3ec311a1e3de4848a560478cefda5b3038810a518281c8032152 + sourceRevisionDigest: sha256:c315b1b7b5fabfea70de7cbb604a022f512b8a0a8866d3d2b5d2720902b1737e + sourceBlobDigest: sha256:ffdfa01671cab29ecdb8b014925f080497ace7616108fe5a4b9153cc0e562f93 tags: - latest - main @@ -11,10 +11,10 @@ targets: livepeer-ai-ts: source: livepeer-ai-OAS sourceNamespace: livepeer-ai-oas - sourceRevisionDigest: sha256:ecb4cf674e1ac45f4116cd5eebcfabd9446312c5f5a6fc6ff95c8e0b6d3ab3f0 - sourceBlobDigest: sha256:84962d1cdd2b3ec311a1e3de4848a560478cefda5b3038810a518281c8032152 + sourceRevisionDigest: sha256:c315b1b7b5fabfea70de7cbb604a022f512b8a0a8866d3d2b5d2720902b1737e + sourceBlobDigest: sha256:ffdfa01671cab29ecdb8b014925f080497ace7616108fe5a4b9153cc0e562f93 codeSamplesNamespace: code-samples-typescript-livepeer-ts - codeSamplesRevisionDigest: sha256:c7c5056503bcc37a38d70ed10bafd2ee5d820cddeaac64aef6224d8290571a90 + codeSamplesRevisionDigest: sha256:717ed852ff71a07f8e1e0c3dd3675a8d5b73894c5b81b902d5d6b08cd0031a4c workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/RELEASES.md b/RELEASES.md index 2179078..97c96f1 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -70,4 +70,14 @@ Based on: ### Generated - [typescript v0.3.3] . ### Releases -- [NPM v0.3.3] https://www.npmjs.com/package/@livepeer/ai/v/0.3.3 - . \ No newline at end of file +- [NPM v0.3.3] https://www.npmjs.com/package/@livepeer/ai/v/0.3.3 - . + +## 2024-09-23 00:01:07 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.401.2 (2.421.3) https://github.com/speakeasy-api/speakeasy +### Generated +- [typescript v0.3.4] . +### Releases +- [NPM v0.3.4] https://www.npmjs.com/package/@livepeer/ai/v/0.3.4 - . \ No newline at end of file diff --git a/docs/models/components/bodygenimagetoimage.md b/docs/models/components/bodygenimagetoimage.md index c76a3de..344fdc6 100644 --- a/docs/models/components/bodygenimagetoimage.md +++ b/docs/models/components/bodygenimagetoimage.md @@ -16,6 +16,7 @@ import { BodyGenImageToImage } from "@livepeer/ai/models/components"; | `prompt` | *string* | :heavy_check_mark: | Text prompt(s) to guide image generation. | | `guidanceScale` | *number* | :heavy_minus_sign: | Encourages model to generate images closely linked to the text prompt (higher values may reduce image quality). | | `imageGuidanceScale` | *number* | :heavy_minus_sign: | Degree to which the generated image is pushed towards the initial image. | +| `loras` | *string* | :heavy_minus_sign: | A LoRA (Low-Rank Adaptation) model and its corresponding weight for image generation. Example: { "latent-consistency/lcm-lora-sdxl": 1.0, "nerijs/pixel-art-xl": 1.2}. | | `modelId` | *string* | :heavy_minus_sign: | Hugging Face model ID used for image generation. | | `negativePrompt` | *string* | :heavy_minus_sign: | Text prompt(s) to guide what to exclude from image generation. Ignored if guidance_scale < 1. | | `numImagesPerPrompt` | *number* | :heavy_minus_sign: | Number of images to generate per prompt. | diff --git a/docs/models/components/imageresponse.md b/docs/models/components/imageresponse.md index 6b8e9e2..d48fbea 100644 --- a/docs/models/components/imageresponse.md +++ b/docs/models/components/imageresponse.md @@ -10,8 +10,8 @@ import { ImageResponse } from "@livepeer/ai/models/components"; let value: ImageResponse = { images: [ { - url: "https://that-hellcat.name", - seed: 645894, + url: "https://unique-veto.info/", + seed: 791725, nsfw: false, }, ], diff --git a/docs/models/components/loc.md b/docs/models/components/loc.md index 653ba47..e7e0d9f 100644 --- a/docs/models/components/loc.md +++ b/docs/models/components/loc.md @@ -5,7 +5,7 @@ ```typescript import { Loc } from "@livepeer/ai/models/components"; -let value: Loc = 272656; +let value: Loc = ""; ``` ## Supported Types diff --git a/docs/models/components/media.md b/docs/models/components/media.md index eb0c063..e5c4923 100644 --- a/docs/models/components/media.md +++ b/docs/models/components/media.md @@ -8,8 +8,8 @@ A media object containing information about the generated media. import { Media } from "@livepeer/ai/models/components"; let value: Media = { - url: "http://innocent-effect.org", - seed: 56713, + url: "https://oddball-translation.com", + seed: 87129, nsfw: false, }; ``` diff --git a/docs/models/components/texttoimageparams.md b/docs/models/components/texttoimageparams.md index db6849a..20c9902 100644 --- a/docs/models/components/texttoimageparams.md +++ b/docs/models/components/texttoimageparams.md @@ -12,15 +12,16 @@ let value: TextToImageParams = { ## Fields -| Field | Type | Required | Description | -| ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | -| `modelId` | *string* | :heavy_minus_sign: | Hugging Face model ID used for image generation. | -| `prompt` | *string* | :heavy_check_mark: | Text prompt(s) to guide image generation. Separate multiple prompts with '\|' if supported by the model. | -| `height` | *number* | :heavy_minus_sign: | The height in pixels of the generated image. | -| `width` | *number* | :heavy_minus_sign: | The width in pixels of the generated image. | -| `guidanceScale` | *number* | :heavy_minus_sign: | Encourages model to generate images closely linked to the text prompt (higher values may reduce image quality). | -| `negativePrompt` | *string* | :heavy_minus_sign: | Text prompt(s) to guide what to exclude from image generation. Ignored if guidance_scale < 1. | -| `safetyCheck` | *boolean* | :heavy_minus_sign: | Perform a safety check to estimate if generated images could be offensive or harmful. | -| `seed` | *number* | :heavy_minus_sign: | Seed for random number generation. | -| `numInferenceSteps` | *number* | :heavy_minus_sign: | Number of denoising steps. More steps usually lead to higher quality images but slower inference. Modulated by strength. | -| `numImagesPerPrompt` | *number* | :heavy_minus_sign: | Number of images to generate per prompt. | \ No newline at end of file +| Field | Type | Required | Description | +| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `modelId` | *string* | :heavy_minus_sign: | Hugging Face model ID used for image generation. | +| `loras` | *string* | :heavy_minus_sign: | A LoRA (Low-Rank Adaptation) model and its corresponding weight for image generation. Example: { "latent-consistency/lcm-lora-sdxl": 1.0, "nerijs/pixel-art-xl": 1.2}. | +| `prompt` | *string* | :heavy_check_mark: | Text prompt(s) to guide image generation. Separate multiple prompts with '\|' if supported by the model. | +| `height` | *number* | :heavy_minus_sign: | The height in pixels of the generated image. | +| `width` | *number* | :heavy_minus_sign: | The width in pixels of the generated image. | +| `guidanceScale` | *number* | :heavy_minus_sign: | Encourages model to generate images closely linked to the text prompt (higher values may reduce image quality). | +| `negativePrompt` | *string* | :heavy_minus_sign: | Text prompt(s) to guide what to exclude from image generation. Ignored if guidance_scale < 1. | +| `safetyCheck` | *boolean* | :heavy_minus_sign: | Perform a safety check to estimate if generated images could be offensive or harmful. | +| `seed` | *number* | :heavy_minus_sign: | Seed for random number generation. | +| `numInferenceSteps` | *number* | :heavy_minus_sign: | Number of denoising steps. More steps usually lead to higher quality images but slower inference. Modulated by strength. | +| `numImagesPerPrompt` | *number* | :heavy_minus_sign: | Number of images to generate per prompt. | \ No newline at end of file diff --git a/docs/models/components/validationerror.md b/docs/models/components/validationerror.md index 80bbdef..4aba57a 100644 --- a/docs/models/components/validationerror.md +++ b/docs/models/components/validationerror.md @@ -7,7 +7,7 @@ import { ValidationError } from "@livepeer/ai/models/components"; let value: ValidationError = { loc: [ - "", + 778157, ], msg: "", type: "", diff --git a/docs/models/components/videoresponse.md b/docs/models/components/videoresponse.md index 640192d..504c247 100644 --- a/docs/models/components/videoresponse.md +++ b/docs/models/components/videoresponse.md @@ -10,8 +10,8 @@ import { VideoResponse } from "@livepeer/ai/models/components"; let value: VideoResponse = { images: [ { - url: "http://spotted-skyline.name", - seed: 479977, + url: "https://wonderful-sediment.info", + seed: 780529, nsfw: false, }, ], diff --git a/docs/models/operations/genaudiototextresponse.md b/docs/models/operations/genaudiototextresponse.md index 834229e..2e97f07 100644 --- a/docs/models/operations/genaudiototextresponse.md +++ b/docs/models/operations/genaudiototextresponse.md @@ -7,7 +7,7 @@ import { GenAudioToTextResponse } from "@livepeer/ai/models/operations"; let value: GenAudioToTextResponse = { contentType: "", - statusCode: 602763, + statusCode: 423655, rawResponse: new Response("{\"message\": \"hello world\"}", { headers: { "Content-Type": "application/json" }, }), diff --git a/docs/models/operations/genimagetoimageresponse.md b/docs/models/operations/genimagetoimageresponse.md index 1b56039..dde4eb3 100644 --- a/docs/models/operations/genimagetoimageresponse.md +++ b/docs/models/operations/genimagetoimageresponse.md @@ -7,7 +7,7 @@ import { GenImageToImageResponse } from "@livepeer/ai/models/operations"; let value: GenImageToImageResponse = { contentType: "", - statusCode: 592845, + statusCode: 715190, rawResponse: new Response("{\"message\": \"hello world\"}", { headers: { "Content-Type": "application/json" }, }), diff --git a/docs/models/operations/genimagetovideoresponse.md b/docs/models/operations/genimagetovideoresponse.md index 006db58..ae359ba 100644 --- a/docs/models/operations/genimagetovideoresponse.md +++ b/docs/models/operations/genimagetovideoresponse.md @@ -7,7 +7,7 @@ import { GenImageToVideoResponse } from "@livepeer/ai/models/operations"; let value: GenImageToVideoResponse = { contentType: "", - statusCode: 715190, + statusCode: 602763, rawResponse: new Response("{\"message\": \"hello world\"}", { headers: { "Content-Type": "application/json" }, }), diff --git a/docs/models/operations/gensegmentanything2response.md b/docs/models/operations/gensegmentanything2response.md index 22e8927..41b99c8 100644 --- a/docs/models/operations/gensegmentanything2response.md +++ b/docs/models/operations/gensegmentanything2response.md @@ -7,7 +7,7 @@ import { GenSegmentAnything2Response } from "@livepeer/ai/models/operations"; let value: GenSegmentAnything2Response = { contentType: "", - statusCode: 857946, + statusCode: 645894, rawResponse: new Response("{\"message\": \"hello world\"}", { headers: { "Content-Type": "application/json" }, }), diff --git a/docs/models/operations/genupscaleresponse.md b/docs/models/operations/genupscaleresponse.md index a6324dc..ad61e19 100644 --- a/docs/models/operations/genupscaleresponse.md +++ b/docs/models/operations/genupscaleresponse.md @@ -7,7 +7,7 @@ import { GenUpscaleResponse } from "@livepeer/ai/models/operations"; let value: GenUpscaleResponse = { contentType: "", - statusCode: 844266, + statusCode: 544883, rawResponse: new Response("{\"message\": \"hello world\"}", { headers: { "Content-Type": "application/json" }, }), diff --git a/jsr.json b/jsr.json index 544f8c4..796403e 100644 --- a/jsr.json +++ b/jsr.json @@ -2,7 +2,7 @@ { "name": "@livepeer/ai", - "version": "0.3.3", + "version": "0.3.4", "exports": { ".": "./src/index.ts", "./models/errors": "./src/models/errors/index.ts", diff --git a/package-lock.json b/package-lock.json index fa401bb..7804c99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@livepeer/ai", - "version": "0.3.3", + "version": "0.3.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@livepeer/ai", - "version": "0.3.3", + "version": "0.3.4", "dependencies": { "jest": "^29.7.0", "jest-junit": "^16.0.0", diff --git a/package.json b/package.json index 629dbd7..60ffbc6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@livepeer/ai", - "version": "0.3.3", + "version": "0.3.4", "author": "Livepeer", "main": "./index.js", "sideEffects": false, diff --git a/src/funcs/generateAudioToText.ts b/src/funcs/generateAudioToText.ts index e63f0d2..6791ca5 100644 --- a/src/funcs/generateAudioToText.ts +++ b/src/funcs/generateAudioToText.ts @@ -4,8 +4,8 @@ import { LivepeerCore } from "../core.js"; import { readableStreamToArrayBuffer } from "../lib/files.js"; -import * as m$ from "../lib/matchers.js"; -import * as schemas$ from "../lib/schemas.js"; +import * as M from "../lib/matchers.js"; +import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; @@ -32,7 +32,7 @@ import { isReadableStream } from "../types/streams.js"; * Transcribe audio files to text. */ export async function generateAudioToText( - client$: LivepeerCore, + client: LivepeerCore, request: components.BodyGenAudioToText, options?: RequestOptions, ): Promise< @@ -49,69 +49,69 @@ export async function generateAudioToText( | ConnectionError > > { - const input$ = request; + const input = request; - const parsed$ = schemas$.safeParse( - input$, - (value$) => components.BodyGenAudioToText$outboundSchema.parse(value$), + const parsed = safeParse( + input, + (value) => components.BodyGenAudioToText$outboundSchema.parse(value), "Input validation failed", ); - if (!parsed$.ok) { - return parsed$; + if (!parsed.ok) { + return parsed; } - const payload$ = parsed$.value; - const body$ = new FormData(); + const payload = parsed.value; + const body = new FormData(); - if (isBlobLike(payload$.audio)) { - body$.append("audio", payload$.audio); - } else if (isReadableStream(payload$.audio.content)) { - const buffer = await readableStreamToArrayBuffer(payload$.audio.content); + if (isBlobLike(payload.audio)) { + body.append("audio", payload.audio); + } else if (isReadableStream(payload.audio.content)) { + const buffer = await readableStreamToArrayBuffer(payload.audio.content); const blob = new Blob([buffer], { type: "application/octet-stream" }); - body$.append("audio", blob); + body.append("audio", blob); } else { - body$.append( + body.append( "audio", - new Blob([payload$.audio.content], { type: "application/octet-stream" }), - payload$.audio.fileName, + new Blob([payload.audio.content], { type: "application/octet-stream" }), + payload.audio.fileName, ); } - if (payload$.model_id !== undefined) { - body$.append("model_id", payload$.model_id); + if (payload.model_id !== undefined) { + body.append("model_id", payload.model_id); } - const path$ = pathToFunc("/audio-to-text")(); + const path = pathToFunc("/audio-to-text")(); - const headers$ = new Headers({ + const headers = new Headers({ Accept: "application/json", }); - const httpBearer$ = await extractSecurity(client$.options$.httpBearer); - const security$ = httpBearer$ == null ? {} : { httpBearer: httpBearer$ }; + const secConfig = await extractSecurity(client._options.httpBearer); + const securityInput = secConfig == null ? {} : { httpBearer: secConfig }; const context = { operationID: "genAudioToText", oAuth2Scopes: [], - securitySource: client$.options$.httpBearer, + securitySource: client._options.httpBearer, }; - const securitySettings$ = resolveGlobalSecurity(security$); + const requestSecurity = resolveGlobalSecurity(securityInput); - const requestRes = client$.createRequest$(context, { - security: securitySettings$, + const requestRes = client._createRequest(context, { + security: requestSecurity, method: "POST", - path: path$, - headers: headers$, - body: body$, - timeoutMs: options?.timeoutMs || client$.options$.timeoutMs || -1, + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return requestRes; } - const request$ = requestRes.value; + const req = requestRes.value; - const doResult = await client$.do$(request$, { + const doResult = await client._do(req, { context, errorCodes: ["400", "401", "413", "422", "4XX", "500", "5XX"], retryConfig: options?.retries - || client$.options$.retryConfig, + || client._options.retryConfig, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { @@ -119,7 +119,7 @@ export async function generateAudioToText( } const response = doResult.value; - const responseFields$ = { + const responseFields = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, @@ -127,7 +127,7 @@ export async function generateAudioToText( Headers: {}, }; - const [result$] = await m$.match< + const [result] = await M.match< operations.GenAudioToTextResponse, | errors.HTTPError | errors.HTTPValidationError @@ -139,16 +139,16 @@ export async function generateAudioToText( | RequestTimeoutError | ConnectionError >( - m$.json(200, operations.GenAudioToTextResponse$inboundSchema, { + M.json(200, operations.GenAudioToTextResponse$inboundSchema, { key: "TextResponse", }), - m$.jsonErr([400, 401, 413, 500], errors.HTTPError$inboundSchema), - m$.jsonErr(422, errors.HTTPValidationError$inboundSchema), - m$.fail(["4XX", "5XX"]), - )(response, { extraFields: responseFields$ }); - if (!result$.ok) { - return result$; + M.jsonErr([400, 401, 413, 500], errors.HTTPError$inboundSchema), + M.jsonErr(422, errors.HTTPValidationError$inboundSchema), + M.fail(["4XX", "5XX"]), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; } - return result$; + return result; } diff --git a/src/funcs/generateImageToImage.ts b/src/funcs/generateImageToImage.ts index 3d2d619..489903a 100644 --- a/src/funcs/generateImageToImage.ts +++ b/src/funcs/generateImageToImage.ts @@ -4,8 +4,8 @@ import { LivepeerCore } from "../core.js"; import { readableStreamToArrayBuffer } from "../lib/files.js"; -import * as m$ from "../lib/matchers.js"; -import * as schemas$ from "../lib/schemas.js"; +import * as M from "../lib/matchers.js"; +import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; @@ -32,7 +32,7 @@ import { isReadableStream } from "../types/streams.js"; * Apply image transformations to a provided image. */ export async function generateImageToImage( - client$: LivepeerCore, + client: LivepeerCore, request: components.BodyGenImageToImage, options?: RequestOptions, ): Promise< @@ -49,97 +49,97 @@ export async function generateImageToImage( | ConnectionError > > { - const input$ = request; + const input = request; - const parsed$ = schemas$.safeParse( - input$, - (value$) => components.BodyGenImageToImage$outboundSchema.parse(value$), + const parsed = safeParse( + input, + (value) => components.BodyGenImageToImage$outboundSchema.parse(value), "Input validation failed", ); - if (!parsed$.ok) { - return parsed$; + if (!parsed.ok) { + return parsed; } - const payload$ = parsed$.value; - const body$ = new FormData(); + const payload = parsed.value; + const body = new FormData(); - if (isBlobLike(payload$.image)) { - body$.append("image", payload$.image); - } else if (isReadableStream(payload$.image.content)) { - const buffer = await readableStreamToArrayBuffer(payload$.image.content); + if (isBlobLike(payload.image)) { + body.append("image", payload.image); + } else if (isReadableStream(payload.image.content)) { + const buffer = await readableStreamToArrayBuffer(payload.image.content); const blob = new Blob([buffer], { type: "application/octet-stream" }); - body$.append("image", blob); + body.append("image", blob); } else { - body$.append( + body.append( "image", - new Blob([payload$.image.content], { type: "application/octet-stream" }), - payload$.image.fileName, + new Blob([payload.image.content], { type: "application/octet-stream" }), + payload.image.fileName, ); } - body$.append("prompt", payload$.prompt); - if (payload$.guidance_scale !== undefined) { - body$.append("guidance_scale", String(payload$.guidance_scale)); + body.append("prompt", payload.prompt); + if (payload.guidance_scale !== undefined) { + body.append("guidance_scale", String(payload.guidance_scale)); } - if (payload$.image_guidance_scale !== undefined) { - body$.append("image_guidance_scale", String(payload$.image_guidance_scale)); + if (payload.image_guidance_scale !== undefined) { + body.append("image_guidance_scale", String(payload.image_guidance_scale)); } - if (payload$.model_id !== undefined) { - body$.append("model_id", payload$.model_id); + if (payload.loras !== undefined) { + body.append("loras", payload.loras); } - if (payload$.negative_prompt !== undefined) { - body$.append("negative_prompt", payload$.negative_prompt); + if (payload.model_id !== undefined) { + body.append("model_id", payload.model_id); } - if (payload$.num_images_per_prompt !== undefined) { - body$.append( - "num_images_per_prompt", - String(payload$.num_images_per_prompt), - ); + if (payload.negative_prompt !== undefined) { + body.append("negative_prompt", payload.negative_prompt); + } + if (payload.num_images_per_prompt !== undefined) { + body.append("num_images_per_prompt", String(payload.num_images_per_prompt)); } - if (payload$.num_inference_steps !== undefined) { - body$.append("num_inference_steps", String(payload$.num_inference_steps)); + if (payload.num_inference_steps !== undefined) { + body.append("num_inference_steps", String(payload.num_inference_steps)); } - if (payload$.safety_check !== undefined) { - body$.append("safety_check", String(payload$.safety_check)); + if (payload.safety_check !== undefined) { + body.append("safety_check", String(payload.safety_check)); } - if (payload$.seed !== undefined) { - body$.append("seed", String(payload$.seed)); + if (payload.seed !== undefined) { + body.append("seed", String(payload.seed)); } - if (payload$.strength !== undefined) { - body$.append("strength", String(payload$.strength)); + if (payload.strength !== undefined) { + body.append("strength", String(payload.strength)); } - const path$ = pathToFunc("/image-to-image")(); + const path = pathToFunc("/image-to-image")(); - const headers$ = new Headers({ + const headers = new Headers({ Accept: "application/json", }); - const httpBearer$ = await extractSecurity(client$.options$.httpBearer); - const security$ = httpBearer$ == null ? {} : { httpBearer: httpBearer$ }; + const secConfig = await extractSecurity(client._options.httpBearer); + const securityInput = secConfig == null ? {} : { httpBearer: secConfig }; const context = { operationID: "genImageToImage", oAuth2Scopes: [], - securitySource: client$.options$.httpBearer, + securitySource: client._options.httpBearer, }; - const securitySettings$ = resolveGlobalSecurity(security$); + const requestSecurity = resolveGlobalSecurity(securityInput); - const requestRes = client$.createRequest$(context, { - security: securitySettings$, + const requestRes = client._createRequest(context, { + security: requestSecurity, method: "POST", - path: path$, - headers: headers$, - body: body$, - timeoutMs: options?.timeoutMs || client$.options$.timeoutMs || -1, + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return requestRes; } - const request$ = requestRes.value; + const req = requestRes.value; - const doResult = await client$.do$(request$, { + const doResult = await client._do(req, { context, errorCodes: ["400", "401", "422", "4XX", "500", "5XX"], retryConfig: options?.retries - || client$.options$.retryConfig, + || client._options.retryConfig, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { @@ -147,7 +147,7 @@ export async function generateImageToImage( } const response = doResult.value; - const responseFields$ = { + const responseFields = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, @@ -155,7 +155,7 @@ export async function generateImageToImage( Headers: {}, }; - const [result$] = await m$.match< + const [result] = await M.match< operations.GenImageToImageResponse, | errors.HTTPError | errors.HTTPValidationError @@ -167,16 +167,16 @@ export async function generateImageToImage( | RequestTimeoutError | ConnectionError >( - m$.json(200, operations.GenImageToImageResponse$inboundSchema, { + M.json(200, operations.GenImageToImageResponse$inboundSchema, { key: "ImageResponse", }), - m$.jsonErr([400, 401, 500], errors.HTTPError$inboundSchema), - m$.jsonErr(422, errors.HTTPValidationError$inboundSchema), - m$.fail(["4XX", "5XX"]), - )(response, { extraFields: responseFields$ }); - if (!result$.ok) { - return result$; + M.jsonErr([400, 401, 500], errors.HTTPError$inboundSchema), + M.jsonErr(422, errors.HTTPValidationError$inboundSchema), + M.fail(["4XX", "5XX"]), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; } - return result$; + return result; } diff --git a/src/funcs/generateImageToVideo.ts b/src/funcs/generateImageToVideo.ts index 19433a6..c56bc8f 100644 --- a/src/funcs/generateImageToVideo.ts +++ b/src/funcs/generateImageToVideo.ts @@ -4,8 +4,8 @@ import { LivepeerCore } from "../core.js"; import { readableStreamToArrayBuffer } from "../lib/files.js"; -import * as m$ from "../lib/matchers.js"; -import * as schemas$ from "../lib/schemas.js"; +import * as M from "../lib/matchers.js"; +import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; @@ -32,7 +32,7 @@ import { isReadableStream } from "../types/streams.js"; * Generate a video from a provided image. */ export async function generateImageToVideo( - client$: LivepeerCore, + client: LivepeerCore, request: components.BodyGenImageToVideo, options?: RequestOptions, ): Promise< @@ -49,93 +49,93 @@ export async function generateImageToVideo( | ConnectionError > > { - const input$ = request; + const input = request; - const parsed$ = schemas$.safeParse( - input$, - (value$) => components.BodyGenImageToVideo$outboundSchema.parse(value$), + const parsed = safeParse( + input, + (value) => components.BodyGenImageToVideo$outboundSchema.parse(value), "Input validation failed", ); - if (!parsed$.ok) { - return parsed$; + if (!parsed.ok) { + return parsed; } - const payload$ = parsed$.value; - const body$ = new FormData(); + const payload = parsed.value; + const body = new FormData(); - if (isBlobLike(payload$.image)) { - body$.append("image", payload$.image); - } else if (isReadableStream(payload$.image.content)) { - const buffer = await readableStreamToArrayBuffer(payload$.image.content); + if (isBlobLike(payload.image)) { + body.append("image", payload.image); + } else if (isReadableStream(payload.image.content)) { + const buffer = await readableStreamToArrayBuffer(payload.image.content); const blob = new Blob([buffer], { type: "application/octet-stream" }); - body$.append("image", blob); + body.append("image", blob); } else { - body$.append( + body.append( "image", - new Blob([payload$.image.content], { type: "application/octet-stream" }), - payload$.image.fileName, + new Blob([payload.image.content], { type: "application/octet-stream" }), + payload.image.fileName, ); } - if (payload$.fps !== undefined) { - body$.append("fps", String(payload$.fps)); + if (payload.fps !== undefined) { + body.append("fps", String(payload.fps)); } - if (payload$.height !== undefined) { - body$.append("height", String(payload$.height)); + if (payload.height !== undefined) { + body.append("height", String(payload.height)); } - if (payload$.model_id !== undefined) { - body$.append("model_id", payload$.model_id); + if (payload.model_id !== undefined) { + body.append("model_id", payload.model_id); } - if (payload$.motion_bucket_id !== undefined) { - body$.append("motion_bucket_id", String(payload$.motion_bucket_id)); + if (payload.motion_bucket_id !== undefined) { + body.append("motion_bucket_id", String(payload.motion_bucket_id)); } - if (payload$.noise_aug_strength !== undefined) { - body$.append("noise_aug_strength", String(payload$.noise_aug_strength)); + if (payload.noise_aug_strength !== undefined) { + body.append("noise_aug_strength", String(payload.noise_aug_strength)); } - if (payload$.num_inference_steps !== undefined) { - body$.append("num_inference_steps", String(payload$.num_inference_steps)); + if (payload.num_inference_steps !== undefined) { + body.append("num_inference_steps", String(payload.num_inference_steps)); } - if (payload$.safety_check !== undefined) { - body$.append("safety_check", String(payload$.safety_check)); + if (payload.safety_check !== undefined) { + body.append("safety_check", String(payload.safety_check)); } - if (payload$.seed !== undefined) { - body$.append("seed", String(payload$.seed)); + if (payload.seed !== undefined) { + body.append("seed", String(payload.seed)); } - if (payload$.width !== undefined) { - body$.append("width", String(payload$.width)); + if (payload.width !== undefined) { + body.append("width", String(payload.width)); } - const path$ = pathToFunc("/image-to-video")(); + const path = pathToFunc("/image-to-video")(); - const headers$ = new Headers({ + const headers = new Headers({ Accept: "application/json", }); - const httpBearer$ = await extractSecurity(client$.options$.httpBearer); - const security$ = httpBearer$ == null ? {} : { httpBearer: httpBearer$ }; + const secConfig = await extractSecurity(client._options.httpBearer); + const securityInput = secConfig == null ? {} : { httpBearer: secConfig }; const context = { operationID: "genImageToVideo", oAuth2Scopes: [], - securitySource: client$.options$.httpBearer, + securitySource: client._options.httpBearer, }; - const securitySettings$ = resolveGlobalSecurity(security$); + const requestSecurity = resolveGlobalSecurity(securityInput); - const requestRes = client$.createRequest$(context, { - security: securitySettings$, + const requestRes = client._createRequest(context, { + security: requestSecurity, method: "POST", - path: path$, - headers: headers$, - body: body$, - timeoutMs: options?.timeoutMs || client$.options$.timeoutMs || -1, + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return requestRes; } - const request$ = requestRes.value; + const req = requestRes.value; - const doResult = await client$.do$(request$, { + const doResult = await client._do(req, { context, errorCodes: ["400", "401", "422", "4XX", "500", "5XX"], retryConfig: options?.retries - || client$.options$.retryConfig, + || client._options.retryConfig, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { @@ -143,7 +143,7 @@ export async function generateImageToVideo( } const response = doResult.value; - const responseFields$ = { + const responseFields = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, @@ -151,7 +151,7 @@ export async function generateImageToVideo( Headers: {}, }; - const [result$] = await m$.match< + const [result] = await M.match< operations.GenImageToVideoResponse, | errors.HTTPError | errors.HTTPValidationError @@ -163,16 +163,16 @@ export async function generateImageToVideo( | RequestTimeoutError | ConnectionError >( - m$.json(200, operations.GenImageToVideoResponse$inboundSchema, { + M.json(200, operations.GenImageToVideoResponse$inboundSchema, { key: "VideoResponse", }), - m$.jsonErr([400, 401, 500], errors.HTTPError$inboundSchema), - m$.jsonErr(422, errors.HTTPValidationError$inboundSchema), - m$.fail(["4XX", "5XX"]), - )(response, { extraFields: responseFields$ }); - if (!result$.ok) { - return result$; + M.jsonErr([400, 401, 500], errors.HTTPError$inboundSchema), + M.jsonErr(422, errors.HTTPValidationError$inboundSchema), + M.fail(["4XX", "5XX"]), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; } - return result$; + return result; } diff --git a/src/funcs/generateSegmentAnything2.ts b/src/funcs/generateSegmentAnything2.ts index 2718a0d..57d88fd 100644 --- a/src/funcs/generateSegmentAnything2.ts +++ b/src/funcs/generateSegmentAnything2.ts @@ -4,8 +4,8 @@ import { LivepeerCore } from "../core.js"; import { readableStreamToArrayBuffer } from "../lib/files.js"; -import * as m$ from "../lib/matchers.js"; -import * as schemas$ from "../lib/schemas.js"; +import * as M from "../lib/matchers.js"; +import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; @@ -32,7 +32,7 @@ import { isReadableStream } from "../types/streams.js"; * Segment objects in an image. */ export async function generateSegmentAnything2( - client$: LivepeerCore, + client: LivepeerCore, request: components.BodyGenSegmentAnything2, options?: RequestOptions, ): Promise< @@ -49,90 +49,90 @@ export async function generateSegmentAnything2( | ConnectionError > > { - const input$ = request; + const input = request; - const parsed$ = schemas$.safeParse( - input$, - (value$) => components.BodyGenSegmentAnything2$outboundSchema.parse(value$), + const parsed = safeParse( + input, + (value) => components.BodyGenSegmentAnything2$outboundSchema.parse(value), "Input validation failed", ); - if (!parsed$.ok) { - return parsed$; + if (!parsed.ok) { + return parsed; } - const payload$ = parsed$.value; - const body$ = new FormData(); + const payload = parsed.value; + const body = new FormData(); - if (isBlobLike(payload$.image)) { - body$.append("image", payload$.image); - } else if (isReadableStream(payload$.image.content)) { - const buffer = await readableStreamToArrayBuffer(payload$.image.content); + if (isBlobLike(payload.image)) { + body.append("image", payload.image); + } else if (isReadableStream(payload.image.content)) { + const buffer = await readableStreamToArrayBuffer(payload.image.content); const blob = new Blob([buffer], { type: "application/octet-stream" }); - body$.append("image", blob); + body.append("image", blob); } else { - body$.append( + body.append( "image", - new Blob([payload$.image.content], { type: "application/octet-stream" }), - payload$.image.fileName, + new Blob([payload.image.content], { type: "application/octet-stream" }), + payload.image.fileName, ); } - if (payload$.box !== undefined) { - body$.append("box", payload$.box); + if (payload.box !== undefined) { + body.append("box", payload.box); } - if (payload$.mask_input !== undefined) { - body$.append("mask_input", payload$.mask_input); + if (payload.mask_input !== undefined) { + body.append("mask_input", payload.mask_input); } - if (payload$.model_id !== undefined) { - body$.append("model_id", payload$.model_id); + if (payload.model_id !== undefined) { + body.append("model_id", payload.model_id); } - if (payload$.multimask_output !== undefined) { - body$.append("multimask_output", String(payload$.multimask_output)); + if (payload.multimask_output !== undefined) { + body.append("multimask_output", String(payload.multimask_output)); } - if (payload$.normalize_coords !== undefined) { - body$.append("normalize_coords", String(payload$.normalize_coords)); + if (payload.normalize_coords !== undefined) { + body.append("normalize_coords", String(payload.normalize_coords)); } - if (payload$.point_coords !== undefined) { - body$.append("point_coords", payload$.point_coords); + if (payload.point_coords !== undefined) { + body.append("point_coords", payload.point_coords); } - if (payload$.point_labels !== undefined) { - body$.append("point_labels", payload$.point_labels); + if (payload.point_labels !== undefined) { + body.append("point_labels", payload.point_labels); } - if (payload$.return_logits !== undefined) { - body$.append("return_logits", String(payload$.return_logits)); + if (payload.return_logits !== undefined) { + body.append("return_logits", String(payload.return_logits)); } - const path$ = pathToFunc("/segment-anything-2")(); + const path = pathToFunc("/segment-anything-2")(); - const headers$ = new Headers({ + const headers = new Headers({ Accept: "application/json", }); - const httpBearer$ = await extractSecurity(client$.options$.httpBearer); - const security$ = httpBearer$ == null ? {} : { httpBearer: httpBearer$ }; + const secConfig = await extractSecurity(client._options.httpBearer); + const securityInput = secConfig == null ? {} : { httpBearer: secConfig }; const context = { operationID: "genSegmentAnything2", oAuth2Scopes: [], - securitySource: client$.options$.httpBearer, + securitySource: client._options.httpBearer, }; - const securitySettings$ = resolveGlobalSecurity(security$); + const requestSecurity = resolveGlobalSecurity(securityInput); - const requestRes = client$.createRequest$(context, { - security: securitySettings$, + const requestRes = client._createRequest(context, { + security: requestSecurity, method: "POST", - path: path$, - headers: headers$, - body: body$, - timeoutMs: options?.timeoutMs || client$.options$.timeoutMs || -1, + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return requestRes; } - const request$ = requestRes.value; + const req = requestRes.value; - const doResult = await client$.do$(request$, { + const doResult = await client._do(req, { context, errorCodes: ["400", "401", "422", "4XX", "500", "5XX"], retryConfig: options?.retries - || client$.options$.retryConfig, + || client._options.retryConfig, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { @@ -140,7 +140,7 @@ export async function generateSegmentAnything2( } const response = doResult.value; - const responseFields$ = { + const responseFields = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, @@ -148,7 +148,7 @@ export async function generateSegmentAnything2( Headers: {}, }; - const [result$] = await m$.match< + const [result] = await M.match< operations.GenSegmentAnything2Response, | errors.HTTPError | errors.HTTPValidationError @@ -160,16 +160,16 @@ export async function generateSegmentAnything2( | RequestTimeoutError | ConnectionError >( - m$.json(200, operations.GenSegmentAnything2Response$inboundSchema, { + M.json(200, operations.GenSegmentAnything2Response$inboundSchema, { key: "MasksResponse", }), - m$.jsonErr([400, 401, 500], errors.HTTPError$inboundSchema), - m$.jsonErr(422, errors.HTTPValidationError$inboundSchema), - m$.fail(["4XX", "5XX"]), - )(response, { extraFields: responseFields$ }); - if (!result$.ok) { - return result$; + M.jsonErr([400, 401, 500], errors.HTTPError$inboundSchema), + M.jsonErr(422, errors.HTTPValidationError$inboundSchema), + M.fail(["4XX", "5XX"]), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; } - return result$; + return result; } diff --git a/src/funcs/generateTextToImage.ts b/src/funcs/generateTextToImage.ts index b98bd86..e2390b3 100644 --- a/src/funcs/generateTextToImage.ts +++ b/src/funcs/generateTextToImage.ts @@ -3,9 +3,9 @@ */ import { LivepeerCore } from "../core.js"; -import { encodeJSON as encodeJSON$ } from "../lib/encodings.js"; -import * as m$ from "../lib/matchers.js"; -import * as schemas$ from "../lib/schemas.js"; +import { encodeJSON } from "../lib/encodings.js"; +import * as M from "../lib/matchers.js"; +import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; @@ -30,7 +30,7 @@ import { Result } from "../types/fp.js"; * Generate images from text prompts. */ export async function generateTextToImage( - client$: LivepeerCore, + client: LivepeerCore, request: components.TextToImageParams, options?: RequestOptions, ): Promise< @@ -47,53 +47,53 @@ export async function generateTextToImage( | ConnectionError > > { - const input$ = request; + const input = request; - const parsed$ = schemas$.safeParse( - input$, - (value$) => components.TextToImageParams$outboundSchema.parse(value$), + const parsed = safeParse( + input, + (value) => components.TextToImageParams$outboundSchema.parse(value), "Input validation failed", ); - if (!parsed$.ok) { - return parsed$; + if (!parsed.ok) { + return parsed; } - const payload$ = parsed$.value; - const body$ = encodeJSON$("body", payload$, { explode: true }); + const payload = parsed.value; + const body = encodeJSON("body", payload, { explode: true }); - const path$ = pathToFunc("/text-to-image")(); + const path = pathToFunc("/text-to-image")(); - const headers$ = new Headers({ + const headers = new Headers({ "Content-Type": "application/json", Accept: "application/json", }); - const httpBearer$ = await extractSecurity(client$.options$.httpBearer); - const security$ = httpBearer$ == null ? {} : { httpBearer: httpBearer$ }; + const secConfig = await extractSecurity(client._options.httpBearer); + const securityInput = secConfig == null ? {} : { httpBearer: secConfig }; const context = { operationID: "genTextToImage", oAuth2Scopes: [], - securitySource: client$.options$.httpBearer, + securitySource: client._options.httpBearer, }; - const securitySettings$ = resolveGlobalSecurity(security$); + const requestSecurity = resolveGlobalSecurity(securityInput); - const requestRes = client$.createRequest$(context, { - security: securitySettings$, + const requestRes = client._createRequest(context, { + security: requestSecurity, method: "POST", - path: path$, - headers: headers$, - body: body$, - timeoutMs: options?.timeoutMs || client$.options$.timeoutMs || -1, + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return requestRes; } - const request$ = requestRes.value; + const req = requestRes.value; - const doResult = await client$.do$(request$, { + const doResult = await client._do(req, { context, errorCodes: ["400", "401", "422", "4XX", "500", "5XX"], retryConfig: options?.retries - || client$.options$.retryConfig, + || client._options.retryConfig, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { @@ -101,7 +101,7 @@ export async function generateTextToImage( } const response = doResult.value; - const responseFields$ = { + const responseFields = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, @@ -109,7 +109,7 @@ export async function generateTextToImage( Headers: {}, }; - const [result$] = await m$.match< + const [result] = await M.match< operations.GenTextToImageResponse, | errors.HTTPError | errors.HTTPValidationError @@ -121,16 +121,16 @@ export async function generateTextToImage( | RequestTimeoutError | ConnectionError >( - m$.json(200, operations.GenTextToImageResponse$inboundSchema, { + M.json(200, operations.GenTextToImageResponse$inboundSchema, { key: "ImageResponse", }), - m$.jsonErr([400, 401, 500], errors.HTTPError$inboundSchema), - m$.jsonErr(422, errors.HTTPValidationError$inboundSchema), - m$.fail(["4XX", "5XX"]), - )(response, { extraFields: responseFields$ }); - if (!result$.ok) { - return result$; + M.jsonErr([400, 401, 500], errors.HTTPError$inboundSchema), + M.jsonErr(422, errors.HTTPValidationError$inboundSchema), + M.fail(["4XX", "5XX"]), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; } - return result$; + return result; } diff --git a/src/funcs/generateUpscale.ts b/src/funcs/generateUpscale.ts index ee26a46..e8c23cc 100644 --- a/src/funcs/generateUpscale.ts +++ b/src/funcs/generateUpscale.ts @@ -4,8 +4,8 @@ import { LivepeerCore } from "../core.js"; import { readableStreamToArrayBuffer } from "../lib/files.js"; -import * as m$ from "../lib/matchers.js"; -import * as schemas$ from "../lib/schemas.js"; +import * as M from "../lib/matchers.js"; +import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; @@ -32,7 +32,7 @@ import { isReadableStream } from "../types/streams.js"; * Upscale an image by increasing its resolution. */ export async function generateUpscale( - client$: LivepeerCore, + client: LivepeerCore, request: components.BodyGenUpscale, options?: RequestOptions, ): Promise< @@ -49,79 +49,79 @@ export async function generateUpscale( | ConnectionError > > { - const input$ = request; + const input = request; - const parsed$ = schemas$.safeParse( - input$, - (value$) => components.BodyGenUpscale$outboundSchema.parse(value$), + const parsed = safeParse( + input, + (value) => components.BodyGenUpscale$outboundSchema.parse(value), "Input validation failed", ); - if (!parsed$.ok) { - return parsed$; + if (!parsed.ok) { + return parsed; } - const payload$ = parsed$.value; - const body$ = new FormData(); + const payload = parsed.value; + const body = new FormData(); - if (isBlobLike(payload$.image)) { - body$.append("image", payload$.image); - } else if (isReadableStream(payload$.image.content)) { - const buffer = await readableStreamToArrayBuffer(payload$.image.content); + if (isBlobLike(payload.image)) { + body.append("image", payload.image); + } else if (isReadableStream(payload.image.content)) { + const buffer = await readableStreamToArrayBuffer(payload.image.content); const blob = new Blob([buffer], { type: "application/octet-stream" }); - body$.append("image", blob); + body.append("image", blob); } else { - body$.append( + body.append( "image", - new Blob([payload$.image.content], { type: "application/octet-stream" }), - payload$.image.fileName, + new Blob([payload.image.content], { type: "application/octet-stream" }), + payload.image.fileName, ); } - body$.append("prompt", payload$.prompt); - if (payload$.model_id !== undefined) { - body$.append("model_id", payload$.model_id); + body.append("prompt", payload.prompt); + if (payload.model_id !== undefined) { + body.append("model_id", payload.model_id); } - if (payload$.num_inference_steps !== undefined) { - body$.append("num_inference_steps", String(payload$.num_inference_steps)); + if (payload.num_inference_steps !== undefined) { + body.append("num_inference_steps", String(payload.num_inference_steps)); } - if (payload$.safety_check !== undefined) { - body$.append("safety_check", String(payload$.safety_check)); + if (payload.safety_check !== undefined) { + body.append("safety_check", String(payload.safety_check)); } - if (payload$.seed !== undefined) { - body$.append("seed", String(payload$.seed)); + if (payload.seed !== undefined) { + body.append("seed", String(payload.seed)); } - const path$ = pathToFunc("/upscale")(); + const path = pathToFunc("/upscale")(); - const headers$ = new Headers({ + const headers = new Headers({ Accept: "application/json", }); - const httpBearer$ = await extractSecurity(client$.options$.httpBearer); - const security$ = httpBearer$ == null ? {} : { httpBearer: httpBearer$ }; + const secConfig = await extractSecurity(client._options.httpBearer); + const securityInput = secConfig == null ? {} : { httpBearer: secConfig }; const context = { operationID: "genUpscale", oAuth2Scopes: [], - securitySource: client$.options$.httpBearer, + securitySource: client._options.httpBearer, }; - const securitySettings$ = resolveGlobalSecurity(security$); + const requestSecurity = resolveGlobalSecurity(securityInput); - const requestRes = client$.createRequest$(context, { - security: securitySettings$, + const requestRes = client._createRequest(context, { + security: requestSecurity, method: "POST", - path: path$, - headers: headers$, - body: body$, - timeoutMs: options?.timeoutMs || client$.options$.timeoutMs || -1, + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return requestRes; } - const request$ = requestRes.value; + const req = requestRes.value; - const doResult = await client$.do$(request$, { + const doResult = await client._do(req, { context, errorCodes: ["400", "401", "422", "4XX", "500", "5XX"], retryConfig: options?.retries - || client$.options$.retryConfig, + || client._options.retryConfig, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { @@ -129,7 +129,7 @@ export async function generateUpscale( } const response = doResult.value; - const responseFields$ = { + const responseFields = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, @@ -137,7 +137,7 @@ export async function generateUpscale( Headers: {}, }; - const [result$] = await m$.match< + const [result] = await M.match< operations.GenUpscaleResponse, | errors.HTTPError | errors.HTTPValidationError @@ -149,16 +149,16 @@ export async function generateUpscale( | RequestTimeoutError | ConnectionError >( - m$.json(200, operations.GenUpscaleResponse$inboundSchema, { + M.json(200, operations.GenUpscaleResponse$inboundSchema, { key: "ImageResponse", }), - m$.jsonErr([400, 401, 500], errors.HTTPError$inboundSchema), - m$.jsonErr(422, errors.HTTPValidationError$inboundSchema), - m$.fail(["4XX", "5XX"]), - )(response, { extraFields: responseFields$ }); - if (!result$.ok) { - return result$; + M.jsonErr([400, 401, 500], errors.HTTPError$inboundSchema), + M.jsonErr(422, errors.HTTPValidationError$inboundSchema), + M.fail(["4XX", "5XX"]), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; } - return result$; + return result; } diff --git a/src/lib/config.ts b/src/lib/config.ts index c595bad..a36cd46 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -61,7 +61,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", openapiDocVersion: "v0.5.0", - sdkVersion: "0.3.3", - genVersion: "2.415.8", - userAgent: "speakeasy-sdk/typescript 0.3.3 2.415.8 v0.5.0 @livepeer/ai", + sdkVersion: "0.3.4", + genVersion: "2.421.3", + userAgent: "speakeasy-sdk/typescript 0.3.4 2.421.3 v0.5.0 @livepeer/ai", } as const; diff --git a/src/lib/sdks.ts b/src/lib/sdks.ts index 5e2a890..a0f4de1 100644 --- a/src/lib/sdks.ts +++ b/src/lib/sdks.ts @@ -71,11 +71,11 @@ const isBrowserLike = webWorkerLike || (typeof window === "object" && typeof window.document !== "undefined"); export class ClientSDK { - private readonly httpClient: HTTPClient; - protected readonly baseURL: URL | null; - protected readonly hooks$: SDKHooks; - protected readonly logger?: Logger | undefined; - public readonly options$: SDKOptions & { hooks?: SDKHooks }; + readonly #httpClient: HTTPClient; + readonly #hooks: SDKHooks; + readonly #logger?: Logger | undefined; + protected readonly _baseURL: URL | null; + public readonly _options: SDKOptions & { hooks?: SDKHooks }; constructor(options: SDKOptions = {}) { const opt = options as unknown; @@ -85,33 +85,33 @@ export class ClientSDK { && "hooks" in opt && opt.hooks instanceof SDKHooks ) { - this.hooks$ = opt.hooks; + this.#hooks = opt.hooks; } else { - this.hooks$ = new SDKHooks(); + this.#hooks = new SDKHooks(); } - this.options$ = { ...options, hooks: this.hooks$ }; + this._options = { ...options, hooks: this.#hooks }; const url = serverURLFromOptions(options); if (url) { url.pathname = url.pathname.replace(/\/+$/, "") + "/"; } - const { baseURL, client } = this.hooks$.sdkInit({ + const { baseURL, client } = this.#hooks.sdkInit({ baseURL: url, client: options.httpClient || new HTTPClient(), }); - this.baseURL = baseURL; - this.httpClient = client; - this.logger = options.debugLogger; + this._baseURL = baseURL; + this.#httpClient = client; + this.#logger = options.debugLogger; } - public createRequest$( + public _createRequest( context: HookContext, conf: RequestConfig, options?: RequestOptions, ): Result { const { method, path, query, headers: opHeaders, security } = conf; - const base = conf.baseURL ?? this.baseURL; + const base = conf.baseURL ?? this._baseURL; if (!base) { return ERR(new InvalidRequestError("No base URL provided for operation")); } @@ -195,7 +195,7 @@ export class ClientSDK { let input; try { - input = this.hooks$.beforeCreateRequest(context, { + input = this.#hooks.beforeCreateRequest(context, { url: reqURL, options: { ...fetchOptions, @@ -215,7 +215,7 @@ export class ClientSDK { return OK(new Request(input.url, input.options)); } - public async do$( + public async _do( request: Request, options: { context: HookContext; @@ -238,25 +238,25 @@ export class ClientSDK { return retry( async () => { - const req = await this.hooks$.beforeRequest(context, request.clone()); - await logRequest(this.logger, req).catch((e) => - this.logger?.log("Failed to log request:", e) + const req = await this.#hooks.beforeRequest(context, request.clone()); + await logRequest(this.#logger, req).catch((e) => + this.#logger?.log("Failed to log request:", e) ); - let response = await this.httpClient.request(req); + let response = await this.#httpClient.request(req); if (matchStatusCode(response, errorCodes)) { - const result = await this.hooks$.afterError(context, response, null); + const result = await this.#hooks.afterError(context, response, null); if (result.error) { throw result.error; } response = result.response || response; } else { - response = await this.hooks$.afterSuccess(context, response); + response = await this.#hooks.afterSuccess(context, response); } - await logResponse(this.logger, response, req) - .catch(e => this.logger?.log("Failed to log response:", e)); + await logResponse(this.#logger, response, req) + .catch(e => this.#logger?.log("Failed to log response:", e)); return response; }, diff --git a/src/models/components/bodygenaudiototext.ts b/src/models/components/bodygenaudiototext.ts index 35bed89..6cc3390 100644 --- a/src/models/components/bodygenaudiototext.ts +++ b/src/models/components/bodygenaudiototext.ts @@ -8,7 +8,7 @@ import { blobLikeSchema } from "../../types/blobs.js"; export type Audio = { fileName: string; - content: ReadableStream | Blob | ArrayBuffer; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; export type BodyGenAudioToText = { @@ -30,13 +30,14 @@ export const Audio$inboundSchema: z.ZodType = z z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), }); /** @internal */ export type Audio$Outbound = { fileName: string; - content: ReadableStream | Blob | ArrayBuffer; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; /** @internal */ @@ -50,6 +51,7 @@ export const Audio$outboundSchema: z.ZodType< z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), }); diff --git a/src/models/components/bodygenimagetoimage.ts b/src/models/components/bodygenimagetoimage.ts index 6fc8ecd..0313cf2 100644 --- a/src/models/components/bodygenimagetoimage.ts +++ b/src/models/components/bodygenimagetoimage.ts @@ -8,7 +8,7 @@ import { blobLikeSchema } from "../../types/blobs.js"; export type Image = { fileName: string; - content: ReadableStream | Blob | ArrayBuffer; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; export type BodyGenImageToImage = { @@ -28,6 +28,10 @@ export type BodyGenImageToImage = { * Degree to which the generated image is pushed towards the initial image. */ imageGuidanceScale?: number | undefined; + /** + * A LoRA (Low-Rank Adaptation) model and its corresponding weight for image generation. Example: { "latent-consistency/lcm-lora-sdxl": 1.0, "nerijs/pixel-art-xl": 1.2}. + */ + loras?: string | undefined; /** * Hugging Face model ID used for image generation. */ @@ -66,13 +70,14 @@ export const Image$inboundSchema: z.ZodType = z z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), }); /** @internal */ export type Image$Outbound = { fileName: string; - content: ReadableStream | Blob | ArrayBuffer; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; /** @internal */ @@ -86,6 +91,7 @@ export const Image$outboundSchema: z.ZodType< z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), }); @@ -112,6 +118,7 @@ export const BodyGenImageToImage$inboundSchema: z.ZodType< prompt: z.string(), guidance_scale: z.number().default(7.5), image_guidance_scale: z.number().default(1.5), + loras: z.string().default(""), model_id: z.string().default(""), negative_prompt: z.string().default(""), num_images_per_prompt: z.number().int().default(1), @@ -137,6 +144,7 @@ export type BodyGenImageToImage$Outbound = { prompt: string; guidance_scale: number; image_guidance_scale: number; + loras: string; model_id: string; negative_prompt: string; num_images_per_prompt: number; @@ -156,6 +164,7 @@ export const BodyGenImageToImage$outboundSchema: z.ZodType< prompt: z.string(), guidanceScale: z.number().default(7.5), imageGuidanceScale: z.number().default(1.5), + loras: z.string().default(""), modelId: z.string().default(""), negativePrompt: z.string().default(""), numImagesPerPrompt: z.number().int().default(1), diff --git a/src/models/components/bodygenimagetovideo.ts b/src/models/components/bodygenimagetovideo.ts index d8b05e6..3fc0deb 100644 --- a/src/models/components/bodygenimagetovideo.ts +++ b/src/models/components/bodygenimagetovideo.ts @@ -8,7 +8,7 @@ import { blobLikeSchema } from "../../types/blobs.js"; export type BodyGenImageToVideoImage = { fileName: string; - content: ReadableStream | Blob | ArrayBuffer; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; export type BodyGenImageToVideo = { @@ -65,13 +65,14 @@ export const BodyGenImageToVideoImage$inboundSchema: z.ZodType< z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), }); /** @internal */ export type BodyGenImageToVideoImage$Outbound = { fileName: string; - content: ReadableStream | Blob | ArrayBuffer; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; /** @internal */ @@ -85,6 +86,7 @@ export const BodyGenImageToVideoImage$outboundSchema: z.ZodType< z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), }); diff --git a/src/models/components/bodygensegmentanything2.ts b/src/models/components/bodygensegmentanything2.ts index 39ed93f..79f5798 100644 --- a/src/models/components/bodygensegmentanything2.ts +++ b/src/models/components/bodygensegmentanything2.ts @@ -8,7 +8,7 @@ import { blobLikeSchema } from "../../types/blobs.js"; export type BodyGenSegmentAnything2Image = { fileName: string; - content: ReadableStream | Blob | ArrayBuffer; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; export type BodyGenSegmentAnything2 = { @@ -61,13 +61,14 @@ export const BodyGenSegmentAnything2Image$inboundSchema: z.ZodType< z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), }); /** @internal */ export type BodyGenSegmentAnything2Image$Outbound = { fileName: string; - content: ReadableStream | Blob | ArrayBuffer; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; /** @internal */ @@ -81,6 +82,7 @@ export const BodyGenSegmentAnything2Image$outboundSchema: z.ZodType< z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), }); diff --git a/src/models/components/bodygenupscale.ts b/src/models/components/bodygenupscale.ts index d1c16dc..5800cde 100644 --- a/src/models/components/bodygenupscale.ts +++ b/src/models/components/bodygenupscale.ts @@ -8,7 +8,7 @@ import { blobLikeSchema } from "../../types/blobs.js"; export type BodyGenUpscaleImage = { fileName: string; - content: ReadableStream | Blob | ArrayBuffer; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; export type BodyGenUpscale = { @@ -49,13 +49,14 @@ export const BodyGenUpscaleImage$inboundSchema: z.ZodType< z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), }); /** @internal */ export type BodyGenUpscaleImage$Outbound = { fileName: string; - content: ReadableStream | Blob | ArrayBuffer; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; /** @internal */ @@ -69,6 +70,7 @@ export const BodyGenUpscaleImage$outboundSchema: z.ZodType< z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), }); diff --git a/src/models/components/texttoimageparams.ts b/src/models/components/texttoimageparams.ts index 35451cd..ed62196 100644 --- a/src/models/components/texttoimageparams.ts +++ b/src/models/components/texttoimageparams.ts @@ -10,6 +10,10 @@ export type TextToImageParams = { * Hugging Face model ID used for image generation. */ modelId?: string | undefined; + /** + * A LoRA (Low-Rank Adaptation) model and its corresponding weight for image generation. Example: { "latent-consistency/lcm-lora-sdxl": 1.0, "nerijs/pixel-art-xl": 1.2}. + */ + loras?: string | undefined; /** * Text prompt(s) to guide image generation. Separate multiple prompts with '|' if supported by the model. */ @@ -55,6 +59,7 @@ export const TextToImageParams$inboundSchema: z.ZodType< unknown > = z.object({ model_id: z.string().default(""), + loras: z.string().default(""), prompt: z.string(), height: z.number().int().default(576), width: z.number().int().default(1024), @@ -78,6 +83,7 @@ export const TextToImageParams$inboundSchema: z.ZodType< /** @internal */ export type TextToImageParams$Outbound = { model_id: string; + loras: string; prompt: string; height: number; width: number; @@ -96,6 +102,7 @@ export const TextToImageParams$outboundSchema: z.ZodType< TextToImageParams > = z.object({ modelId: z.string().default(""), + loras: z.string().default(""), prompt: z.string(), height: z.number().int().default(576), width: z.number().int().default(1024), diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index b841599..2278ba7 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -8,6 +8,6 @@ import { Generate } from "./generate.js"; export class Livepeer extends ClientSDK { private _generate?: Generate; get generate(): Generate { - return (this._generate ??= new Generate(this.options$)); + return (this._generate ??= new Generate(this._options)); } }