/* * 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 classification result data */ export type ClassificationResponseData = { /** * The label selected by the model from the provided options. This is the classification result. */ label: string; /** * Optional confidence score between 0 and 1 indicating how confident the model is in its classification decision. Higher values indicate higher confidence. */ confidence?: number | undefined; /** * Optional brief explanation from the model explaining why it chose this particular label. Provides transparency into the classification decision. */ reasoning?: string | undefined; }; /** * Metadata about the classification request and execution */ export type Metadata = { /** * The model that was used to perform the classification */ model: string; /** * The array of possible labels that were provided in the request */ labels: Array; /** * ISO 8601 timestamp indicating when the classification was performed */ classifiedAt: string; }; /** * Response from the text classification endpoint containing the classification result, confidence, and metadata. */ export type ClassificationResponse = { /** * Indicates whether the classification request was successful */ success: boolean; /** * The classification result data */ data: ClassificationResponseData; /** * Metadata about the classification request and execution */ metadata: Metadata; }; /** @internal */ export const ClassificationResponseData$inboundSchema: z.ZodType< ClassificationResponseData, z.ZodTypeDef, unknown > = z.object({ label: z.string(), confidence: z.number().optional(), reasoning: z.string().optional(), }); /** @internal */ export type ClassificationResponseData$Outbound = { label: string; confidence?: number | undefined; reasoning?: string | undefined; }; /** @internal */ export const ClassificationResponseData$outboundSchema: z.ZodType< ClassificationResponseData$Outbound, z.ZodTypeDef, ClassificationResponseData > = z.object({ label: z.string(), confidence: z.number().optional(), reasoning: z.string().optional(), }); export function classificationResponseDataToJSON( classificationResponseData: ClassificationResponseData, ): string { return JSON.stringify( ClassificationResponseData$outboundSchema.parse(classificationResponseData), ); } export function classificationResponseDataFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ClassificationResponseData$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ClassificationResponseData' from JSON`, ); } /** @internal */ export const Metadata$inboundSchema: z.ZodType< Metadata, z.ZodTypeDef, unknown > = z.object({ model: z.string(), labels: z.array(z.string()), classifiedAt: z.string(), }); /** @internal */ export type Metadata$Outbound = { model: string; labels: Array; classifiedAt: string; }; /** @internal */ export const Metadata$outboundSchema: z.ZodType< Metadata$Outbound, z.ZodTypeDef, Metadata > = z.object({ model: z.string(), labels: z.array(z.string()), classifiedAt: z.string(), }); export function metadataToJSON(metadata: Metadata): string { return JSON.stringify(Metadata$outboundSchema.parse(metadata)); } export function metadataFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Metadata$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Metadata' from JSON`, ); } /** @internal */ export const ClassificationResponse$inboundSchema: z.ZodType< ClassificationResponse, z.ZodTypeDef, unknown > = z.object({ success: z.boolean(), data: z.lazy(() => ClassificationResponseData$inboundSchema), metadata: z.lazy(() => Metadata$inboundSchema), }); /** @internal */ export type ClassificationResponse$Outbound = { success: boolean; data: ClassificationResponseData$Outbound; metadata: Metadata$Outbound; }; /** @internal */ export const ClassificationResponse$outboundSchema: z.ZodType< ClassificationResponse$Outbound, z.ZodTypeDef, ClassificationResponse > = z.object({ success: z.boolean(), data: z.lazy(() => ClassificationResponseData$outboundSchema), metadata: z.lazy(() => Metadata$outboundSchema), }); export function classificationResponseToJSON( classificationResponse: ClassificationResponse, ): string { return JSON.stringify( ClassificationResponse$outboundSchema.parse(classificationResponse), ); } export function classificationResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ClassificationResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ClassificationResponse' from JSON`, ); }