import {z} from 'zod' export type GetApiModelsModelNameArgs = {'X-Pinecone-Api-Version': string, model_name: string}; export type GetApiModelsModelNameOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const inferenceModelInfoMetric = z.string(); export const inferenceModelInfoSupportedMetrics = z.array(inferenceModelInfoMetric); export const inferenceModelInfoSupportedParameter = z.object({parameter: z.string(), type: z.string(), value_type: z.string(), required: z.boolean(), allowed_values: z.array(z.union([z.string(), z.number().int()])).optional(), min: z.number().optional(), max: z.number().optional(), default: z.union([z.string(), z.number().int(), z.number(), z.boolean()]).optional()}); export const inferenceModelInfo = z.object({model: z.string(), short_description: z.string(), type: z.string(), vector_type: z.string().optional(), default_dimension: z.number().int().gte(1).lte(20000).optional(), modality: z.string().optional(), max_sequence_length: z.number().int().gte(1).optional(), max_batch_size: z.number().int().gte(1).optional(), provider_name: z.string().optional(), supported_dimensions: z.array(z.number().int().gte(1).lte(20000)).optional(), supported_metrics: inferenceModelInfoSupportedMetrics.optional(), supported_parameters: z.array(inferenceModelInfoSupportedParameter)}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Describe a model * * GET /models/{model_name} */ export const getApiModelsModelName = async (args: GetApiModelsModelNameArgs, options?: GetApiModelsModelNameOptions) => { const {baseUrl = "https://api.pinecone.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Pinecone-Api-Version'] != null) headers.set("X-Pinecone-Api-Version", String(args['X-Pinecone-Api-Version'])) if (ApiKeyAuth !== undefined) headers.set("Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/models/${encodeURIComponent(String(args.model_name))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(inferenceModelInfo, await res.json()) };