/* * 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 { ChatCompletionMessageToolCall, ChatCompletionMessageToolCall$inboundSchema, ChatCompletionMessageToolCall$Outbound, ChatCompletionMessageToolCall$outboundSchema, } from "./chatcompletionmessagetoolcall.js"; import { ChatCompletionMessageToolCallFunction, ChatCompletionMessageToolCallFunction$inboundSchema, ChatCompletionMessageToolCallFunction$Outbound, ChatCompletionMessageToolCallFunction$outboundSchema, } from "./chatcompletionmessagetoolcallfunction.js"; import { ChatMessageResponseContent, ChatMessageResponseContent$inboundSchema, ChatMessageResponseContent$Outbound, ChatMessageResponseContent$outboundSchema, } from "./chatmessageresponsecontent.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; /** * The role of the author of this message. */ export const ChatCompletionResponseMessageRole = { System: "system", User: "user", Assistant: "assistant", } as const; /** * The role of the author of this message. */ export type ChatCompletionResponseMessageRole = ClosedEnum< typeof ChatCompletionResponseMessageRole >; /** * The contents of the message. */ export type ChatCompletionResponseMessageContent = | string | Array; export type ChatCompletionResponseMessage = { /** * The role of the author of this message. */ role: ChatCompletionResponseMessageRole; /** * The contents of the message. */ content?: string | Array | null | undefined; /** * The tool calls generated by the model, such as function calls. */ toolCalls?: Array | undefined; /** * An identifier for the tool call. */ toolCallId?: string | undefined; function?: ChatCompletionMessageToolCallFunction | undefined; /** * Unused field for OpenAI compatibility. */ name?: string | null | undefined; }; /** @internal */ export const ChatCompletionResponseMessageRole$inboundSchema: z.ZodNativeEnum< typeof ChatCompletionResponseMessageRole > = z.nativeEnum(ChatCompletionResponseMessageRole); /** @internal */ export const ChatCompletionResponseMessageRole$outboundSchema: z.ZodNativeEnum< typeof ChatCompletionResponseMessageRole > = ChatCompletionResponseMessageRole$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace ChatCompletionResponseMessageRole$ { /** @deprecated use `ChatCompletionResponseMessageRole$inboundSchema` instead. */ export const inboundSchema = ChatCompletionResponseMessageRole$inboundSchema; /** @deprecated use `ChatCompletionResponseMessageRole$outboundSchema` instead. */ export const outboundSchema = ChatCompletionResponseMessageRole$outboundSchema; } /** @internal */ export const ChatCompletionResponseMessageContent$inboundSchema: z.ZodType< ChatCompletionResponseMessageContent, z.ZodTypeDef, unknown > = z.union([z.string(), z.array(ChatMessageResponseContent$inboundSchema)]); /** @internal */ export type ChatCompletionResponseMessageContent$Outbound = | string | Array; /** @internal */ export const ChatCompletionResponseMessageContent$outboundSchema: z.ZodType< ChatCompletionResponseMessageContent$Outbound, z.ZodTypeDef, ChatCompletionResponseMessageContent > = z.union([z.string(), z.array(ChatMessageResponseContent$outboundSchema)]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace ChatCompletionResponseMessageContent$ { /** @deprecated use `ChatCompletionResponseMessageContent$inboundSchema` instead. */ export const inboundSchema = ChatCompletionResponseMessageContent$inboundSchema; /** @deprecated use `ChatCompletionResponseMessageContent$outboundSchema` instead. */ export const outboundSchema = ChatCompletionResponseMessageContent$outboundSchema; /** @deprecated use `ChatCompletionResponseMessageContent$Outbound` instead. */ export type Outbound = ChatCompletionResponseMessageContent$Outbound; } export function chatCompletionResponseMessageContentToJSON( chatCompletionResponseMessageContent: ChatCompletionResponseMessageContent, ): string { return JSON.stringify( ChatCompletionResponseMessageContent$outboundSchema.parse( chatCompletionResponseMessageContent, ), ); } export function chatCompletionResponseMessageContentFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ChatCompletionResponseMessageContent$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ChatCompletionResponseMessageContent' from JSON`, ); } /** @internal */ export const ChatCompletionResponseMessage$inboundSchema: z.ZodType< ChatCompletionResponseMessage, z.ZodTypeDef, unknown > = z.object({ role: ChatCompletionResponseMessageRole$inboundSchema, content: z.nullable( z.union([z.string(), z.array(ChatMessageResponseContent$inboundSchema)]), ).optional(), tool_calls: z.array(ChatCompletionMessageToolCall$inboundSchema).optional(), tool_call_id: z.string().optional(), function: ChatCompletionMessageToolCallFunction$inboundSchema.optional(), name: z.nullable(z.string()).optional(), }).transform((v) => { return remap$(v, { "tool_calls": "toolCalls", "tool_call_id": "toolCallId", }); }); /** @internal */ export type ChatCompletionResponseMessage$Outbound = { role: string; content?: | string | Array | null | undefined; tool_calls?: Array | undefined; tool_call_id?: string | undefined; function?: ChatCompletionMessageToolCallFunction$Outbound | undefined; name?: string | null | undefined; }; /** @internal */ export const ChatCompletionResponseMessage$outboundSchema: z.ZodType< ChatCompletionResponseMessage$Outbound, z.ZodTypeDef, ChatCompletionResponseMessage > = z.object({ role: ChatCompletionResponseMessageRole$outboundSchema, content: z.nullable( z.union([z.string(), z.array(ChatMessageResponseContent$outboundSchema)]), ).optional(), toolCalls: z.array(ChatCompletionMessageToolCall$outboundSchema).optional(), toolCallId: z.string().optional(), function: ChatCompletionMessageToolCallFunction$outboundSchema.optional(), name: z.nullable(z.string()).optional(), }).transform((v) => { return remap$(v, { toolCalls: "tool_calls", toolCallId: "tool_call_id", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace ChatCompletionResponseMessage$ { /** @deprecated use `ChatCompletionResponseMessage$inboundSchema` instead. */ export const inboundSchema = ChatCompletionResponseMessage$inboundSchema; /** @deprecated use `ChatCompletionResponseMessage$outboundSchema` instead. */ export const outboundSchema = ChatCompletionResponseMessage$outboundSchema; /** @deprecated use `ChatCompletionResponseMessage$Outbound` instead. */ export type Outbound = ChatCompletionResponseMessage$Outbound; } export function chatCompletionResponseMessageToJSON( chatCompletionResponseMessage: ChatCompletionResponseMessage, ): string { return JSON.stringify( ChatCompletionResponseMessage$outboundSchema.parse( chatCompletionResponseMessage, ), ); } export function chatCompletionResponseMessageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ChatCompletionResponseMessage$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ChatCompletionResponseMessage' from JSON`, ); }