UNPKG

@antl3x/toolrag

Version:

Context-aware tool retrieval for language models - unlock the full potential of LLM function calling without context window limitations or constraints.

54 lines 1.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmbeddingProviderOpenAI = void 0; const openai_1 = __importDefault(require("openai")); const zod_1 = require("zod"); const EmbeddingProviderOpenAIConfigSchema = zod_1.z .object({ model: zod_1.z .enum(['text-embedding-3-small', 'text-embedding-3-large']) .default('text-embedding-3-large'), client: zod_1.z.instanceof(openai_1.default).optional(), }) .default({}); /** * OpenAI implementation of the EmbeddingProvider */ class EmbeddingProviderOpenAI { _client; _dimensions; _config; constructor(config) { this._config = EmbeddingProviderOpenAIConfigSchema.parse(config); this._client = this._config.client || new openai_1.default(); // Default dimensions based on model this._dimensions = this._config.model === 'text-embedding-3-small' ? 1536 : this._config.model === 'text-embedding-3-large' ? 3072 : 1536; // Default fallback } async getEmbedding(text) { const response = await this._client.embeddings.create({ model: this._config.model, input: text, dimensions: this._dimensions, }); return response.data[0].embedding; } getDimensions() { return this._dimensions; } getName() { return `openai`; } getModel() { return this._config.model; } } exports.EmbeddingProviderOpenAI = EmbeddingProviderOpenAI; //# sourceMappingURL=EmbeddingProviderOpenAI.js.map