/* * 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 BodyGenSegmentAnything2Image = { fileName: string; content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; export type BodyGenSegmentAnything2 = { /** * Image to segment. */ image: BodyGenSegmentAnything2Image | Blob; /** * A length 4 array given as a box prompt to the model, in XYXY format. */ box?: string | undefined; /** * A low-resolution mask input to the model, typically from a previous prediction iteration, with the form 1xHxW (H=W=256 for SAM). */ maskInput?: string | undefined; /** * Hugging Face model ID used for image generation. */ modelId?: string | undefined; /** * If true, the model will return three masks for ambiguous input prompts, often producing better masks than a single prediction. */ multimaskOutput?: boolean | undefined; /** * If true, the point coordinates will be normalized to the range [0,1], with point_coords expected to be with respect to image dimensions. */ normalizeCoords?: boolean | undefined; /** * Nx2 array of point prompts to the model, where each point is in (X,Y) in pixels. */ pointCoords?: string | undefined; /** * Labels for the point prompts, where 1 indicates a foreground point and 0 indicates a background point. */ pointLabels?: string | undefined; /** * If true, returns un-thresholded mask logits instead of a binary mask. */ returnLogits?: boolean | undefined; }; /** @internal */ export const BodyGenSegmentAnything2Image$inboundSchema: z.ZodType< BodyGenSegmentAnything2Image, z.ZodTypeDef, unknown > = z.object({ fileName: z.string(), content: z.union([ z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), z.instanceof(Uint8Array), ]), }); /** @internal */ export type BodyGenSegmentAnything2Image$Outbound = { fileName: string; content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; /** @internal */ export const BodyGenSegmentAnything2Image$outboundSchema: z.ZodType< BodyGenSegmentAnything2Image$Outbound, z.ZodTypeDef, BodyGenSegmentAnything2Image > = 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 BodyGenSegmentAnything2Image$ { /** @deprecated use `BodyGenSegmentAnything2Image$inboundSchema` instead. */ export const inboundSchema = BodyGenSegmentAnything2Image$inboundSchema; /** @deprecated use `BodyGenSegmentAnything2Image$outboundSchema` instead. */ export const outboundSchema = BodyGenSegmentAnything2Image$outboundSchema; /** @deprecated use `BodyGenSegmentAnything2Image$Outbound` instead. */ export type Outbound = BodyGenSegmentAnything2Image$Outbound; } export function bodyGenSegmentAnything2ImageToJSON( bodyGenSegmentAnything2Image: BodyGenSegmentAnything2Image, ): string { return JSON.stringify( BodyGenSegmentAnything2Image$outboundSchema.parse( bodyGenSegmentAnything2Image, ), ); } export function bodyGenSegmentAnything2ImageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => BodyGenSegmentAnything2Image$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'BodyGenSegmentAnything2Image' from JSON`, ); } /** @internal */ export const BodyGenSegmentAnything2$inboundSchema: z.ZodType< BodyGenSegmentAnything2, z.ZodTypeDef, unknown > = z.object({ image: z.lazy(() => BodyGenSegmentAnything2Image$inboundSchema), box: z.string().optional(), mask_input: z.string().optional(), model_id: z.string().default("facebook/sam2-hiera-large"), multimask_output: z.boolean().default(true), normalize_coords: z.boolean().default(true), point_coords: z.string().optional(), point_labels: z.string().optional(), return_logits: z.boolean().default(true), }).transform((v) => { return remap$(v, { "mask_input": "maskInput", "model_id": "modelId", "multimask_output": "multimaskOutput", "normalize_coords": "normalizeCoords", "point_coords": "pointCoords", "point_labels": "pointLabels", "return_logits": "returnLogits", }); }); /** @internal */ export type BodyGenSegmentAnything2$Outbound = { image: BodyGenSegmentAnything2Image$Outbound | Blob; box?: string | undefined; mask_input?: string | undefined; model_id: string; multimask_output: boolean; normalize_coords: boolean; point_coords?: string | undefined; point_labels?: string | undefined; return_logits: boolean; }; /** @internal */ export const BodyGenSegmentAnything2$outboundSchema: z.ZodType< BodyGenSegmentAnything2$Outbound, z.ZodTypeDef, BodyGenSegmentAnything2 > = z.object({ image: z.lazy(() => BodyGenSegmentAnything2Image$outboundSchema).or( blobLikeSchema, ), box: z.string().optional(), maskInput: z.string().optional(), modelId: z.string().default("facebook/sam2-hiera-large"), multimaskOutput: z.boolean().default(true), normalizeCoords: z.boolean().default(true), pointCoords: z.string().optional(), pointLabels: z.string().optional(), returnLogits: z.boolean().default(true), }).transform((v) => { return remap$(v, { maskInput: "mask_input", modelId: "model_id", multimaskOutput: "multimask_output", normalizeCoords: "normalize_coords", pointCoords: "point_coords", pointLabels: "point_labels", returnLogits: "return_logits", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace BodyGenSegmentAnything2$ { /** @deprecated use `BodyGenSegmentAnything2$inboundSchema` instead. */ export const inboundSchema = BodyGenSegmentAnything2$inboundSchema; /** @deprecated use `BodyGenSegmentAnything2$outboundSchema` instead. */ export const outboundSchema = BodyGenSegmentAnything2$outboundSchema; /** @deprecated use `BodyGenSegmentAnything2$Outbound` instead. */ export type Outbound = BodyGenSegmentAnything2$Outbound; } export function bodyGenSegmentAnything2ToJSON( bodyGenSegmentAnything2: BodyGenSegmentAnything2, ): string { return JSON.stringify( BodyGenSegmentAnything2$outboundSchema.parse(bodyGenSegmentAnything2), ); } export function bodyGenSegmentAnything2FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => BodyGenSegmentAnything2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'BodyGenSegmentAnything2' from JSON`, ); }