/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type OpenAIChatCompletionChoiceFile2 = { /** * The unique identifier of a previously uploaded file */ fileId: string; /** * Optional filename override */ filename?: string | undefined; }; export type OpenAIChatCompletionChoiceFile1 = { /** * The name of the file */ filename: string; /** * Base64-encoded file data */ fileData: string; }; /** * The file to include in the message, either as raw data or by reference */ export type OpenAIChatCompletionChoice2File = | OpenAIChatCompletionChoiceFile1 | OpenAIChatCompletionChoiceFile2; export type OpenAIChatCompletionChoice24 = { /** * Content type identifier for file content */ type: "file"; /** * The file to include in the message, either as raw data or by reference */ file: OpenAIChatCompletionChoiceFile1 | OpenAIChatCompletionChoiceFile2; }; /** * The format of the encoded audio data */ export const OpenAIChatCompletionChoice2Format = { Wav: "wav", Mp3: "mp3", } as const; /** * The format of the encoded audio data */ export type OpenAIChatCompletionChoice2Format = ClosedEnum< typeof OpenAIChatCompletionChoice2Format >; export type OpenAIChatCompletionChoice2InputAudio = { /** * Base64-encoded audio data */ data: string; /** * The format of the encoded audio data */ format: OpenAIChatCompletionChoice2Format; }; export type OpenAIChatCompletionChoice23 = { /** * Content type identifier for audio input content */ type: "input_audio"; inputAudio: OpenAIChatCompletionChoice2InputAudio; }; /** * The detail level of the image analysis. 'low' disables high-res mode, 'high' enables it, 'auto' lets the model decide. */ export const OpenAIChatCompletionChoice2Detail = { Auto: "auto", Low: "low", High: "high", } as const; /** * The detail level of the image analysis. 'low' disables high-res mode, 'high' enables it, 'auto' lets the model decide. */ export type OpenAIChatCompletionChoice2Detail = ClosedEnum< typeof OpenAIChatCompletionChoice2Detail >; export type TwoImageUrl = { /** * The URL of the image, or a base64-encoded image data URL */ url: string; /** * The detail level of the image analysis. 'low' disables high-res mode, 'high' enables it, 'auto' lets the model decide. */ detail?: OpenAIChatCompletionChoice2Detail | undefined; }; export type OpenAIChatCompletionChoice22 = { /** * Content type identifier for image URL content */ type: "image_url"; imageUrl: TwoImageUrl; }; export type OpenAIChatCompletionChoice21 = { /** * Content type identifier for text content */ type: "text"; /** * The text content to include in the message */ text: string; }; /** * A content part that can be included in a message. Supports text, images, audio, and files. */ export type Content2 = | OpenAIChatCompletionChoice21 | OpenAIChatCompletionChoice22 | OpenAIChatCompletionChoice23 | OpenAIChatCompletionChoice24; /** * The contents of the assistant message. Can be null when the message contains tool calls only. */ export type OpenAIChatCompletionChoiceContent = | string | Array< | OpenAIChatCompletionChoice21 | OpenAIChatCompletionChoice22 | OpenAIChatCompletionChoice23 | OpenAIChatCompletionChoice24 >; /** * The function that the model called */ export type OpenAIChatCompletionChoiceFunction = { /** * The name of the function to call */ name: string; /** * The arguments to call the function with, as a JSON string */ arguments: string; }; export type OpenAIChatCompletionChoiceToolCalls = { /** * The ID of the tool call */ id: string; /** * The type of the tool. Currently only 'function' is supported. */ type: "function"; /** * The function that the model called */ function: OpenAIChatCompletionChoiceFunction; }; /** * The message generated by the model */ export type Message = { /** * The role of the message author, must be 'assistant' for assistant messages */ role: "assistant"; /** * An optional name for the participant. For tool role messages, this is the name of the function called. */ name?: string | undefined; /** * Tool call that this message is responding to. Required when role is 'tool'. */ toolCallId?: string | undefined; /** * The contents of the assistant message. Can be null when the message contains tool calls only. */ content: | string | Array< | OpenAIChatCompletionChoice21 | OpenAIChatCompletionChoice22 | OpenAIChatCompletionChoice23 | OpenAIChatCompletionChoice24 > | null; /** * The reasoning content generated by the model before producing the final response. Present for models that support chain-of-thought reasoning. */ reasoning?: string | null | undefined; /** * The tool calls generated by the model, such as function calls. */ toolCalls?: Array | undefined; }; /** * The reason why the model stopped generating tokens. */ export const One = { Stop: "stop", Length: "length", ToolCalls: "tool_calls", ContentFilter: "content_filter", } as const; /** * The reason why the model stopped generating tokens. */ export type One = ClosedEnum; export type FinishReason = One | string; /** * Log probability information for the choice */ export type Logprobs = { /** * The list of tokens */ tokens: Array; /** * The log probability of each token */ tokenLogprobs: Array; /** * The top log probabilities for each token position */ topLogprobs: Array<{ [k: string]: number }>; /** * The character offset from the beginning of the returned text for each token */ textOffset: Array; }; /** * A chat completion choice generated by the model */ export type OpenAIChatCompletionChoice = { /** * The index of this choice in the list of choices */ index: number; /** * The message generated by the model */ message: Message; /** * The reason the model stopped generating tokens. 'stop' means natural stop point or provided stop sequence, 'length' means max_tokens limit reached, 'tool_calls' means the model called a tool, 'content_filter' means content was filtered due to policy violations. */ finishReason: One | string | null; /** * Log probability information for the choice */ logprobs?: Logprobs | null | undefined; }; /** @internal */ export const OpenAIChatCompletionChoiceFile2$inboundSchema: z.ZodType< OpenAIChatCompletionChoiceFile2, z.ZodTypeDef, unknown > = z.object({ file_id: z.string(), filename: z.string().optional(), }).transform((v) => { return remap$(v, { "file_id": "fileId", }); }); /** @internal */ export type OpenAIChatCompletionChoiceFile2$Outbound = { file_id: string; filename?: string | undefined; }; /** @internal */ export const OpenAIChatCompletionChoiceFile2$outboundSchema: z.ZodType< OpenAIChatCompletionChoiceFile2$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoiceFile2 > = z.object({ fileId: z.string(), filename: z.string().optional(), }).transform((v) => { return remap$(v, { fileId: "file_id", }); }); export function openAIChatCompletionChoiceFile2ToJSON( openAIChatCompletionChoiceFile2: OpenAIChatCompletionChoiceFile2, ): string { return JSON.stringify( OpenAIChatCompletionChoiceFile2$outboundSchema.parse( openAIChatCompletionChoiceFile2, ), ); } export function openAIChatCompletionChoiceFile2FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoiceFile2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoiceFile2' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoiceFile1$inboundSchema: z.ZodType< OpenAIChatCompletionChoiceFile1, z.ZodTypeDef, unknown > = z.object({ filename: z.string(), file_data: z.string(), }).transform((v) => { return remap$(v, { "file_data": "fileData", }); }); /** @internal */ export type OpenAIChatCompletionChoiceFile1$Outbound = { filename: string; file_data: string; }; /** @internal */ export const OpenAIChatCompletionChoiceFile1$outboundSchema: z.ZodType< OpenAIChatCompletionChoiceFile1$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoiceFile1 > = z.object({ filename: z.string(), fileData: z.string(), }).transform((v) => { return remap$(v, { fileData: "file_data", }); }); export function openAIChatCompletionChoiceFile1ToJSON( openAIChatCompletionChoiceFile1: OpenAIChatCompletionChoiceFile1, ): string { return JSON.stringify( OpenAIChatCompletionChoiceFile1$outboundSchema.parse( openAIChatCompletionChoiceFile1, ), ); } export function openAIChatCompletionChoiceFile1FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoiceFile1$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoiceFile1' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoice2File$inboundSchema: z.ZodType< OpenAIChatCompletionChoice2File, z.ZodTypeDef, unknown > = z.union([ z.lazy(() => OpenAIChatCompletionChoiceFile1$inboundSchema), z.lazy(() => OpenAIChatCompletionChoiceFile2$inboundSchema), ]); /** @internal */ export type OpenAIChatCompletionChoice2File$Outbound = | OpenAIChatCompletionChoiceFile1$Outbound | OpenAIChatCompletionChoiceFile2$Outbound; /** @internal */ export const OpenAIChatCompletionChoice2File$outboundSchema: z.ZodType< OpenAIChatCompletionChoice2File$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoice2File > = z.union([ z.lazy(() => OpenAIChatCompletionChoiceFile1$outboundSchema), z.lazy(() => OpenAIChatCompletionChoiceFile2$outboundSchema), ]); export function openAIChatCompletionChoice2FileToJSON( openAIChatCompletionChoice2File: OpenAIChatCompletionChoice2File, ): string { return JSON.stringify( OpenAIChatCompletionChoice2File$outboundSchema.parse( openAIChatCompletionChoice2File, ), ); } export function openAIChatCompletionChoice2FileFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoice2File$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoice2File' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoice24$inboundSchema: z.ZodType< OpenAIChatCompletionChoice24, z.ZodTypeDef, unknown > = z.object({ type: z.literal("file"), file: z.union([ z.lazy(() => OpenAIChatCompletionChoiceFile1$inboundSchema), z.lazy(() => OpenAIChatCompletionChoiceFile2$inboundSchema), ]), }); /** @internal */ export type OpenAIChatCompletionChoice24$Outbound = { type: "file"; file: | OpenAIChatCompletionChoiceFile1$Outbound | OpenAIChatCompletionChoiceFile2$Outbound; }; /** @internal */ export const OpenAIChatCompletionChoice24$outboundSchema: z.ZodType< OpenAIChatCompletionChoice24$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoice24 > = z.object({ type: z.literal("file"), file: z.union([ z.lazy(() => OpenAIChatCompletionChoiceFile1$outboundSchema), z.lazy(() => OpenAIChatCompletionChoiceFile2$outboundSchema), ]), }); export function openAIChatCompletionChoice24ToJSON( openAIChatCompletionChoice24: OpenAIChatCompletionChoice24, ): string { return JSON.stringify( OpenAIChatCompletionChoice24$outboundSchema.parse( openAIChatCompletionChoice24, ), ); } export function openAIChatCompletionChoice24FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoice24$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoice24' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoice2Format$inboundSchema: z.ZodNativeEnum< typeof OpenAIChatCompletionChoice2Format > = z.nativeEnum(OpenAIChatCompletionChoice2Format); /** @internal */ export const OpenAIChatCompletionChoice2Format$outboundSchema: z.ZodNativeEnum< typeof OpenAIChatCompletionChoice2Format > = OpenAIChatCompletionChoice2Format$inboundSchema; /** @internal */ export const OpenAIChatCompletionChoice2InputAudio$inboundSchema: z.ZodType< OpenAIChatCompletionChoice2InputAudio, z.ZodTypeDef, unknown > = z.object({ data: z.string(), format: OpenAIChatCompletionChoice2Format$inboundSchema, }); /** @internal */ export type OpenAIChatCompletionChoice2InputAudio$Outbound = { data: string; format: string; }; /** @internal */ export const OpenAIChatCompletionChoice2InputAudio$outboundSchema: z.ZodType< OpenAIChatCompletionChoice2InputAudio$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoice2InputAudio > = z.object({ data: z.string(), format: OpenAIChatCompletionChoice2Format$outboundSchema, }); export function openAIChatCompletionChoice2InputAudioToJSON( openAIChatCompletionChoice2InputAudio: OpenAIChatCompletionChoice2InputAudio, ): string { return JSON.stringify( OpenAIChatCompletionChoice2InputAudio$outboundSchema.parse( openAIChatCompletionChoice2InputAudio, ), ); } export function openAIChatCompletionChoice2InputAudioFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoice2InputAudio$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoice2InputAudio' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoice23$inboundSchema: z.ZodType< OpenAIChatCompletionChoice23, z.ZodTypeDef, unknown > = z.object({ type: z.literal("input_audio"), input_audio: z.lazy(() => OpenAIChatCompletionChoice2InputAudio$inboundSchema ), }).transform((v) => { return remap$(v, { "input_audio": "inputAudio", }); }); /** @internal */ export type OpenAIChatCompletionChoice23$Outbound = { type: "input_audio"; input_audio: OpenAIChatCompletionChoice2InputAudio$Outbound; }; /** @internal */ export const OpenAIChatCompletionChoice23$outboundSchema: z.ZodType< OpenAIChatCompletionChoice23$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoice23 > = z.object({ type: z.literal("input_audio"), inputAudio: z.lazy(() => OpenAIChatCompletionChoice2InputAudio$outboundSchema ), }).transform((v) => { return remap$(v, { inputAudio: "input_audio", }); }); export function openAIChatCompletionChoice23ToJSON( openAIChatCompletionChoice23: OpenAIChatCompletionChoice23, ): string { return JSON.stringify( OpenAIChatCompletionChoice23$outboundSchema.parse( openAIChatCompletionChoice23, ), ); } export function openAIChatCompletionChoice23FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoice23$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoice23' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoice2Detail$inboundSchema: z.ZodNativeEnum< typeof OpenAIChatCompletionChoice2Detail > = z.nativeEnum(OpenAIChatCompletionChoice2Detail); /** @internal */ export const OpenAIChatCompletionChoice2Detail$outboundSchema: z.ZodNativeEnum< typeof OpenAIChatCompletionChoice2Detail > = OpenAIChatCompletionChoice2Detail$inboundSchema; /** @internal */ export const TwoImageUrl$inboundSchema: z.ZodType< TwoImageUrl, z.ZodTypeDef, unknown > = z.object({ url: z.string(), detail: OpenAIChatCompletionChoice2Detail$inboundSchema.optional(), }); /** @internal */ export type TwoImageUrl$Outbound = { url: string; detail?: string | undefined; }; /** @internal */ export const TwoImageUrl$outboundSchema: z.ZodType< TwoImageUrl$Outbound, z.ZodTypeDef, TwoImageUrl > = z.object({ url: z.string(), detail: OpenAIChatCompletionChoice2Detail$outboundSchema.optional(), }); export function twoImageUrlToJSON(twoImageUrl: TwoImageUrl): string { return JSON.stringify(TwoImageUrl$outboundSchema.parse(twoImageUrl)); } export function twoImageUrlFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => TwoImageUrl$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'TwoImageUrl' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoice22$inboundSchema: z.ZodType< OpenAIChatCompletionChoice22, z.ZodTypeDef, unknown > = z.object({ type: z.literal("image_url"), image_url: z.lazy(() => TwoImageUrl$inboundSchema), }).transform((v) => { return remap$(v, { "image_url": "imageUrl", }); }); /** @internal */ export type OpenAIChatCompletionChoice22$Outbound = { type: "image_url"; image_url: TwoImageUrl$Outbound; }; /** @internal */ export const OpenAIChatCompletionChoice22$outboundSchema: z.ZodType< OpenAIChatCompletionChoice22$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoice22 > = z.object({ type: z.literal("image_url"), imageUrl: z.lazy(() => TwoImageUrl$outboundSchema), }).transform((v) => { return remap$(v, { imageUrl: "image_url", }); }); export function openAIChatCompletionChoice22ToJSON( openAIChatCompletionChoice22: OpenAIChatCompletionChoice22, ): string { return JSON.stringify( OpenAIChatCompletionChoice22$outboundSchema.parse( openAIChatCompletionChoice22, ), ); } export function openAIChatCompletionChoice22FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoice22$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoice22' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoice21$inboundSchema: z.ZodType< OpenAIChatCompletionChoice21, z.ZodTypeDef, unknown > = z.object({ type: z.literal("text"), text: z.string(), }); /** @internal */ export type OpenAIChatCompletionChoice21$Outbound = { type: "text"; text: string; }; /** @internal */ export const OpenAIChatCompletionChoice21$outboundSchema: z.ZodType< OpenAIChatCompletionChoice21$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoice21 > = z.object({ type: z.literal("text"), text: z.string(), }); export function openAIChatCompletionChoice21ToJSON( openAIChatCompletionChoice21: OpenAIChatCompletionChoice21, ): string { return JSON.stringify( OpenAIChatCompletionChoice21$outboundSchema.parse( openAIChatCompletionChoice21, ), ); } export function openAIChatCompletionChoice21FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoice21$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoice21' from JSON`, ); } /** @internal */ export const Content2$inboundSchema: z.ZodType< Content2, z.ZodTypeDef, unknown > = z.union([ z.lazy(() => OpenAIChatCompletionChoice21$inboundSchema), z.lazy(() => OpenAIChatCompletionChoice22$inboundSchema), z.lazy(() => OpenAIChatCompletionChoice23$inboundSchema), z.lazy(() => OpenAIChatCompletionChoice24$inboundSchema), ]); /** @internal */ export type Content2$Outbound = | OpenAIChatCompletionChoice21$Outbound | OpenAIChatCompletionChoice22$Outbound | OpenAIChatCompletionChoice23$Outbound | OpenAIChatCompletionChoice24$Outbound; /** @internal */ export const Content2$outboundSchema: z.ZodType< Content2$Outbound, z.ZodTypeDef, Content2 > = z.union([ z.lazy(() => OpenAIChatCompletionChoice21$outboundSchema), z.lazy(() => OpenAIChatCompletionChoice22$outboundSchema), z.lazy(() => OpenAIChatCompletionChoice23$outboundSchema), z.lazy(() => OpenAIChatCompletionChoice24$outboundSchema), ]); export function content2ToJSON(content2: Content2): string { return JSON.stringify(Content2$outboundSchema.parse(content2)); } export function content2FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Content2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Content2' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoiceContent$inboundSchema: z.ZodType< OpenAIChatCompletionChoiceContent, z.ZodTypeDef, unknown > = z.union([ z.string(), z.array(z.union([ z.lazy(() => OpenAIChatCompletionChoice21$inboundSchema), z.lazy(() => OpenAIChatCompletionChoice22$inboundSchema), z.lazy(() => OpenAIChatCompletionChoice23$inboundSchema), z.lazy(() => OpenAIChatCompletionChoice24$inboundSchema), ])), ]); /** @internal */ export type OpenAIChatCompletionChoiceContent$Outbound = | string | Array< | OpenAIChatCompletionChoice21$Outbound | OpenAIChatCompletionChoice22$Outbound | OpenAIChatCompletionChoice23$Outbound | OpenAIChatCompletionChoice24$Outbound >; /** @internal */ export const OpenAIChatCompletionChoiceContent$outboundSchema: z.ZodType< OpenAIChatCompletionChoiceContent$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoiceContent > = z.union([ z.string(), z.array(z.union([ z.lazy(() => OpenAIChatCompletionChoice21$outboundSchema), z.lazy(() => OpenAIChatCompletionChoice22$outboundSchema), z.lazy(() => OpenAIChatCompletionChoice23$outboundSchema), z.lazy(() => OpenAIChatCompletionChoice24$outboundSchema), ])), ]); export function openAIChatCompletionChoiceContentToJSON( openAIChatCompletionChoiceContent: OpenAIChatCompletionChoiceContent, ): string { return JSON.stringify( OpenAIChatCompletionChoiceContent$outboundSchema.parse( openAIChatCompletionChoiceContent, ), ); } export function openAIChatCompletionChoiceContentFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoiceContent$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoiceContent' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoiceFunction$inboundSchema: z.ZodType< OpenAIChatCompletionChoiceFunction, z.ZodTypeDef, unknown > = z.object({ name: z.string(), arguments: z.string(), }); /** @internal */ export type OpenAIChatCompletionChoiceFunction$Outbound = { name: string; arguments: string; }; /** @internal */ export const OpenAIChatCompletionChoiceFunction$outboundSchema: z.ZodType< OpenAIChatCompletionChoiceFunction$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoiceFunction > = z.object({ name: z.string(), arguments: z.string(), }); export function openAIChatCompletionChoiceFunctionToJSON( openAIChatCompletionChoiceFunction: OpenAIChatCompletionChoiceFunction, ): string { return JSON.stringify( OpenAIChatCompletionChoiceFunction$outboundSchema.parse( openAIChatCompletionChoiceFunction, ), ); } export function openAIChatCompletionChoiceFunctionFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoiceFunction$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoiceFunction' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoiceToolCalls$inboundSchema: z.ZodType< OpenAIChatCompletionChoiceToolCalls, z.ZodTypeDef, unknown > = z.object({ id: z.string(), type: z.literal("function"), function: z.lazy(() => OpenAIChatCompletionChoiceFunction$inboundSchema), }); /** @internal */ export type OpenAIChatCompletionChoiceToolCalls$Outbound = { id: string; type: "function"; function: OpenAIChatCompletionChoiceFunction$Outbound; }; /** @internal */ export const OpenAIChatCompletionChoiceToolCalls$outboundSchema: z.ZodType< OpenAIChatCompletionChoiceToolCalls$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoiceToolCalls > = z.object({ id: z.string(), type: z.literal("function"), function: z.lazy(() => OpenAIChatCompletionChoiceFunction$outboundSchema), }); export function openAIChatCompletionChoiceToolCallsToJSON( openAIChatCompletionChoiceToolCalls: OpenAIChatCompletionChoiceToolCalls, ): string { return JSON.stringify( OpenAIChatCompletionChoiceToolCalls$outboundSchema.parse( openAIChatCompletionChoiceToolCalls, ), ); } export function openAIChatCompletionChoiceToolCallsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoiceToolCalls$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoiceToolCalls' from JSON`, ); } /** @internal */ export const Message$inboundSchema: z.ZodType = z.object({ role: z.literal("assistant"), name: z.string().optional(), tool_call_id: z.string().optional(), content: z.nullable( z.union([ z.string(), z.array( z.union([ z.lazy(() => OpenAIChatCompletionChoice21$inboundSchema), z.lazy(() => OpenAIChatCompletionChoice22$inboundSchema), z.lazy(() => OpenAIChatCompletionChoice23$inboundSchema), z.lazy(() => OpenAIChatCompletionChoice24$inboundSchema), ]), ), ]), ), reasoning: z.nullable(z.string()).optional(), tool_calls: z.array( z.lazy(() => OpenAIChatCompletionChoiceToolCalls$inboundSchema), ).optional(), }).transform((v) => { return remap$(v, { "tool_call_id": "toolCallId", "tool_calls": "toolCalls", }); }); /** @internal */ export type Message$Outbound = { role: "assistant"; name?: string | undefined; tool_call_id?: string | undefined; content: | string | Array< | OpenAIChatCompletionChoice21$Outbound | OpenAIChatCompletionChoice22$Outbound | OpenAIChatCompletionChoice23$Outbound | OpenAIChatCompletionChoice24$Outbound > | null; reasoning?: string | null | undefined; tool_calls?: Array | undefined; }; /** @internal */ export const Message$outboundSchema: z.ZodType< Message$Outbound, z.ZodTypeDef, Message > = z.object({ role: z.literal("assistant"), name: z.string().optional(), toolCallId: z.string().optional(), content: z.nullable( z.union([ z.string(), z.array( z.union([ z.lazy(() => OpenAIChatCompletionChoice21$outboundSchema), z.lazy(() => OpenAIChatCompletionChoice22$outboundSchema), z.lazy(() => OpenAIChatCompletionChoice23$outboundSchema), z.lazy(() => OpenAIChatCompletionChoice24$outboundSchema), ]), ), ]), ), reasoning: z.nullable(z.string()).optional(), toolCalls: z.array( z.lazy(() => OpenAIChatCompletionChoiceToolCalls$outboundSchema), ).optional(), }).transform((v) => { return remap$(v, { toolCallId: "tool_call_id", toolCalls: "tool_calls", }); }); export function messageToJSON(message: Message): string { return JSON.stringify(Message$outboundSchema.parse(message)); } export function messageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Message$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Message' from JSON`, ); } /** @internal */ export const One$inboundSchema: z.ZodNativeEnum = z.nativeEnum(One); /** @internal */ export const One$outboundSchema: z.ZodNativeEnum = One$inboundSchema; /** @internal */ export const FinishReason$inboundSchema: z.ZodType< FinishReason, z.ZodTypeDef, unknown > = z.union([One$inboundSchema, z.string()]); /** @internal */ export type FinishReason$Outbound = string | string; /** @internal */ export const FinishReason$outboundSchema: z.ZodType< FinishReason$Outbound, z.ZodTypeDef, FinishReason > = z.union([One$outboundSchema, z.string()]); export function finishReasonToJSON(finishReason: FinishReason): string { return JSON.stringify(FinishReason$outboundSchema.parse(finishReason)); } export function finishReasonFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => FinishReason$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'FinishReason' from JSON`, ); } /** @internal */ export const Logprobs$inboundSchema: z.ZodType< Logprobs, z.ZodTypeDef, unknown > = z.object({ tokens: z.array(z.string()), token_logprobs: z.array(z.number()), top_logprobs: z.array(z.record(z.number())), text_offset: z.array(z.number().int()), }).transform((v) => { return remap$(v, { "token_logprobs": "tokenLogprobs", "top_logprobs": "topLogprobs", "text_offset": "textOffset", }); }); /** @internal */ export type Logprobs$Outbound = { tokens: Array; token_logprobs: Array; top_logprobs: Array<{ [k: string]: number }>; text_offset: Array; }; /** @internal */ export const Logprobs$outboundSchema: z.ZodType< Logprobs$Outbound, z.ZodTypeDef, Logprobs > = z.object({ tokens: z.array(z.string()), tokenLogprobs: z.array(z.number()), topLogprobs: z.array(z.record(z.number())), textOffset: z.array(z.number().int()), }).transform((v) => { return remap$(v, { tokenLogprobs: "token_logprobs", topLogprobs: "top_logprobs", textOffset: "text_offset", }); }); export function logprobsToJSON(logprobs: Logprobs): string { return JSON.stringify(Logprobs$outboundSchema.parse(logprobs)); } export function logprobsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Logprobs$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Logprobs' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionChoice$inboundSchema: z.ZodType< OpenAIChatCompletionChoice, z.ZodTypeDef, unknown > = z.object({ index: z.number().int(), message: z.lazy(() => Message$inboundSchema), finish_reason: z.nullable(z.union([One$inboundSchema, z.string()])), logprobs: z.nullable(z.lazy(() => Logprobs$inboundSchema)).optional(), }).transform((v) => { return remap$(v, { "finish_reason": "finishReason", }); }); /** @internal */ export type OpenAIChatCompletionChoice$Outbound = { index: number; message: Message$Outbound; finish_reason: string | string | null; logprobs?: Logprobs$Outbound | null | undefined; }; /** @internal */ export const OpenAIChatCompletionChoice$outboundSchema: z.ZodType< OpenAIChatCompletionChoice$Outbound, z.ZodTypeDef, OpenAIChatCompletionChoice > = z.object({ index: z.number().int(), message: z.lazy(() => Message$outboundSchema), finishReason: z.nullable(z.union([One$outboundSchema, z.string()])), logprobs: z.nullable(z.lazy(() => Logprobs$outboundSchema)).optional(), }).transform((v) => { return remap$(v, { finishReason: "finish_reason", }); }); export function openAIChatCompletionChoiceToJSON( openAIChatCompletionChoice: OpenAIChatCompletionChoice, ): string { return JSON.stringify( OpenAIChatCompletionChoice$outboundSchema.parse(openAIChatCompletionChoice), ); } export function openAIChatCompletionChoiceFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionChoice$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionChoice' from JSON`, ); }