/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * The function definition */ export type FunctionT = { /** * The name of the function to be called. Must be a-z, A-Z, 0-9, underscores and dashes, with a maximum length of 64 characters. */ name: string; /** * A description of what the function does. Used by the model to choose when and how to call the function. */ description?: string | undefined; /** * The parameters the function accepts, described as a JSON Schema object. Omit to accept no parameters. */ parameters?: any | undefined; }; /** * A tool the model may call while generating a response. */ export type OpenAIToolDefinition = { /** * The type of the tool. Currently only 'function' is supported. */ type: "function"; /** * The function definition */ function: FunctionT; }; /** @internal */ export const FunctionT$inboundSchema: z.ZodType< FunctionT, z.ZodTypeDef, unknown > = z.object({ name: z.string(), description: z.string().optional(), parameters: z.any().optional(), }); /** @internal */ export type FunctionT$Outbound = { name: string; description?: string | undefined; parameters?: any | undefined; }; /** @internal */ export const FunctionT$outboundSchema: z.ZodType< FunctionT$Outbound, z.ZodTypeDef, FunctionT > = z.object({ name: z.string(), description: z.string().optional(), parameters: z.any().optional(), }); export function functionToJSON(functionT: FunctionT): string { return JSON.stringify(FunctionT$outboundSchema.parse(functionT)); } export function functionFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => FunctionT$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'FunctionT' from JSON`, ); } /** @internal */ export const OpenAIToolDefinition$inboundSchema: z.ZodType< OpenAIToolDefinition, z.ZodTypeDef, unknown > = z.object({ type: z.literal("function"), function: z.lazy(() => FunctionT$inboundSchema), }); /** @internal */ export type OpenAIToolDefinition$Outbound = { type: "function"; function: FunctionT$Outbound; }; /** @internal */ export const OpenAIToolDefinition$outboundSchema: z.ZodType< OpenAIToolDefinition$Outbound, z.ZodTypeDef, OpenAIToolDefinition > = z.object({ type: z.literal("function"), function: z.lazy(() => FunctionT$outboundSchema), }); export function openAIToolDefinitionToJSON( openAIToolDefinition: OpenAIToolDefinition, ): string { return JSON.stringify( OpenAIToolDefinition$outboundSchema.parse(openAIToolDefinition), ); } export function openAIToolDefinitionFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIToolDefinition$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIToolDefinition' from JSON`, ); }