UNPKG

@axflow/models

Version:

Zero-dependency, modular SDK for building robust natural language applications

51 lines (48 loc) 1.8 kB
type SharedRequestOptions = { apiKey?: string; apiUrl?: string; fetch?: typeof fetch; headers?: Record<string, string>; signal?: AbortSignal; }; declare namespace OpenAIEmbeddingTypes { type RequestOptions = SharedRequestOptions; type Request = { input: string | Array<string> | Array<number> | Array<Array<number>>; model: string; user?: string; }; type EmbeddingObject = { index: number; object: 'embedding'; embedding: number[]; }; type Response = { object: 'list'; data: EmbeddingObject[]; model: string; usage: { prompt_tokens: number; total_tokens: number; }; }; } /** * Calculate text embeddings using the OpenAI API. * * @see https://platform.openai.com/docs/api-reference/embeddings * * @param request The request body sent to OpenAI. See OpenAI's documentation for /v1/embeddings for supported parameters. * @param options * @param options.apiKey OpenAI API key. * @param options.apiUrl The url of the OpenAI (or compatible) API. Defaults to https://api.openai.com/v1/embeddings. * @param options.fetch A custom implementation of fetch. Defaults to globalThis.fetch. * @param options.headers Optionally add additional HTTP headers to the request. * @param options.signal An AbortSignal that can be used to abort the fetch request. * @returns An object consisting of the text embeddings and other metadata. See OpenAI's documentation for /v1/embeddings. */ declare function run(request: OpenAIEmbeddingTypes.Request, options: OpenAIEmbeddingTypes.RequestOptions): Promise<OpenAIEmbeddingTypes.Response>; declare class OpenAIEmbedding { static run: typeof run; } export { OpenAIEmbedding, OpenAIEmbeddingTypes };