|
import { z } from "zod"; |
|
import { |
|
embeddingEndpointTei, |
|
embeddingEndpointTeiParametersSchema, |
|
} from "./tei/embeddingEndpoints"; |
|
import { |
|
embeddingEndpointTransformersJS, |
|
embeddingEndpointTransformersJSParametersSchema, |
|
} from "./transformersjs/embeddingEndpoints"; |
|
|
|
|
|
interface EmbeddingEndpointParameters { |
|
inputs: string[]; |
|
} |
|
|
|
export type Embedding = number[]; |
|
|
|
|
|
export type EmbeddingEndpoint = (params: EmbeddingEndpointParameters) => Promise<Embedding[]>; |
|
|
|
export const embeddingEndpointSchema = z.discriminatedUnion("type", [ |
|
embeddingEndpointTeiParametersSchema, |
|
embeddingEndpointTransformersJSParametersSchema, |
|
]); |
|
|
|
type EmbeddingEndpointTypeOptions = z.infer<typeof embeddingEndpointSchema>["type"]; |
|
|
|
|
|
export type EmbeddingEndpointGenerator<T extends EmbeddingEndpointTypeOptions> = ( |
|
inputs: Extract<z.infer<typeof embeddingEndpointSchema>, { type: T }> |
|
) => EmbeddingEndpoint | Promise<EmbeddingEndpoint>; |
|
|
|
|
|
export const embeddingEndpoints: { |
|
[Key in EmbeddingEndpointTypeOptions]: EmbeddingEndpointGenerator<Key>; |
|
} = { |
|
tei: embeddingEndpointTei, |
|
transformersjs: embeddingEndpointTransformersJS, |
|
}; |
|
|
|
export default embeddingEndpoints; |
|
|