UNPKG

ai-utils.js

Version:

Build AI applications, chatbots, and agents with JavaScript and TypeScript.

120 lines (119 loc) 4.23 kB
import z from "zod"; import { AbstractModel } from "../../model-function/AbstractModel.js"; import { FunctionOptions } from "../../model-function/FunctionOptions.js"; import { TextEmbeddingModel, TextEmbeddingModelSettings } from "../../model-function/embed-text/TextEmbeddingModel.js"; import { FullTokenizer } from "../../model-function/tokenize-text/Tokenizer.js"; import { RetryFunction } from "../../util/api/RetryFunction.js"; import { ThrottleFunction } from "../../util/api/ThrottleFunction.js"; export declare const COHERE_TEXT_EMBEDDING_MODELS: { "embed-english-light-v2.0": { contextWindowSize: number; embeddingDimensions: number; }; "embed-english-v2.0": { contextWindowSize: number; embeddingDimensions: number; }; "embed-multilingual-v2.0": { contextWindowSize: number; embeddingDimensions: number; }; }; export type CohereTextEmbeddingModelType = keyof typeof COHERE_TEXT_EMBEDDING_MODELS; export interface CohereTextEmbeddingModelSettings extends TextEmbeddingModelSettings { model: CohereTextEmbeddingModelType; baseUrl?: string; apiKey?: string; retry?: RetryFunction; throttle?: ThrottleFunction; tokenizerSettings?: { retry?: RetryFunction; throttle?: ThrottleFunction; }; truncate?: "NONE" | "START" | "END"; } /** * Create a text embedding model that calls the Cohere Co.Embed API. * * @see https://docs.cohere.com/reference/embed * * @example * const { embeddings } = await embedTexts( * new CohereTextEmbeddingModel({ model: "embed-english-light-v2.0" }), * [ * "At first, Nox didn't know what to do with the pup.", * "He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.", * ] * ); */ export declare class CohereTextEmbeddingModel extends AbstractModel<CohereTextEmbeddingModelSettings> implements TextEmbeddingModel<CohereTextEmbeddingResponse, CohereTextEmbeddingModelSettings>, FullTokenizer { constructor(settings: CohereTextEmbeddingModelSettings); readonly provider: "cohere"; get modelName(): "embed-english-light-v2.0" | "embed-english-v2.0" | "embed-multilingual-v2.0"; readonly maxTextsPerCall = 96; readonly embeddingDimensions: number; readonly contextWindowSize: number; private readonly tokenizer; tokenize(text: string): Promise<number[]>; tokenizeWithTexts(text: string): Promise<{ tokens: number[]; tokenTexts: string[]; }>; detokenize(tokens: number[]): Promise<string>; private get apiKey(); callAPI(texts: Array<string>, options?: FunctionOptions<CohereTextEmbeddingModelSettings>): Promise<CohereTextEmbeddingResponse>; generateEmbeddingResponse(texts: string[], options?: FunctionOptions<CohereTextEmbeddingModelSettings>): Promise<{ texts: string[]; embeddings: number[][]; id: string; meta: { api_version: { version: string; }; }; }>; extractEmbeddings(response: CohereTextEmbeddingResponse): number[][]; withSettings(additionalSettings: Partial<CohereTextEmbeddingModelSettings>): this; } declare const cohereTextEmbeddingResponseSchema: z.ZodObject<{ id: z.ZodString; texts: z.ZodArray<z.ZodString, "many">; embeddings: z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">; meta: z.ZodObject<{ api_version: z.ZodObject<{ version: z.ZodString; }, "strip", z.ZodTypeAny, { version: string; }, { version: string; }>; }, "strip", z.ZodTypeAny, { api_version: { version: string; }; }, { api_version: { version: string; }; }>; }, "strip", z.ZodTypeAny, { texts: string[]; embeddings: number[][]; id: string; meta: { api_version: { version: string; }; }; }, { texts: string[]; embeddings: number[][]; id: string; meta: { api_version: { version: string; }; }; }>; export type CohereTextEmbeddingResponse = z.infer<typeof cohereTextEmbeddingResponseSchema>; export {};