/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. * @generated-id: 20da8e33491e */ import * as z from "zod/v4"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { JsonSchema, JsonSchema$inboundSchema, JsonSchema$Outbound, JsonSchema$outboundSchema, } from "./jsonschema.js"; import { ResponseFormats, ResponseFormats$inboundSchema, ResponseFormats$outboundSchema, } from "./responseformats.js"; /** * Specify the format that the model must output. By default it will use `{ "type": "text" }`. Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. Setting to `{ "type": "json_schema" }` enables JSON schema mode, which guarantees the message the model generates is in JSON and follows the schema you provide. */ export type ResponseFormat = { type?: ResponseFormats | undefined; jsonSchema?: JsonSchema | null | undefined; }; /** @internal */ export const ResponseFormat$inboundSchema: z.ZodType = z.object({ type: ResponseFormats$inboundSchema.optional(), json_schema: z.nullable(JsonSchema$inboundSchema).optional(), }).transform((v) => { return remap$(v, { "json_schema": "jsonSchema", }); }); /** @internal */ export type ResponseFormat$Outbound = { type?: string | undefined; json_schema?: JsonSchema$Outbound | null | undefined; }; /** @internal */ export const ResponseFormat$outboundSchema: z.ZodType< ResponseFormat$Outbound, ResponseFormat > = z.object({ type: ResponseFormats$outboundSchema.optional(), jsonSchema: z.nullable(JsonSchema$outboundSchema).optional(), }).transform((v) => { return remap$(v, { jsonSchema: "json_schema", }); }); export function responseFormatToJSON(responseFormat: ResponseFormat): string { return JSON.stringify(ResponseFormat$outboundSchema.parse(responseFormat)); } export function responseFormatFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ResponseFormat$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ResponseFormat' from JSON`, ); }