import {z} from 'zod' export type GoogleCloudAiplatformV1Tensor = {boolVal?: Array | undefined, bytesVal?: Array | undefined, doubleVal?: Array | undefined, dtype?: ('DATA_TYPE_UNSPECIFIED' | 'BOOL' | 'STRING' | 'FLOAT' | 'DOUBLE' | 'INT8' | 'INT16' | 'INT32' | 'INT64' | 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64') | undefined, floatVal?: Array | undefined, int64Val?: Array | undefined, intVal?: Array | undefined, listVal?: Array | undefined, shape?: Array | undefined, stringVal?: Array | undefined, structVal?: {[key: string]: GoogleCloudAiplatformV1Tensor} | undefined, tensorVal?: string | undefined, uint64Val?: Array | undefined, uintVal?: Array | undefined}; export type GoogleCloudAiplatformV1StreamingPredictRequest = {inputs?: Array | undefined, parameters?: GoogleCloudAiplatformV1Tensor | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdEndpointsEndpointsIdServerStreamingPredictArgs = {projectsId: string, locationsId: string, endpointsId: string, body: GoogleCloudAiplatformV1StreamingPredictRequest}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdEndpointsEndpointsIdServerStreamingPredictOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleCloudAiplatformV1Tensor: z.ZodType = z.object({boolVal: z.array(z.boolean()).optional(), bytesVal: z.array(z.string()).optional(), doubleVal: z.array(z.number()).optional(), dtype: z.enum(["DATA_TYPE_UNSPECIFIED", "BOOL", "STRING", "FLOAT", "DOUBLE", "INT8", "INT16", "INT32", "INT64", "UINT8", "UINT16", "UINT32", "UINT64"]).optional(), floatVal: z.array(z.number()).optional(), int64Val: z.array(z.string()).optional(), intVal: z.array(z.number().int()).optional(), listVal: z.array(z.lazy(() => googleCloudAiplatformV1Tensor)).optional(), shape: z.array(z.string()).optional(), stringVal: z.array(z.string()).optional(), structVal: z.record(z.string(), z.lazy(() => googleCloudAiplatformV1Tensor)).optional(), tensorVal: z.string().optional(), uint64Val: z.array(z.string()).optional(), uintVal: z.array(z.number().int()).optional()}); export const googleCloudAiplatformV1StreamingPredictResponse = z.object({outputs: z.array(googleCloudAiplatformV1Tensor).optional(), parameters: googleCloudAiplatformV1Tensor.optional()}); 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 }; /** * Perform a server-side streaming online prediction request for Vertex LLM streaming. * * POST /v1/projects/{projectsId}/locations/{locationsId}/endpoints/{endpointsId}:serverStreamingPredict * * Also accepts auth: Oauth2 + Oauth2c, Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdEndpointsEndpointsIdServerStreamingPredict = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdEndpointsEndpointsIdServerStreamingPredictArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdEndpointsEndpointsIdServerStreamingPredictOptions) => { const {baseUrl = "https://aiplatform.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/endpoints/${encodeURIComponent(String(args.endpointsId))}:serverStreamingPredict${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(googleCloudAiplatformV1StreamingPredictResponse, await res.json()) };