/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { EventStream } from "../lib/event-streams.js"; 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 { CreateCompletionResponse, CreateCompletionResponse$inboundSchema, CreateCompletionResponse$Outbound, CreateCompletionResponse$outboundSchema, } from "./createcompletionresponse.js"; import { CreateCompletionResponseStream, CreateCompletionResponseStream$inboundSchema, } from "./createcompletionresponsestream.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; /** * The prompt to generate completions for. * * @remarks * It can be a single string or an array of strings. * It can also be an array of integers or an array of integer arrays, * which allows to pass already tokenized prompt. * If multiple prompts are specified, several choices with corresponding `index` will be returned in the output." */ export type Prompt = | string | Array | Array | Array>; export type CreateCompletionLogprobs = number | boolean; /** * Up to 4 sequences where the API will stop generating further tokens. The returned text will contain the stop sequence. * * @remarks */ export type CreateCompletionStop = string | Array; /** * Must be one of `text`, `json_object`, or `grammar`. */ export const CreateCompletionType = { Text: "text", JsonObject: "json_object", Grammar: "grammar", } as const; /** * Must be one of `text`, `json_object`, or `grammar`. */ export type CreateCompletionType = ClosedEnum; /** * JSON schema according to https://json-schema.org/specification that can be provided if `"type": "json_object"`. * * @remarks * Can be provided as a JSON object or a JSON string. * If not provided when `type` is "json_object", it defaults to `{"type": "object"}`. * * Most common fields like `type`, `properties`, `items`, `required` and `anyOf` are supported. * * More sophisticated cases like `oneOf` might not be covered. * * Note: it's an OpenAI API extension. * * Example: `{"type": "object", "properties": {"foo": {"type": "string"}, "bar": {"type": "integer"}}, "required": ["foo"]}` */ export type CreateCompletionSchemaField = {}; /** * Allows to force the model to produce specific output format. * * @remarks * * Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON. * * Optional JSON schema can be provided as `response_format = {"type": "json_object", "schema": }`. * * **Important:** when using JSON mode, it's crucial to also instruct the model to produce JSON via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length. In this case the return value might not be a valid JSON. */ export type CreateCompletionResponseFormat = { /** * Must be one of `text`, `json_object`, or `grammar`. */ type?: CreateCompletionType | null | undefined; /** * JSON schema according to https://json-schema.org/specification that can be provided if `"type": "json_object"`. * * @remarks * Can be provided as a JSON object or a JSON string. * If not provided when `type` is "json_object", it defaults to `{"type": "object"}`. * * Most common fields like `type`, `properties`, `items`, `required` and `anyOf` are supported. * * More sophisticated cases like `oneOf` might not be covered. * * Note: it's an OpenAI API extension. * * Example: `{"type": "object", "properties": {"foo": {"type": "string"}, "bar": {"type": "integer"}}, "required": ["foo"]}` */ schemaField?: CreateCompletionSchemaField | null | undefined; /** * A string representing the grammar when `type` is set to "grammar". * * @remarks * Required when `type` is "grammar". */ grammar?: string | null | undefined; }; /** * What to do if the token count of prompt plus `max_tokens` exceeds the model's context window. * * @remarks * * Passing `truncate` limits the `max_tokens` to at most `context_window_length - prompt_length`. This is the default. * * Passing `error` would trigger a request error. * * The default of 'truncate' is selected as it allows to ask for high `max_tokens` value while respecting the context window length without having to do client-side prompt tokenization. * * Note, that it differs from OpenAI's behavior that matches that of `error`. */ export const CreateCompletionContextLengthExceededBehavior = { Truncate: "truncate", Error: "error", } as const; /** * What to do if the token count of prompt plus `max_tokens` exceeds the model's context window. * * @remarks * * Passing `truncate` limits the `max_tokens` to at most `context_window_length - prompt_length`. This is the default. * * Passing `error` would trigger a request error. * * The default of 'truncate' is selected as it allows to ask for high `max_tokens` value while respecting the context window length without having to do client-side prompt tokenization. * * Note, that it differs from OpenAI's behavior that matches that of `error`. */ export type CreateCompletionContextLengthExceededBehavior = ClosedEnum< typeof CreateCompletionContextLengthExceededBehavior >; export type CreateCompletionRequestBody = { /** * The name of the model to use. */ model: string; /** * The prompt to generate completions for. * * @remarks * It can be a single string or an array of strings. * It can also be an array of integers or an array of integer arrays, * which allows to pass already tokenized prompt. * If multiple prompts are specified, several choices with corresponding `index` will be returned in the output." */ prompt: string | Array | Array | Array>; /** * The list of base64 encoded images for visual language completition generation. * * @remarks * They should be formatted as MIME_TYPE,\ * eg. data:image/jpeg;base64,\ * Additionally, the number of images provided should match the number of '\' special token in the prompt */ images?: Array | undefined; /** * The maximum number of tokens to generate in the completion. * * @remarks * * If the token count of your prompt plus `max_tokens` exceed the model's context length, the behavior is depends on `context_length_exceeded_behavior`. By default, `max_tokens` will be lowered to fit in the context window instead of returning an error. */ maxTokens?: number | null | undefined; logprobs?: number | boolean | null | undefined; echo?: boolean | undefined; /** * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. * * @remarks * * We generally recommend altering this or `top_p` but not both. */ temperature?: number | null | undefined; /** * An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. * * @remarks * * We generally recommend altering this or `temperature` but not both. */ topP?: number | null | undefined; /** * Top-k sampling is another sampling method where the k most probable next tokens are filtered and the probability mass is redistributed among only those k next tokens. The value of k controls the number of candidates for the next token at each step during text generation. * * @remarks */ topK?: number | null | undefined; /** * Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. * * @remarks * * Reasonable value is around 0.1 to 1 if the aim is to just reduce repetitive samples somewhat. If the aim is to strongly suppress repetition, then one can increase the coefficients up to 2, but this can noticeably degrade the quality of samples. Negative values can be used to increase the likelihood of repetition. * * See also `presence_penalty` for penalizing tokens that have at least one appearance at a fixed rate. */ frequencyPenalty?: number | null | undefined; /** * Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. * * @remarks * * Reasonable value is around 0.1 to 1 if the aim is to just reduce repetitive samples somewhat. If the aim is to strongly suppress repetition, then one can increase the coefficients up to 2, but this can noticeably degrade the quality of samples. Negative values can be used to increase the likelihood of repetition. * * See also `frequence_penalty` for penalizing tokens at an increasing rate depending on how often they appear. */ presencePenalty?: number | null | undefined; /** * How many completions to generate for each prompt. * * @remarks * * **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`. */ n?: number | null | undefined; /** * Up to 4 sequences where the API will stop generating further tokens. The returned text will contain the stop sequence. * * @remarks */ stop?: string | Array | null | undefined; /** * Allows to force the model to produce specific output format. * * @remarks * * Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON. * * Optional JSON schema can be provided as `response_format = {"type": "json_object", "schema": }`. * * **Important:** when using JSON mode, it's crucial to also instruct the model to produce JSON via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length. In this case the return value might not be a valid JSON. */ responseFormat?: CreateCompletionResponseFormat | null | undefined; /** * Whether to stream back partial progress. If set, tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) * * @remarks * as they become available, with the stream terminated by a `data: [DONE]` message. */ stream?: boolean | null | undefined; /** * What to do if the token count of prompt plus `max_tokens` exceeds the model's context window. * * @remarks * * Passing `truncate` limits the `max_tokens` to at most `context_window_length - prompt_length`. This is the default. * * Passing `error` would trigger a request error. * * The default of 'truncate' is selected as it allows to ask for high `max_tokens` value while respecting the context window length without having to do client-side prompt tokenization. * * Note, that it differs from OpenAI's behavior that matches that of `error`. */ contextLengthExceededBehavior?: | CreateCompletionContextLengthExceededBehavior | undefined; /** * A unique identifier representing your end-user, which can help monitor and detect abuse */ user?: string | null | undefined; /** * User-provided speculation. * * @remarks * * It is useful for situations like partial text rewriting when the caller has a strong guess of what the generation might look like. This speculative guess can be used by Fireworks to speed up the response considerably. * * The speculation is always validated using deterministic (greedy) generation. I.e., the server will find the longest prefix of the "speculation" field that matches the model's generation with temperature=0. After that, it will proceed with normal generation respecting request parameters, including the temperature. */ speculation?: string | null | undefined; minP?: number | undefined; typicalP?: number | undefined; repetitionPenalty?: number | undefined; topLogprobs?: number | null | undefined; echoLast?: number | null | undefined; mirostatTarget?: number | null | undefined; mirostatLr?: number | undefined; minTokens?: number | undefined; ignoreEos?: boolean | undefined; promptCacheMaxLen?: number | null | undefined; rawOutput?: boolean | undefined; logitBias?: { [k: string]: number } | undefined; forcedGeneration?: string | null | undefined; getLastActivation?: boolean | undefined; }; export type CreateCompletionResponse1 = | CreateCompletionResponse | EventStream; /** @internal */ export const Prompt$inboundSchema: z.ZodType = z .union([ z.string(), z.array(z.string()), z.array(z.number().int()), z.array(z.array(z.number().int())), ]); /** @internal */ export type Prompt$Outbound = | string | Array | Array | Array>; /** @internal */ export const Prompt$outboundSchema: z.ZodType< Prompt$Outbound, z.ZodTypeDef, Prompt > = z.union([ z.string(), z.array(z.string()), z.array(z.number().int()), z.array(z.array(z.number().int())), ]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace Prompt$ { /** @deprecated use `Prompt$inboundSchema` instead. */ export const inboundSchema = Prompt$inboundSchema; /** @deprecated use `Prompt$outboundSchema` instead. */ export const outboundSchema = Prompt$outboundSchema; /** @deprecated use `Prompt$Outbound` instead. */ export type Outbound = Prompt$Outbound; } export function promptToJSON(prompt: Prompt): string { return JSON.stringify(Prompt$outboundSchema.parse(prompt)); } export function promptFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Prompt$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Prompt' from JSON`, ); } /** @internal */ export const CreateCompletionLogprobs$inboundSchema: z.ZodType< CreateCompletionLogprobs, z.ZodTypeDef, unknown > = z.union([z.number().int(), z.boolean()]); /** @internal */ export type CreateCompletionLogprobs$Outbound = number | boolean; /** @internal */ export const CreateCompletionLogprobs$outboundSchema: z.ZodType< CreateCompletionLogprobs$Outbound, z.ZodTypeDef, CreateCompletionLogprobs > = z.union([z.number().int(), z.boolean()]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace CreateCompletionLogprobs$ { /** @deprecated use `CreateCompletionLogprobs$inboundSchema` instead. */ export const inboundSchema = CreateCompletionLogprobs$inboundSchema; /** @deprecated use `CreateCompletionLogprobs$outboundSchema` instead. */ export const outboundSchema = CreateCompletionLogprobs$outboundSchema; /** @deprecated use `CreateCompletionLogprobs$Outbound` instead. */ export type Outbound = CreateCompletionLogprobs$Outbound; } export function createCompletionLogprobsToJSON( createCompletionLogprobs: CreateCompletionLogprobs, ): string { return JSON.stringify( CreateCompletionLogprobs$outboundSchema.parse(createCompletionLogprobs), ); } export function createCompletionLogprobsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateCompletionLogprobs$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateCompletionLogprobs' from JSON`, ); } /** @internal */ export const CreateCompletionStop$inboundSchema: z.ZodType< CreateCompletionStop, z.ZodTypeDef, unknown > = z.union([z.string(), z.array(z.string())]); /** @internal */ export type CreateCompletionStop$Outbound = string | Array; /** @internal */ export const CreateCompletionStop$outboundSchema: z.ZodType< CreateCompletionStop$Outbound, z.ZodTypeDef, CreateCompletionStop > = z.union([z.string(), z.array(z.string())]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace CreateCompletionStop$ { /** @deprecated use `CreateCompletionStop$inboundSchema` instead. */ export const inboundSchema = CreateCompletionStop$inboundSchema; /** @deprecated use `CreateCompletionStop$outboundSchema` instead. */ export const outboundSchema = CreateCompletionStop$outboundSchema; /** @deprecated use `CreateCompletionStop$Outbound` instead. */ export type Outbound = CreateCompletionStop$Outbound; } export function createCompletionStopToJSON( createCompletionStop: CreateCompletionStop, ): string { return JSON.stringify( CreateCompletionStop$outboundSchema.parse(createCompletionStop), ); } export function createCompletionStopFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateCompletionStop$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateCompletionStop' from JSON`, ); } /** @internal */ export const CreateCompletionType$inboundSchema: z.ZodNativeEnum< typeof CreateCompletionType > = z.nativeEnum(CreateCompletionType); /** @internal */ export const CreateCompletionType$outboundSchema: z.ZodNativeEnum< typeof CreateCompletionType > = CreateCompletionType$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace CreateCompletionType$ { /** @deprecated use `CreateCompletionType$inboundSchema` instead. */ export const inboundSchema = CreateCompletionType$inboundSchema; /** @deprecated use `CreateCompletionType$outboundSchema` instead. */ export const outboundSchema = CreateCompletionType$outboundSchema; } /** @internal */ export const CreateCompletionSchemaField$inboundSchema: z.ZodType< CreateCompletionSchemaField, z.ZodTypeDef, unknown > = z.object({}); /** @internal */ export type CreateCompletionSchemaField$Outbound = {}; /** @internal */ export const CreateCompletionSchemaField$outboundSchema: z.ZodType< CreateCompletionSchemaField$Outbound, z.ZodTypeDef, CreateCompletionSchemaField > = z.object({}); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace CreateCompletionSchemaField$ { /** @deprecated use `CreateCompletionSchemaField$inboundSchema` instead. */ export const inboundSchema = CreateCompletionSchemaField$inboundSchema; /** @deprecated use `CreateCompletionSchemaField$outboundSchema` instead. */ export const outboundSchema = CreateCompletionSchemaField$outboundSchema; /** @deprecated use `CreateCompletionSchemaField$Outbound` instead. */ export type Outbound = CreateCompletionSchemaField$Outbound; } export function createCompletionSchemaFieldToJSON( createCompletionSchemaField: CreateCompletionSchemaField, ): string { return JSON.stringify( CreateCompletionSchemaField$outboundSchema.parse( createCompletionSchemaField, ), ); } export function createCompletionSchemaFieldFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateCompletionSchemaField$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateCompletionSchemaField' from JSON`, ); } /** @internal */ export const CreateCompletionResponseFormat$inboundSchema: z.ZodType< CreateCompletionResponseFormat, z.ZodTypeDef, unknown > = z.object({ type: z.nullable(CreateCompletionType$inboundSchema.default("text")), schema_field: z.nullable( z.lazy(() => CreateCompletionSchemaField$inboundSchema), ).optional(), grammar: z.nullable(z.string()).default(null), }).transform((v) => { return remap$(v, { "schema_field": "schemaField", }); }); /** @internal */ export type CreateCompletionResponseFormat$Outbound = { type: string | null; schema_field?: CreateCompletionSchemaField$Outbound | null | undefined; grammar: string | null; }; /** @internal */ export const CreateCompletionResponseFormat$outboundSchema: z.ZodType< CreateCompletionResponseFormat$Outbound, z.ZodTypeDef, CreateCompletionResponseFormat > = z.object({ type: z.nullable(CreateCompletionType$outboundSchema.default("text")), schemaField: z.nullable( z.lazy(() => CreateCompletionSchemaField$outboundSchema), ).optional(), grammar: z.nullable(z.string()).default(null), }).transform((v) => { return remap$(v, { schemaField: "schema_field", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace CreateCompletionResponseFormat$ { /** @deprecated use `CreateCompletionResponseFormat$inboundSchema` instead. */ export const inboundSchema = CreateCompletionResponseFormat$inboundSchema; /** @deprecated use `CreateCompletionResponseFormat$outboundSchema` instead. */ export const outboundSchema = CreateCompletionResponseFormat$outboundSchema; /** @deprecated use `CreateCompletionResponseFormat$Outbound` instead. */ export type Outbound = CreateCompletionResponseFormat$Outbound; } export function createCompletionResponseFormatToJSON( createCompletionResponseFormat: CreateCompletionResponseFormat, ): string { return JSON.stringify( CreateCompletionResponseFormat$outboundSchema.parse( createCompletionResponseFormat, ), ); } export function createCompletionResponseFormatFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateCompletionResponseFormat$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateCompletionResponseFormat' from JSON`, ); } /** @internal */ export const CreateCompletionContextLengthExceededBehavior$inboundSchema: z.ZodNativeEnum = z .nativeEnum(CreateCompletionContextLengthExceededBehavior); /** @internal */ export const CreateCompletionContextLengthExceededBehavior$outboundSchema: z.ZodNativeEnum = CreateCompletionContextLengthExceededBehavior$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace CreateCompletionContextLengthExceededBehavior$ { /** @deprecated use `CreateCompletionContextLengthExceededBehavior$inboundSchema` instead. */ export const inboundSchema = CreateCompletionContextLengthExceededBehavior$inboundSchema; /** @deprecated use `CreateCompletionContextLengthExceededBehavior$outboundSchema` instead. */ export const outboundSchema = CreateCompletionContextLengthExceededBehavior$outboundSchema; } /** @internal */ export const CreateCompletionRequestBody$inboundSchema: z.ZodType< CreateCompletionRequestBody, z.ZodTypeDef, unknown > = z.object({ model: z.string(), prompt: z.union([ z.string(), z.array(z.string()), z.array(z.number().int()), z.array(z.array(z.number().int())), ]), images: z.array(z.string()).optional(), max_tokens: z.nullable(z.number().int().default(16)), logprobs: z.nullable(z.union([z.number().int(), z.boolean()])).optional(), echo: z.boolean().default(false), temperature: z.nullable(z.number().default(1)), top_p: z.nullable(z.number().default(1)), top_k: z.nullable(z.number().int()).optional(), frequency_penalty: z.nullable(z.number().default(0)), presence_penalty: z.nullable(z.number().default(0)), n: z.nullable(z.number().int().default(1)), stop: z.nullable(z.union([z.string(), z.array(z.string())])).optional(), response_format: z.nullable( z.lazy(() => CreateCompletionResponseFormat$inboundSchema), ).optional(), stream: z.nullable(z.boolean().default(false)), context_length_exceeded_behavior: CreateCompletionContextLengthExceededBehavior$inboundSchema.optional(), user: z.nullable(z.string()).optional(), speculation: z.nullable(z.string()).optional(), min_p: z.number().default(0), typical_p: z.number().default(1), repetition_penalty: z.number().default(1), top_logprobs: z.nullable(z.number().int()).optional(), echo_last: z.nullable(z.number().int()).optional(), mirostat_target: z.nullable(z.number()).optional(), mirostat_lr: z.number().default(0), min_tokens: z.number().int().default(0), ignore_eos: z.boolean().default(false), prompt_cache_max_len: z.nullable(z.number().int()).optional(), raw_output: z.boolean().default(false), logit_bias: z.record(z.number()).optional(), forced_generation: z.nullable(z.string()).optional(), get_last_activation: z.boolean().default(false), }).transform((v) => { return remap$(v, { "max_tokens": "maxTokens", "top_p": "topP", "top_k": "topK", "frequency_penalty": "frequencyPenalty", "presence_penalty": "presencePenalty", "response_format": "responseFormat", "context_length_exceeded_behavior": "contextLengthExceededBehavior", "min_p": "minP", "typical_p": "typicalP", "repetition_penalty": "repetitionPenalty", "top_logprobs": "topLogprobs", "echo_last": "echoLast", "mirostat_target": "mirostatTarget", "mirostat_lr": "mirostatLr", "min_tokens": "minTokens", "ignore_eos": "ignoreEos", "prompt_cache_max_len": "promptCacheMaxLen", "raw_output": "rawOutput", "logit_bias": "logitBias", "forced_generation": "forcedGeneration", "get_last_activation": "getLastActivation", }); }); /** @internal */ export type CreateCompletionRequestBody$Outbound = { model: string; prompt: string | Array | Array | Array>; images?: Array | undefined; max_tokens: number | null; logprobs?: number | boolean | null | undefined; echo: boolean; temperature: number | null; top_p: number | null; top_k?: number | null | undefined; frequency_penalty: number | null; presence_penalty: number | null; n: number | null; stop?: string | Array | null | undefined; response_format?: CreateCompletionResponseFormat$Outbound | null | undefined; stream: boolean | null; context_length_exceeded_behavior?: string | undefined; user?: string | null | undefined; speculation?: string | null | undefined; min_p: number; typical_p: number; repetition_penalty: number; top_logprobs?: number | null | undefined; echo_last?: number | null | undefined; mirostat_target?: number | null | undefined; mirostat_lr: number; min_tokens: number; ignore_eos: boolean; prompt_cache_max_len?: number | null | undefined; raw_output: boolean; logit_bias?: { [k: string]: number } | undefined; forced_generation?: string | null | undefined; get_last_activation: boolean; }; /** @internal */ export const CreateCompletionRequestBody$outboundSchema: z.ZodType< CreateCompletionRequestBody$Outbound, z.ZodTypeDef, CreateCompletionRequestBody > = z.object({ model: z.string(), prompt: z.union([ z.string(), z.array(z.string()), z.array(z.number().int()), z.array(z.array(z.number().int())), ]), images: z.array(z.string()).optional(), maxTokens: z.nullable(z.number().int().default(16)), logprobs: z.nullable(z.union([z.number().int(), z.boolean()])).optional(), echo: z.boolean().default(false), temperature: z.nullable(z.number().default(1)), topP: z.nullable(z.number().default(1)), topK: z.nullable(z.number().int()).optional(), frequencyPenalty: z.nullable(z.number().default(0)), presencePenalty: z.nullable(z.number().default(0)), n: z.nullable(z.number().int().default(1)), stop: z.nullable(z.union([z.string(), z.array(z.string())])).optional(), responseFormat: z.nullable( z.lazy(() => CreateCompletionResponseFormat$outboundSchema), ).optional(), stream: z.nullable(z.boolean().default(false)), contextLengthExceededBehavior: CreateCompletionContextLengthExceededBehavior$outboundSchema.optional(), user: z.nullable(z.string()).optional(), speculation: z.nullable(z.string()).optional(), minP: z.number().default(0), typicalP: z.number().default(1), repetitionPenalty: z.number().default(1), topLogprobs: z.nullable(z.number().int()).optional(), echoLast: z.nullable(z.number().int()).optional(), mirostatTarget: z.nullable(z.number()).optional(), mirostatLr: z.number().default(0), minTokens: z.number().int().default(0), ignoreEos: z.boolean().default(false), promptCacheMaxLen: z.nullable(z.number().int()).optional(), rawOutput: z.boolean().default(false), logitBias: z.record(z.number()).optional(), forcedGeneration: z.nullable(z.string()).optional(), getLastActivation: z.boolean().default(false), }).transform((v) => { return remap$(v, { maxTokens: "max_tokens", topP: "top_p", topK: "top_k", frequencyPenalty: "frequency_penalty", presencePenalty: "presence_penalty", responseFormat: "response_format", contextLengthExceededBehavior: "context_length_exceeded_behavior", minP: "min_p", typicalP: "typical_p", repetitionPenalty: "repetition_penalty", topLogprobs: "top_logprobs", echoLast: "echo_last", mirostatTarget: "mirostat_target", mirostatLr: "mirostat_lr", minTokens: "min_tokens", ignoreEos: "ignore_eos", promptCacheMaxLen: "prompt_cache_max_len", rawOutput: "raw_output", logitBias: "logit_bias", forcedGeneration: "forced_generation", getLastActivation: "get_last_activation", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace CreateCompletionRequestBody$ { /** @deprecated use `CreateCompletionRequestBody$inboundSchema` instead. */ export const inboundSchema = CreateCompletionRequestBody$inboundSchema; /** @deprecated use `CreateCompletionRequestBody$outboundSchema` instead. */ export const outboundSchema = CreateCompletionRequestBody$outboundSchema; /** @deprecated use `CreateCompletionRequestBody$Outbound` instead. */ export type Outbound = CreateCompletionRequestBody$Outbound; } export function createCompletionRequestBodyToJSON( createCompletionRequestBody: CreateCompletionRequestBody, ): string { return JSON.stringify( CreateCompletionRequestBody$outboundSchema.parse( createCompletionRequestBody, ), ); } export function createCompletionRequestBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateCompletionRequestBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateCompletionRequestBody' from JSON`, ); } /** @internal */ export const CreateCompletionResponse1$inboundSchema: z.ZodType< CreateCompletionResponse1, z.ZodTypeDef, unknown > = z.union([ CreateCompletionResponse$inboundSchema, z.instanceof(ReadableStream).transform(stream => { return new EventStream({ stream, decoder(rawEvent) { const schema = CreateCompletionResponseStream$inboundSchema; return schema.parse(rawEvent); }, }); }), ]); /** @internal */ export type CreateCompletionResponse1$Outbound = | CreateCompletionResponse$Outbound | never; /** @internal */ export const CreateCompletionResponse1$outboundSchema: z.ZodType< CreateCompletionResponse1$Outbound, z.ZodTypeDef, CreateCompletionResponse1 > = z.union([CreateCompletionResponse$outboundSchema, z.never()]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace CreateCompletionResponse1$ { /** @deprecated use `CreateCompletionResponse1$inboundSchema` instead. */ export const inboundSchema = CreateCompletionResponse1$inboundSchema; /** @deprecated use `CreateCompletionResponse1$outboundSchema` instead. */ export const outboundSchema = CreateCompletionResponse1$outboundSchema; /** @deprecated use `CreateCompletionResponse1$Outbound` instead. */ export type Outbound = CreateCompletionResponse1$Outbound; } export function createCompletionResponse1ToJSON( createCompletionResponse1: CreateCompletionResponse1, ): string { return JSON.stringify( CreateCompletionResponse1$outboundSchema.parse(createCompletionResponse1), ); } export function createCompletionResponse1FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateCompletionResponse1$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateCompletionResponse1' from JSON`, ); }