/* * 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 { ClosedEnum } from "../types/enums.js"; import { Result as SafeParseResult } from "../types/fp.js"; import { ChatCompletionResponseMessage, ChatCompletionResponseMessage$inboundSchema, ChatCompletionResponseMessage$Outbound, ChatCompletionResponseMessage$outboundSchema, } from "./chatcompletionresponsemessage.js"; import { NewLogProbsContent, NewLogProbsContent$inboundSchema, NewLogProbsContent$Outbound, NewLogProbsContent$outboundSchema, } from "./newlogprobscontent.js"; import { NewLogProbsContentTopLogProbs, NewLogProbsContentTopLogProbs$inboundSchema, NewLogProbsContentTopLogProbs$Outbound, NewLogProbsContentTopLogProbs$outboundSchema, } from "./newlogprobscontenttoplogprobs.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; import { UsageInfo, UsageInfo$inboundSchema, UsageInfo$Outbound, UsageInfo$outboundSchema, } from "./usageinfo.js"; /** * The reason the model stopped generating tokens. This will be "stop" if * * @remarks * the model hit a natural stop point or a provided stop sequence, or * "length" if the maximum number of tokens specified in the request was * reached. */ export const FinishReason = { Stop: "stop", Length: "length", } as const; /** * The reason the model stopped generating tokens. This will be "stop" if * * @remarks * the model hit a natural stop point or a provided stop sequence, or * "length" if the maximum number of tokens specified in the request was * reached. */ export type FinishReason = ClosedEnum; export type LogprobsNewLogProbsContent = { token?: string | undefined; logprob?: number | undefined; bytes?: Array | undefined; topLogprobs?: Array | undefined; tokenId?: number | undefined; textOffset?: number | undefined; }; export type LogprobsLogProbs = { tokens?: Array | undefined; tokenLogprobs?: Array | undefined; topLogprobs?: Array<{ [k: string]: number }> | undefined; textOffset?: Array | undefined; tokenIds?: Array | undefined; }; /** * The log probabilities of the most likely tokens. */ export type Logprobs = LogprobsLogProbs | LogprobsNewLogProbsContent; export type RawOutput = { /** * Pieces of the prompt (like individual messages) before truncation and concatenation. Depending on prompt_truncate_len, some of the messages might be dropped. Contains a mix of strings to be tokenized and individual tokens. */ promptFragments?: Array | undefined; /** * Fully processed prompt as seen by the model. */ promptTokenIds?: Array | undefined; /** * Raw completion produced by the model before any tool calls are parsed. */ completion?: string | undefined; completionLogprobs?: NewLogProbsContent | undefined; }; export type Choices = { /** * The index of the chat completion choice. */ index: number; message: ChatCompletionResponseMessage; /** * The reason the model stopped generating tokens. This will be "stop" if * * @remarks * the model hit a natural stop point or a provided stop sequence, or * "length" if the maximum number of tokens specified in the request was * reached. */ finishReason: FinishReason; /** * The log probabilities of the most likely tokens. */ logprobs?: LogprobsLogProbs | LogprobsNewLogProbsContent | null | undefined; rawOutput?: RawOutput | undefined; }; export type CreateChatCompletionResponse = { /** * A unique identifier of the response. */ id: string; /** * The object type, which is always "chat.completion". */ object: string; /** * The Unix time in seconds when the response was generated. */ created: number; /** * The model used for the chat completion. */ model: string; /** * The list of chat completion choices. */ choices: Array; /** * Usage statistics. * * @remarks * * For streaming responses, `usage` field is included in the very last response chunk returned. * * Note that returning `usage` for streaming requests is an OpenAI API extension. If you use OpenAI SDK, you might access the field directly even if it's not present in the type signature in the SDK. */ usage?: UsageInfo | null | undefined; }; /** @internal */ export const FinishReason$inboundSchema: z.ZodNativeEnum = z.nativeEnum(FinishReason); /** @internal */ export const FinishReason$outboundSchema: z.ZodNativeEnum = FinishReason$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace FinishReason$ { /** @deprecated use `FinishReason$inboundSchema` instead. */ export const inboundSchema = FinishReason$inboundSchema; /** @deprecated use `FinishReason$outboundSchema` instead. */ export const outboundSchema = FinishReason$outboundSchema; } /** @internal */ export const LogprobsNewLogProbsContent$inboundSchema: z.ZodType< LogprobsNewLogProbsContent, z.ZodTypeDef, unknown > = z.object({ token: z.string().optional(), logprob: z.number().optional(), bytes: z.array(z.number().int()).optional(), top_logprobs: z.array(NewLogProbsContentTopLogProbs$inboundSchema).optional(), token_id: z.number().int().optional(), text_offset: z.number().int().optional(), }).transform((v) => { return remap$(v, { "top_logprobs": "topLogprobs", "token_id": "tokenId", "text_offset": "textOffset", }); }); /** @internal */ export type LogprobsNewLogProbsContent$Outbound = { token?: string | undefined; logprob?: number | undefined; bytes?: Array | undefined; top_logprobs?: Array | undefined; token_id?: number | undefined; text_offset?: number | undefined; }; /** @internal */ export const LogprobsNewLogProbsContent$outboundSchema: z.ZodType< LogprobsNewLogProbsContent$Outbound, z.ZodTypeDef, LogprobsNewLogProbsContent > = z.object({ token: z.string().optional(), logprob: z.number().optional(), bytes: z.array(z.number().int()).optional(), topLogprobs: z.array(NewLogProbsContentTopLogProbs$outboundSchema).optional(), tokenId: z.number().int().optional(), textOffset: z.number().int().optional(), }).transform((v) => { return remap$(v, { topLogprobs: "top_logprobs", tokenId: "token_id", textOffset: "text_offset", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace LogprobsNewLogProbsContent$ { /** @deprecated use `LogprobsNewLogProbsContent$inboundSchema` instead. */ export const inboundSchema = LogprobsNewLogProbsContent$inboundSchema; /** @deprecated use `LogprobsNewLogProbsContent$outboundSchema` instead. */ export const outboundSchema = LogprobsNewLogProbsContent$outboundSchema; /** @deprecated use `LogprobsNewLogProbsContent$Outbound` instead. */ export type Outbound = LogprobsNewLogProbsContent$Outbound; } export function logprobsNewLogProbsContentToJSON( logprobsNewLogProbsContent: LogprobsNewLogProbsContent, ): string { return JSON.stringify( LogprobsNewLogProbsContent$outboundSchema.parse(logprobsNewLogProbsContent), ); } export function logprobsNewLogProbsContentFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => LogprobsNewLogProbsContent$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'LogprobsNewLogProbsContent' from JSON`, ); } /** @internal */ export const LogprobsLogProbs$inboundSchema: z.ZodType< LogprobsLogProbs, z.ZodTypeDef, unknown > = z.object({ tokens: z.array(z.string()).optional(), token_logprobs: z.array(z.number()).optional(), top_logprobs: z.array(z.record(z.number().int())).optional(), text_offset: z.array(z.number().int()).optional(), token_ids: z.array(z.number().int()).optional(), }).transform((v) => { return remap$(v, { "token_logprobs": "tokenLogprobs", "top_logprobs": "topLogprobs", "text_offset": "textOffset", "token_ids": "tokenIds", }); }); /** @internal */ export type LogprobsLogProbs$Outbound = { tokens?: Array | undefined; token_logprobs?: Array | undefined; top_logprobs?: Array<{ [k: string]: number }> | undefined; text_offset?: Array | undefined; token_ids?: Array | undefined; }; /** @internal */ export const LogprobsLogProbs$outboundSchema: z.ZodType< LogprobsLogProbs$Outbound, z.ZodTypeDef, LogprobsLogProbs > = z.object({ tokens: z.array(z.string()).optional(), tokenLogprobs: z.array(z.number()).optional(), topLogprobs: z.array(z.record(z.number().int())).optional(), textOffset: z.array(z.number().int()).optional(), tokenIds: z.array(z.number().int()).optional(), }).transform((v) => { return remap$(v, { tokenLogprobs: "token_logprobs", topLogprobs: "top_logprobs", textOffset: "text_offset", tokenIds: "token_ids", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace LogprobsLogProbs$ { /** @deprecated use `LogprobsLogProbs$inboundSchema` instead. */ export const inboundSchema = LogprobsLogProbs$inboundSchema; /** @deprecated use `LogprobsLogProbs$outboundSchema` instead. */ export const outboundSchema = LogprobsLogProbs$outboundSchema; /** @deprecated use `LogprobsLogProbs$Outbound` instead. */ export type Outbound = LogprobsLogProbs$Outbound; } export function logprobsLogProbsToJSON( logprobsLogProbs: LogprobsLogProbs, ): string { return JSON.stringify( LogprobsLogProbs$outboundSchema.parse(logprobsLogProbs), ); } export function logprobsLogProbsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => LogprobsLogProbs$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'LogprobsLogProbs' from JSON`, ); } /** @internal */ export const Logprobs$inboundSchema: z.ZodType< Logprobs, z.ZodTypeDef, unknown > = z.union([ z.lazy(() => LogprobsLogProbs$inboundSchema), z.lazy(() => LogprobsNewLogProbsContent$inboundSchema), ]); /** @internal */ export type Logprobs$Outbound = | LogprobsLogProbs$Outbound | LogprobsNewLogProbsContent$Outbound; /** @internal */ export const Logprobs$outboundSchema: z.ZodType< Logprobs$Outbound, z.ZodTypeDef, Logprobs > = z.union([ z.lazy(() => LogprobsLogProbs$outboundSchema), z.lazy(() => LogprobsNewLogProbsContent$outboundSchema), ]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace Logprobs$ { /** @deprecated use `Logprobs$inboundSchema` instead. */ export const inboundSchema = Logprobs$inboundSchema; /** @deprecated use `Logprobs$outboundSchema` instead. */ export const outboundSchema = Logprobs$outboundSchema; /** @deprecated use `Logprobs$Outbound` instead. */ export type Outbound = Logprobs$Outbound; } 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 RawOutput$inboundSchema: z.ZodType< RawOutput, z.ZodTypeDef, unknown > = z.object({ prompt_fragments: z.array(z.string()).optional(), prompt_token_ids: z.array(z.number().int()).optional(), completion: z.string().optional(), completion_logprobs: NewLogProbsContent$inboundSchema.optional(), }).transform((v) => { return remap$(v, { "prompt_fragments": "promptFragments", "prompt_token_ids": "promptTokenIds", "completion_logprobs": "completionLogprobs", }); }); /** @internal */ export type RawOutput$Outbound = { prompt_fragments?: Array | undefined; prompt_token_ids?: Array | undefined; completion?: string | undefined; completion_logprobs?: NewLogProbsContent$Outbound | undefined; }; /** @internal */ export const RawOutput$outboundSchema: z.ZodType< RawOutput$Outbound, z.ZodTypeDef, RawOutput > = z.object({ promptFragments: z.array(z.string()).optional(), promptTokenIds: z.array(z.number().int()).optional(), completion: z.string().optional(), completionLogprobs: NewLogProbsContent$outboundSchema.optional(), }).transform((v) => { return remap$(v, { promptFragments: "prompt_fragments", promptTokenIds: "prompt_token_ids", completionLogprobs: "completion_logprobs", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace RawOutput$ { /** @deprecated use `RawOutput$inboundSchema` instead. */ export const inboundSchema = RawOutput$inboundSchema; /** @deprecated use `RawOutput$outboundSchema` instead. */ export const outboundSchema = RawOutput$outboundSchema; /** @deprecated use `RawOutput$Outbound` instead. */ export type Outbound = RawOutput$Outbound; } export function rawOutputToJSON(rawOutput: RawOutput): string { return JSON.stringify(RawOutput$outboundSchema.parse(rawOutput)); } export function rawOutputFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => RawOutput$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'RawOutput' from JSON`, ); } /** @internal */ export const Choices$inboundSchema: z.ZodType = z.object({ index: z.number().int(), message: ChatCompletionResponseMessage$inboundSchema, finish_reason: FinishReason$inboundSchema, logprobs: z.nullable( z.union([ z.lazy(() => LogprobsLogProbs$inboundSchema), z.lazy(() => LogprobsNewLogProbsContent$inboundSchema), ]), ).optional(), raw_output: z.lazy(() => RawOutput$inboundSchema).optional(), }).transform((v) => { return remap$(v, { "finish_reason": "finishReason", "raw_output": "rawOutput", }); }); /** @internal */ export type Choices$Outbound = { index: number; message: ChatCompletionResponseMessage$Outbound; finish_reason: string; logprobs?: | LogprobsLogProbs$Outbound | LogprobsNewLogProbsContent$Outbound | null | undefined; raw_output?: RawOutput$Outbound | undefined; }; /** @internal */ export const Choices$outboundSchema: z.ZodType< Choices$Outbound, z.ZodTypeDef, Choices > = z.object({ index: z.number().int(), message: ChatCompletionResponseMessage$outboundSchema, finishReason: FinishReason$outboundSchema, logprobs: z.nullable( z.union([ z.lazy(() => LogprobsLogProbs$outboundSchema), z.lazy(() => LogprobsNewLogProbsContent$outboundSchema), ]), ).optional(), rawOutput: z.lazy(() => RawOutput$outboundSchema).optional(), }).transform((v) => { return remap$(v, { finishReason: "finish_reason", rawOutput: "raw_output", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace Choices$ { /** @deprecated use `Choices$inboundSchema` instead. */ export const inboundSchema = Choices$inboundSchema; /** @deprecated use `Choices$outboundSchema` instead. */ export const outboundSchema = Choices$outboundSchema; /** @deprecated use `Choices$Outbound` instead. */ export type Outbound = Choices$Outbound; } export function choicesToJSON(choices: Choices): string { return JSON.stringify(Choices$outboundSchema.parse(choices)); } export function choicesFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Choices$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Choices' from JSON`, ); } /** @internal */ export const CreateChatCompletionResponse$inboundSchema: z.ZodType< CreateChatCompletionResponse, z.ZodTypeDef, unknown > = z.object({ id: z.string(), object: z.string(), created: z.number().int(), model: z.string(), choices: z.array(z.lazy(() => Choices$inboundSchema)), usage: z.nullable(UsageInfo$inboundSchema).optional(), }); /** @internal */ export type CreateChatCompletionResponse$Outbound = { id: string; object: string; created: number; model: string; choices: Array; usage?: UsageInfo$Outbound | null | undefined; }; /** @internal */ export const CreateChatCompletionResponse$outboundSchema: z.ZodType< CreateChatCompletionResponse$Outbound, z.ZodTypeDef, CreateChatCompletionResponse > = z.object({ id: z.string(), object: z.string(), created: z.number().int(), model: z.string(), choices: z.array(z.lazy(() => Choices$outboundSchema)), usage: z.nullable(UsageInfo$outboundSchema).optional(), }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace CreateChatCompletionResponse$ { /** @deprecated use `CreateChatCompletionResponse$inboundSchema` instead. */ export const inboundSchema = CreateChatCompletionResponse$inboundSchema; /** @deprecated use `CreateChatCompletionResponse$outboundSchema` instead. */ export const outboundSchema = CreateChatCompletionResponse$outboundSchema; /** @deprecated use `CreateChatCompletionResponse$Outbound` instead. */ export type Outbound = CreateChatCompletionResponse$Outbound; } export function createChatCompletionResponseToJSON( createChatCompletionResponse: CreateChatCompletionResponse, ): string { return JSON.stringify( CreateChatCompletionResponse$outboundSchema.parse( createChatCompletionResponse, ), ); } export function createChatCompletionResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateChatCompletionResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateChatCompletionResponse' from JSON`, ); }