/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { blobLikeSchema } from "../../types/blobs.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type Image = { fileName: string; content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; export type BodyGenImageToImage = { /** * Uploaded image to modify with the pipeline. */ image: Image | Blob; /** * Text prompt(s) to guide image generation. */ prompt: string; /** * Encourages model to generate images closely linked to the text prompt (higher values may reduce image quality). */ guidanceScale?: number | undefined; /** * 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. */ modelId?: string | undefined; /** * Text prompt(s) to guide what to exclude from image generation. Ignored if guidance_scale < 1. */ negativePrompt?: string | undefined; /** * Number of images to generate per prompt. */ numImagesPerPrompt?: number | undefined; /** * Number of denoising steps. More steps usually lead to higher quality images but slower inference. Modulated by strength. */ numInferenceSteps?: number | undefined; /** * Perform a safety check to estimate if generated images could be offensive or harmful. */ safetyCheck?: boolean | undefined; /** * Seed for random number generation. */ seed?: number | undefined; /** * Degree of transformation applied to the reference image (0 to 1). */ strength?: number | undefined; }; /** @internal */ export const Image$inboundSchema: z.ZodType = z .object({ fileName: z.string(), content: z.union([ z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), z.instanceof(Uint8Array), ]), }); /** @internal */ export type Image$Outbound = { fileName: string; content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; /** @internal */ export const Image$outboundSchema: z.ZodType< Image$Outbound, z.ZodTypeDef, Image > = z.object({ fileName: z.string(), content: z.union([ z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), z.instanceof(Uint8Array), ]), }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace Image$ { /** @deprecated use `Image$inboundSchema` instead. */ export const inboundSchema = Image$inboundSchema; /** @deprecated use `Image$outboundSchema` instead. */ export const outboundSchema = Image$outboundSchema; /** @deprecated use `Image$Outbound` instead. */ export type Outbound = Image$Outbound; } export function imageToJSON(image: Image): string { return JSON.stringify(Image$outboundSchema.parse(image)); } export function imageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Image$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Image' from JSON`, ); } /** @internal */ export const BodyGenImageToImage$inboundSchema: z.ZodType< BodyGenImageToImage, z.ZodTypeDef, unknown > = z.object({ image: z.lazy(() => Image$inboundSchema), 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("timbrooks/instruct-pix2pix"), negative_prompt: z.string().default(""), num_images_per_prompt: z.number().int().default(1), num_inference_steps: z.number().int().default(100), safety_check: z.boolean().default(true), seed: z.number().int().optional(), strength: z.number().default(0.8), }).transform((v) => { return remap$(v, { "guidance_scale": "guidanceScale", "image_guidance_scale": "imageGuidanceScale", "model_id": "modelId", "negative_prompt": "negativePrompt", "num_images_per_prompt": "numImagesPerPrompt", "num_inference_steps": "numInferenceSteps", "safety_check": "safetyCheck", }); }); /** @internal */ export type BodyGenImageToImage$Outbound = { image: Image$Outbound | Blob; prompt: string; guidance_scale: number; image_guidance_scale: number; loras: string; model_id: string; negative_prompt: string; num_images_per_prompt: number; num_inference_steps: number; safety_check: boolean; seed?: number | undefined; strength: number; }; /** @internal */ export const BodyGenImageToImage$outboundSchema: z.ZodType< BodyGenImageToImage$Outbound, z.ZodTypeDef, BodyGenImageToImage > = z.object({ image: z.lazy(() => Image$outboundSchema).or(blobLikeSchema), prompt: z.string(), guidanceScale: z.number().default(7.5), imageGuidanceScale: z.number().default(1.5), loras: z.string().default(""), modelId: z.string().default("timbrooks/instruct-pix2pix"), negativePrompt: z.string().default(""), numImagesPerPrompt: z.number().int().default(1), numInferenceSteps: z.number().int().default(100), safetyCheck: z.boolean().default(true), seed: z.number().int().optional(), strength: z.number().default(0.8), }).transform((v) => { return remap$(v, { guidanceScale: "guidance_scale", imageGuidanceScale: "image_guidance_scale", modelId: "model_id", negativePrompt: "negative_prompt", numImagesPerPrompt: "num_images_per_prompt", numInferenceSteps: "num_inference_steps", safetyCheck: "safety_check", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace BodyGenImageToImage$ { /** @deprecated use `BodyGenImageToImage$inboundSchema` instead. */ export const inboundSchema = BodyGenImageToImage$inboundSchema; /** @deprecated use `BodyGenImageToImage$outboundSchema` instead. */ export const outboundSchema = BodyGenImageToImage$outboundSchema; /** @deprecated use `BodyGenImageToImage$Outbound` instead. */ export type Outbound = BodyGenImageToImage$Outbound; } export function bodyGenImageToImageToJSON( bodyGenImageToImage: BodyGenImageToImage, ): string { return JSON.stringify( BodyGenImageToImage$outboundSchema.parse(bodyGenImageToImage), ); } export function bodyGenImageToImageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => BodyGenImageToImage$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'BodyGenImageToImage' from JSON`, ); }