@retrivora-ai/rag-engine 2.1.1 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handlers/index.js +106 -76
- package/dist/handlers/index.mjs +106 -76
- package/dist/server.js +106 -76
- package/dist/server.mjs +106 -76
- package/package.json +1 -1
- package/src/config/serverConfig.ts +5 -5
- package/src/llm/providers/UniversalLLMAdapter.ts +40 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retrivora-ai/rag-engine",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Retrivora AI is a plug-and-play AI engine for RAG chat experiences — generic vector DB + LLM provider, embeddable or standalone.",
|
|
5
5
|
"author": "Abhinav Alkuchi",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -171,20 +171,20 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
|
|
|
171
171
|
}
|
|
172
172
|
})();
|
|
173
173
|
|
|
174
|
-
const
|
|
174
|
+
const defaultGatewayUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? 'https://llm.retrivora.com/api/v1';
|
|
175
175
|
|
|
176
176
|
const defaultLlmProvider = isFreeTier ? 'universal_rest' : 'universal_rest';
|
|
177
177
|
const llmProvider = (readEnum(env, 'LLM_PROVIDER', defaultLlmProvider, LLM_PROVIDERS) ?? base?.llm?.provider ?? defaultLlmProvider) as LLMProvider;
|
|
178
|
-
const llmBaseUrl = readString(env, 'LLM_BASE_URL') ?? base?.llm?.baseUrl ??
|
|
178
|
+
const llmBaseUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? base?.llm?.baseUrl ?? defaultGatewayUrl;
|
|
179
179
|
const llmModel = readString(env, 'LLM_MODEL') ?? base?.llm?.model ?? (isFreeTier ? 'llama-3.1-8b-instant' : (DEFAULT_MODEL_BY_PROVIDER[llmProvider] ?? 'gpt-4o'));
|
|
180
|
-
const llmApiKey = llmApiKeyByProvider[llmProvider] ?? readString(env, 'LLM_API_KEY') ?? base?.llm?.apiKey ??
|
|
180
|
+
const llmApiKey = llmApiKeyByProvider[llmProvider] ?? readString(env, 'LLM_API_KEY') ?? readString(env, 'LITELLM_MASTER_KEY') ?? readString(env, 'LITELLM_API_KEY') ?? base?.llm?.apiKey ?? licenseKey;
|
|
181
181
|
const llmProfile = readString(env, 'LLM_UNIVERSAL_PROFILE') ?? (base?.llm?.options?.profile as string) ?? 'litellm';
|
|
182
182
|
|
|
183
183
|
const defaultEmbeddingProvider = isFreeTier ? 'universal_rest' : 'universal_rest';
|
|
184
184
|
const embeddingProvider = (readEnum(env, 'EMBEDDING_PROVIDER', defaultEmbeddingProvider, EMBEDDING_PROVIDERS) ?? base?.embedding?.provider ?? defaultEmbeddingProvider) as EmbeddingProvider;
|
|
185
|
-
const embeddingBaseUrl = readString(env, 'EMBEDDING_BASE_URL') ?? base?.embedding?.baseUrl ??
|
|
185
|
+
const embeddingBaseUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'EMBEDDING_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? base?.embedding?.baseUrl ?? defaultGatewayUrl;
|
|
186
186
|
const embeddingModel = readString(env, 'EMBEDDING_MODEL') ?? base?.embedding?.model ?? 'text-embedding-004';
|
|
187
|
-
const embeddingApiKey = embeddingApiKeyByProvider[embeddingProvider] ?? readString(env, 'EMBEDDING_API_KEY') ?? readString(env, 'LLM_API_KEY') ?? base?.embedding?.apiKey ??
|
|
187
|
+
const embeddingApiKey = embeddingApiKeyByProvider[embeddingProvider] ?? readString(env, 'EMBEDDING_API_KEY') ?? readString(env, 'LLM_API_KEY') ?? readString(env, 'LITELLM_MASTER_KEY') ?? readString(env, 'LITELLM_API_KEY') ?? base?.embedding?.apiKey ?? licenseKey;
|
|
188
188
|
const embeddingProfile = readString(env, 'EMBEDDING_UNIVERSAL_PROFILE') ?? (base?.embedding?.options?.profile as string) ?? 'litellm';
|
|
189
189
|
|
|
190
190
|
return {
|
|
@@ -112,8 +112,17 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
// Try direct HTTP POST request to llm.retrivora.com first
|
|
116
|
+
try {
|
|
117
|
+
const { data } = await this.http.post(path, payload);
|
|
118
|
+
const extractPath = this.opts.responseExtractPath ?? 'choices[0].message.content';
|
|
119
|
+
const result = resolvePath(data, extractPath) ?? extractContent(data);
|
|
120
|
+
if (result !== undefined) {
|
|
121
|
+
return String(result);
|
|
122
|
+
}
|
|
123
|
+
} catch (httpErr: any) {
|
|
124
|
+
console.warn(`[UniversalLLMAdapter] Direct HTTP POST to ${this.baseUrl}${path} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
|
|
125
|
+
|
|
117
126
|
const _g = globalThis as any;
|
|
118
127
|
let dispatch = _g.__retrivoraDispatchChat;
|
|
119
128
|
if (typeof dispatch !== 'function') {
|
|
@@ -128,25 +137,19 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
if (typeof dispatch === 'function') {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return content;
|
|
142
|
-
}
|
|
143
|
-
throw new Error(`[UniversalLLMAdapter] In-process dispatch returned empty content for model: ${this.model}`);
|
|
144
|
-
} catch (dispatchErr) {
|
|
145
|
-
throw dispatchErr;
|
|
140
|
+
const res = await dispatch({
|
|
141
|
+
model: this.model,
|
|
142
|
+
messages: formattedMessages as any,
|
|
143
|
+
max_tokens: this.maxTokens,
|
|
144
|
+
temperature: this.temperature,
|
|
145
|
+
}, this.apiKey);
|
|
146
|
+
|
|
147
|
+
const content = extractContent(res?.response);
|
|
148
|
+
if (content !== undefined) {
|
|
149
|
+
return content;
|
|
146
150
|
}
|
|
147
|
-
} else {
|
|
148
|
-
throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
|
|
149
151
|
}
|
|
152
|
+
throw httpErr;
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
const { data } = await this.http.post(path, payload);
|
|
@@ -328,8 +331,17 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
328
331
|
};
|
|
329
332
|
}
|
|
330
333
|
|
|
331
|
-
|
|
332
|
-
|
|
334
|
+
// Try direct HTTP POST request to llm.retrivora.com first
|
|
335
|
+
try {
|
|
336
|
+
const { data } = await this.http.post(path, payload);
|
|
337
|
+
const extractPath = this.opts.embedExtractPath ?? 'data[0].embedding';
|
|
338
|
+
const vector = resolvePath(data, extractPath);
|
|
339
|
+
if (Array.isArray(vector)) {
|
|
340
|
+
return vector as number[];
|
|
341
|
+
}
|
|
342
|
+
} catch (httpErr: any) {
|
|
343
|
+
console.warn(`[UniversalLLMAdapter] Direct HTTP embedding POST to ${this.baseUrl}${path} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
|
|
344
|
+
|
|
333
345
|
const _g = globalThis as any;
|
|
334
346
|
let dispatch = _g.__retrivoraDispatchEmbedding;
|
|
335
347
|
if (typeof dispatch !== 'function') {
|
|
@@ -344,22 +356,16 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
344
356
|
}
|
|
345
357
|
|
|
346
358
|
if (typeof dispatch === 'function') {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}, this.apiKey);
|
|
359
|
+
const res = await dispatch({
|
|
360
|
+
model: this.model,
|
|
361
|
+
input: text,
|
|
362
|
+
}, this.apiKey);
|
|
352
363
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
throw new Error(`[UniversalLLMAdapter] In-process embedding dispatch returned invalid vector for model: ${this.model}`);
|
|
357
|
-
} catch (dispatchErr) {
|
|
358
|
-
throw dispatchErr;
|
|
364
|
+
if (res?.data?.[0]?.embedding) {
|
|
365
|
+
return res.data[0].embedding;
|
|
359
366
|
}
|
|
360
|
-
} else {
|
|
361
|
-
throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
|
|
362
367
|
}
|
|
368
|
+
throw httpErr;
|
|
363
369
|
}
|
|
364
370
|
|
|
365
371
|
const { data } = await this.http.post(path, payload);
|