@juspay/neurolink 7.29.2 → 7.29.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/CHANGELOG.md +6 -0
- package/dist/cli/commands/config.d.ts +83 -83
- package/dist/cli/commands/mcp.js +39 -9
- package/dist/cli/commands/models.js +25 -21
- package/dist/cli/commands/ollama.js +2 -2
- package/dist/cli/factories/commandFactory.d.ts +8 -0
- package/dist/cli/factories/commandFactory.js +65 -65
- package/dist/cli/factories/ollamaCommandFactory.js +3 -1
- package/dist/cli/factories/sagemakerCommandFactory.js +3 -2
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +11 -11
- package/dist/cli/utils/envManager.js +5 -5
- package/dist/cli/utils/ollamaUtils.d.ts +12 -0
- package/dist/cli/utils/ollamaUtils.js +58 -42
- package/dist/config/configManager.js +5 -2
- package/dist/core/analytics.d.ts +2 -24
- package/dist/core/analytics.js +12 -17
- package/dist/core/baseProvider.d.ts +30 -1
- package/dist/core/baseProvider.js +180 -198
- package/dist/core/dynamicModels.d.ts +4 -4
- package/dist/core/dynamicModels.js +7 -7
- package/dist/core/evaluation.d.ts +9 -9
- package/dist/core/evaluation.js +117 -65
- package/dist/core/evaluationProviders.d.ts +18 -2
- package/dist/core/evaluationProviders.js +15 -13
- package/dist/core/modelConfiguration.d.ts +63 -0
- package/dist/core/modelConfiguration.js +354 -290
- package/dist/core/streamAnalytics.d.ts +10 -5
- package/dist/core/streamAnalytics.js +10 -10
- package/dist/core/types.d.ts +19 -109
- package/dist/core/types.js +13 -0
- package/dist/factories/providerFactory.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/lib/config/configManager.js +5 -2
- package/dist/lib/core/analytics.d.ts +2 -24
- package/dist/lib/core/analytics.js +12 -17
- package/dist/lib/core/baseProvider.d.ts +30 -1
- package/dist/lib/core/baseProvider.js +180 -198
- package/dist/lib/core/dynamicModels.js +7 -7
- package/dist/lib/core/evaluation.d.ts +9 -9
- package/dist/lib/core/evaluation.js +117 -65
- package/dist/lib/core/evaluationProviders.d.ts +18 -2
- package/dist/lib/core/evaluationProviders.js +15 -13
- package/dist/lib/core/modelConfiguration.d.ts +63 -0
- package/dist/lib/core/modelConfiguration.js +354 -290
- package/dist/lib/core/streamAnalytics.d.ts +10 -5
- package/dist/lib/core/streamAnalytics.js +10 -10
- package/dist/lib/core/types.d.ts +19 -109
- package/dist/lib/core/types.js +13 -0
- package/dist/lib/factories/providerFactory.js +1 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/mcp/externalServerManager.js +15 -6
- package/dist/lib/mcp/factory.js +1 -1
- package/dist/lib/mcp/index.d.ts +1 -1
- package/dist/lib/mcp/index.js +1 -1
- package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/lib/mcp/mcpClientFactory.js +3 -0
- package/dist/lib/mcp/registry.d.ts +3 -3
- package/dist/lib/mcp/registry.js +3 -3
- package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/lib/mcp/toolDiscoveryService.js +8 -2
- package/dist/lib/mcp/toolRegistry.js +4 -4
- package/dist/lib/middleware/builtin/analytics.js +4 -4
- package/dist/lib/middleware/builtin/guardrails.js +2 -2
- package/dist/lib/middleware/registry.js +11 -2
- package/dist/lib/models/modelRegistry.d.ts +1 -1
- package/dist/lib/models/modelRegistry.js +3 -3
- package/dist/lib/models/modelResolver.d.ts +1 -1
- package/dist/lib/models/modelResolver.js +2 -2
- package/dist/lib/neurolink.d.ts +116 -0
- package/dist/lib/neurolink.js +716 -922
- package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
- package/dist/lib/providers/amazonSagemaker.js +12 -3
- package/dist/lib/providers/anthropic.d.ts +1 -1
- package/dist/lib/providers/anthropic.js +7 -6
- package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/lib/providers/anthropicBaseProvider.js +4 -3
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/azureOpenai.js +1 -1
- package/dist/lib/providers/googleAiStudio.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.js +2 -2
- package/dist/lib/providers/googleVertex.d.ts +40 -0
- package/dist/lib/providers/googleVertex.js +330 -274
- package/dist/lib/providers/huggingFace.js +1 -1
- package/dist/lib/providers/mistral.d.ts +1 -1
- package/dist/lib/providers/mistral.js +2 -2
- package/dist/lib/providers/ollama.d.ts +4 -0
- package/dist/lib/providers/ollama.js +38 -18
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +2 -2
- package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/lib/providers/sagemaker/client.js +13 -3
- package/dist/lib/providers/sagemaker/config.js +5 -1
- package/dist/lib/providers/sagemaker/detection.js +19 -9
- package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
- package/dist/lib/providers/sagemaker/errors.js +103 -20
- package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/lib/providers/sagemaker/language-model.js +4 -4
- package/dist/lib/providers/sagemaker/parsers.js +14 -6
- package/dist/lib/providers/sagemaker/streaming.js +14 -3
- package/dist/lib/providers/sagemaker/types.d.ts +1 -1
- package/dist/lib/proxy/awsProxyIntegration.js +1 -1
- package/dist/lib/sdk/toolRegistration.d.ts +1 -1
- package/dist/lib/types/cli.d.ts +80 -8
- package/dist/lib/types/contextTypes.js +2 -2
- package/dist/lib/types/generateTypes.d.ts +4 -6
- package/dist/lib/types/providers.d.ts +81 -19
- package/dist/lib/types/providers.js +6 -6
- package/dist/lib/types/streamTypes.d.ts +4 -6
- package/dist/lib/types/typeAliases.d.ts +1 -1
- package/dist/lib/utils/analyticsUtils.d.ts +33 -0
- package/dist/lib/utils/analyticsUtils.js +76 -0
- package/dist/lib/utils/errorHandling.js +4 -1
- package/dist/lib/utils/evaluationUtils.d.ts +27 -0
- package/dist/lib/utils/evaluationUtils.js +131 -0
- package/dist/lib/utils/optionsUtils.js +10 -1
- package/dist/lib/utils/performance.d.ts +1 -1
- package/dist/lib/utils/performance.js +15 -3
- package/dist/lib/utils/providerHealth.d.ts +48 -0
- package/dist/lib/utils/providerHealth.js +199 -254
- package/dist/lib/utils/providerUtils.js +2 -2
- package/dist/lib/utils/timeout.js +8 -3
- package/dist/mcp/externalServerManager.js +15 -6
- package/dist/mcp/factory.js +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/mcp/mcpClientFactory.js +3 -0
- package/dist/mcp/registry.d.ts +3 -3
- package/dist/mcp/registry.js +3 -3
- package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/mcp/toolDiscoveryService.js +8 -2
- package/dist/mcp/toolRegistry.js +4 -4
- package/dist/middleware/builtin/analytics.js +4 -4
- package/dist/middleware/builtin/guardrails.js +2 -2
- package/dist/middleware/registry.js +11 -2
- package/dist/models/modelRegistry.d.ts +1 -1
- package/dist/models/modelRegistry.js +3 -3
- package/dist/models/modelResolver.d.ts +1 -1
- package/dist/models/modelResolver.js +2 -2
- package/dist/neurolink.d.ts +116 -0
- package/dist/neurolink.js +716 -922
- package/dist/providers/amazonSagemaker.d.ts +1 -1
- package/dist/providers/amazonSagemaker.js +12 -3
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +7 -6
- package/dist/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/providers/anthropicBaseProvider.js +4 -3
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/azureOpenai.js +1 -1
- package/dist/providers/googleAiStudio.d.ts +1 -1
- package/dist/providers/googleAiStudio.js +2 -2
- package/dist/providers/googleVertex.d.ts +40 -0
- package/dist/providers/googleVertex.js +330 -274
- package/dist/providers/huggingFace.js +1 -1
- package/dist/providers/mistral.d.ts +1 -1
- package/dist/providers/mistral.js +2 -2
- package/dist/providers/ollama.d.ts +4 -0
- package/dist/providers/ollama.js +38 -18
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +2 -2
- package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/providers/sagemaker/client.js +13 -3
- package/dist/providers/sagemaker/config.js +5 -1
- package/dist/providers/sagemaker/detection.js +19 -9
- package/dist/providers/sagemaker/errors.d.ts +8 -1
- package/dist/providers/sagemaker/errors.js +103 -20
- package/dist/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/providers/sagemaker/language-model.js +4 -4
- package/dist/providers/sagemaker/parsers.js +14 -6
- package/dist/providers/sagemaker/streaming.js +14 -3
- package/dist/providers/sagemaker/types.d.ts +1 -1
- package/dist/proxy/awsProxyIntegration.js +1 -1
- package/dist/sdk/toolRegistration.d.ts +1 -1
- package/dist/types/cli.d.ts +80 -8
- package/dist/types/contextTypes.js +2 -2
- package/dist/types/generateTypes.d.ts +4 -6
- package/dist/types/providers.d.ts +81 -19
- package/dist/types/providers.js +6 -6
- package/dist/types/streamTypes.d.ts +4 -6
- package/dist/types/typeAliases.d.ts +1 -1
- package/dist/utils/analyticsUtils.d.ts +33 -0
- package/dist/utils/analyticsUtils.js +76 -0
- package/dist/utils/errorHandling.js +4 -1
- package/dist/utils/evaluationUtils.d.ts +27 -0
- package/dist/utils/evaluationUtils.js +131 -0
- package/dist/utils/optionsUtils.js +10 -1
- package/dist/utils/performance.d.ts +1 -1
- package/dist/utils/performance.js +15 -3
- package/dist/utils/providerHealth.d.ts +48 -0
- package/dist/utils/providerHealth.js +199 -254
- package/dist/utils/providerUtils.js +2 -2
- package/dist/utils/timeout.js +8 -3
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* NeuroLink
|
|
2
|
+
* NeuroLink Evaluation System
|
|
3
3
|
*/
|
|
4
|
-
import type { EvaluationData } from "
|
|
5
|
-
export interface
|
|
4
|
+
import type { EvaluationData } from "../index.js";
|
|
5
|
+
export interface EvaluationResult extends EvaluationData {
|
|
6
6
|
domainAlignment?: number;
|
|
7
7
|
terminologyAccuracy?: number;
|
|
8
8
|
toolEffectiveness?: number;
|
|
@@ -20,7 +20,7 @@ export interface UnifiedEvaluationResult extends EvaluationData {
|
|
|
20
20
|
alertSeverity: "low" | "medium" | "high" | "none";
|
|
21
21
|
reasoning: string;
|
|
22
22
|
}
|
|
23
|
-
export interface
|
|
23
|
+
export interface EvaluationContext {
|
|
24
24
|
userQuery: string;
|
|
25
25
|
aiResponse: string;
|
|
26
26
|
context?: Record<string, unknown>;
|
|
@@ -43,14 +43,14 @@ export interface UnifiedEvaluationContext {
|
|
|
43
43
|
/**
|
|
44
44
|
* Get default evaluation when evaluation fails
|
|
45
45
|
*/
|
|
46
|
-
declare function
|
|
46
|
+
declare function getDefaultEvaluation(reason: string, evaluationTime: number, context: EvaluationContext): EvaluationResult;
|
|
47
47
|
/**
|
|
48
48
|
* Parse unified evaluation result from text response
|
|
49
49
|
*/
|
|
50
|
-
declare function
|
|
50
|
+
declare function parseEvaluationResult(response: string, context: EvaluationContext): Partial<EvaluationResult>;
|
|
51
51
|
/**
|
|
52
52
|
* Main unified evaluation function
|
|
53
53
|
*/
|
|
54
|
-
export declare function
|
|
55
|
-
export declare function evaluateResponse(
|
|
56
|
-
export {
|
|
54
|
+
export declare function generateEvaluation(context: EvaluationContext): Promise<EvaluationResult>;
|
|
55
|
+
export declare function evaluateResponse(context: EvaluationContext): Promise<EvaluationResult>;
|
|
56
|
+
export { getDefaultEvaluation, parseEvaluationResult };
|
package/dist/core/evaluation.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* NeuroLink
|
|
2
|
+
* NeuroLink Evaluation System
|
|
3
3
|
*/
|
|
4
4
|
import { logger } from "../utils/logger.js";
|
|
5
5
|
import { AIProviderFactory } from "./factory.js";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { ProviderRegistry } from "../factories/providerRegistry.js";
|
|
8
8
|
import { modelConfig } from "./modelConfiguration.js";
|
|
9
|
+
import { normalizeEvaluationData } from "../utils/evaluationUtils.js";
|
|
9
10
|
// Zod schema for validation
|
|
10
|
-
const
|
|
11
|
+
const EvaluationSchema = z.object({
|
|
11
12
|
relevance: z.number().min(1).max(10),
|
|
12
13
|
accuracy: z.number().min(1).max(10),
|
|
13
14
|
completeness: z.number().min(1).max(10),
|
|
@@ -19,8 +20,8 @@ const UnifiedEvaluationSchema = z.object({
|
|
|
19
20
|
/**
|
|
20
21
|
* Get default evaluation when evaluation fails
|
|
21
22
|
*/
|
|
22
|
-
function
|
|
23
|
-
const functionTag = "
|
|
23
|
+
function getDefaultEvaluation(reason, evaluationTime, context) {
|
|
24
|
+
const functionTag = "getDefaultEvaluation";
|
|
24
25
|
logger.debug(`[${functionTag}] Creating default evaluation`, {
|
|
25
26
|
reason,
|
|
26
27
|
evaluationTime,
|
|
@@ -61,11 +62,14 @@ function getDefaultUnifiedEvaluation(reason, evaluationTime, context) {
|
|
|
61
62
|
/**
|
|
62
63
|
* Parse unified evaluation result from text response
|
|
63
64
|
*/
|
|
64
|
-
function
|
|
65
|
-
const functionTag = "
|
|
65
|
+
function parseEvaluationResult(response, context) {
|
|
66
|
+
const functionTag = "parseEvaluationResult";
|
|
66
67
|
try {
|
|
67
68
|
logger.debug(`[${functionTag}] Parsing evaluation response`, {
|
|
68
69
|
responseLength: response.length,
|
|
70
|
+
domain: context.primaryDomain,
|
|
71
|
+
hasToolUsage: !!context.toolUsage?.length,
|
|
72
|
+
hasConversationHistory: !!context.conversationHistory?.length,
|
|
69
73
|
});
|
|
70
74
|
// Try JSON parsing first
|
|
71
75
|
const jsonMatch = response.match(/\{[^}]*\}/s);
|
|
@@ -74,8 +78,11 @@ function parseUnifiedEvaluationResult(response, context) {
|
|
|
74
78
|
const parsed = JSON.parse(jsonMatch[0]);
|
|
75
79
|
return parsed;
|
|
76
80
|
}
|
|
77
|
-
catch (
|
|
78
|
-
logger.debug(`[${functionTag}] JSON parsing failed, trying regex
|
|
81
|
+
catch (jsonError) {
|
|
82
|
+
logger.debug(`[${functionTag}] JSON parsing failed, trying regex`, {
|
|
83
|
+
error: jsonError instanceof Error ? jsonError.message : String(jsonError),
|
|
84
|
+
jsonContent: jsonMatch[0].substring(0, 100), // First 100 chars for debugging
|
|
85
|
+
});
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
88
|
// Fallback to regex parsing
|
|
@@ -115,14 +122,49 @@ function parseUnifiedEvaluationResult(response, context) {
|
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
|
-
// Ensure minimum valid scores
|
|
119
|
-
|
|
125
|
+
// Ensure minimum valid scores and validate with schema
|
|
126
|
+
// Use context to enhance evaluation data
|
|
127
|
+
const evaluationData = {
|
|
120
128
|
relevance: result.relevance || 1,
|
|
121
129
|
accuracy: result.accuracy || 1,
|
|
122
130
|
completeness: result.completeness || 1,
|
|
123
131
|
overall: result.overall || 1,
|
|
124
|
-
|
|
132
|
+
domainAlignment: result.domainAlignment || (context.primaryDomain ? 5 : undefined), // Default to 5 if domain-specific
|
|
133
|
+
terminologyAccuracy: result.terminologyAccuracy || (context.primaryDomain ? 5 : undefined),
|
|
134
|
+
toolEffectiveness: result.toolEffectiveness || (context.toolUsage?.length ? 5 : undefined), // Default to 5 if tools were used
|
|
125
135
|
};
|
|
136
|
+
// Validate against schema
|
|
137
|
+
try {
|
|
138
|
+
const validated = EvaluationSchema.parse(evaluationData);
|
|
139
|
+
// Enhance reasoning with context information
|
|
140
|
+
let enhancedReasoning = result.reasoning || "No detailed reasoning provided";
|
|
141
|
+
if (context.primaryDomain) {
|
|
142
|
+
enhancedReasoning += ` (Domain: ${context.primaryDomain})`;
|
|
143
|
+
}
|
|
144
|
+
if (context.toolUsage?.length) {
|
|
145
|
+
enhancedReasoning += ` (Tools used: ${context.toolUsage.map((t) => t.toolName).join(", ")})`;
|
|
146
|
+
}
|
|
147
|
+
if (context.conversationHistory?.length) {
|
|
148
|
+
enhancedReasoning += ` (Conversation turns: ${context.conversationHistory.length})`;
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
...validated,
|
|
152
|
+
reasoning: enhancedReasoning,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
catch (validationError) {
|
|
156
|
+
logger.warn(`[${functionTag}] Schema validation failed, using fallback`, {
|
|
157
|
+
validationError,
|
|
158
|
+
originalData: evaluationData,
|
|
159
|
+
});
|
|
160
|
+
return {
|
|
161
|
+
relevance: Math.max(1, Math.min(10, result.relevance || 1)),
|
|
162
|
+
accuracy: Math.max(1, Math.min(10, result.accuracy || 1)),
|
|
163
|
+
completeness: Math.max(1, Math.min(10, result.completeness || 1)),
|
|
164
|
+
overall: Math.max(1, Math.min(10, result.overall || 1)),
|
|
165
|
+
reasoning: result.reasoning || "No detailed reasoning provided",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
126
168
|
}
|
|
127
169
|
catch (error) {
|
|
128
170
|
logger.error(`[${functionTag}] Failed to parse evaluation result`, {
|
|
@@ -140,8 +182,8 @@ function parseUnifiedEvaluationResult(response, context) {
|
|
|
140
182
|
/**
|
|
141
183
|
* Main unified evaluation function
|
|
142
184
|
*/
|
|
143
|
-
export async function
|
|
144
|
-
const functionTag = "
|
|
185
|
+
export async function generateEvaluation(context) {
|
|
186
|
+
const functionTag = "generateEvaluation";
|
|
145
187
|
const startTime = Date.now();
|
|
146
188
|
logger.debug(`[${functionTag}] Starting evaluation`, {
|
|
147
189
|
hasUserQuery: !!context.userQuery,
|
|
@@ -161,7 +203,7 @@ export async function generateUnifiedEvaluation(context) {
|
|
|
161
203
|
const provider = await AIProviderFactory.createProvider(evaluationProvider, evaluationModel);
|
|
162
204
|
if (!provider) {
|
|
163
205
|
logger.debug(`[${functionTag}] No evaluation provider available, returning defaults`);
|
|
164
|
-
return
|
|
206
|
+
return getDefaultEvaluation("no-provider", Date.now() - startTime, context);
|
|
165
207
|
}
|
|
166
208
|
// Create evaluation prompt
|
|
167
209
|
const prompt = `
|
|
@@ -187,68 +229,78 @@ Reasoning: [Provide a detailed explanation of your evaluation, explaining why yo
|
|
|
187
229
|
const result = await provider.generate(prompt);
|
|
188
230
|
if (!result) {
|
|
189
231
|
logger.debug(`[${functionTag}] No response from provider`);
|
|
190
|
-
return
|
|
232
|
+
return getDefaultEvaluation("no-response", Date.now() - startTime, context);
|
|
191
233
|
}
|
|
192
234
|
// Extract text from result
|
|
193
235
|
const response = typeof result === "string" ? result : result?.content || String(result);
|
|
194
236
|
// Parse evaluation result
|
|
195
|
-
const parsed =
|
|
196
|
-
// Validate and enhance result
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
fallbackUsed: false,
|
|
206
|
-
costEstimate: 0.001, // Rough estimate
|
|
207
|
-
},
|
|
237
|
+
const parsed = parseEvaluationResult(response, context);
|
|
238
|
+
// Validate and enhance result using schema
|
|
239
|
+
const baseResult = {
|
|
240
|
+
relevance: parsed.relevance || 1,
|
|
241
|
+
accuracy: parsed.accuracy || 1,
|
|
242
|
+
completeness: parsed.completeness || 1,
|
|
243
|
+
overall: parsed.overall || 1,
|
|
244
|
+
domainAlignment: parsed.domainAlignment,
|
|
245
|
+
terminologyAccuracy: parsed.terminologyAccuracy,
|
|
246
|
+
toolEffectiveness: parsed.toolEffectiveness,
|
|
208
247
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
248
|
+
// Validate against schema before finalizing
|
|
249
|
+
try {
|
|
250
|
+
const validatedScores = EvaluationSchema.parse(baseResult);
|
|
251
|
+
const validatedResult = normalizeEvaluationData({
|
|
252
|
+
...parsed,
|
|
253
|
+
...validatedScores,
|
|
254
|
+
evaluationModel: `${evaluationProvider}/${evaluationModel}`,
|
|
255
|
+
evaluationTime: Date.now() - startTime,
|
|
256
|
+
evaluationProvider,
|
|
257
|
+
evaluationAttempt: 1,
|
|
258
|
+
evaluationConfig: {
|
|
259
|
+
mode: "standard",
|
|
260
|
+
fallbackUsed: false,
|
|
261
|
+
costEstimate: 0.001, // Rough estimate
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
logger.debug(`[${functionTag}] Schema validation passed`, {
|
|
265
|
+
validatedScores,
|
|
266
|
+
});
|
|
267
|
+
return validatedResult;
|
|
268
|
+
}
|
|
269
|
+
catch (validationError) {
|
|
270
|
+
logger.warn(`[${functionTag}] Schema validation failed in main evaluation`, {
|
|
271
|
+
validationError,
|
|
272
|
+
baseResult,
|
|
273
|
+
});
|
|
274
|
+
// Fallback with clamped values using normalizer
|
|
275
|
+
const validatedResult = normalizeEvaluationData({
|
|
276
|
+
...parsed,
|
|
277
|
+
relevance: parsed.relevance || 1,
|
|
278
|
+
accuracy: parsed.accuracy || 1,
|
|
279
|
+
completeness: parsed.completeness || 1,
|
|
280
|
+
overall: parsed.overall || 1,
|
|
281
|
+
evaluationModel: `${evaluationProvider}/${evaluationModel}`,
|
|
282
|
+
evaluationTime: Date.now() - startTime,
|
|
283
|
+
evaluationProvider,
|
|
284
|
+
evaluationAttempt: 1,
|
|
285
|
+
evaluationConfig: {
|
|
286
|
+
mode: "standard",
|
|
287
|
+
fallbackUsed: false,
|
|
288
|
+
costEstimate: 0.001, // Rough estimate
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
return validatedResult;
|
|
292
|
+
}
|
|
217
293
|
}
|
|
218
294
|
catch (error) {
|
|
219
295
|
logger.error(`[${functionTag}] Evaluation failed`, {
|
|
220
296
|
error: error instanceof Error ? error.message : String(error),
|
|
221
297
|
});
|
|
222
|
-
return
|
|
298
|
+
return getDefaultEvaluation(error instanceof Error ? error.message : "unknown-error", Date.now() - startTime, context);
|
|
223
299
|
}
|
|
224
300
|
}
|
|
225
|
-
//
|
|
226
|
-
export async function evaluateResponse(
|
|
227
|
-
|
|
228
|
-
let aiResponse;
|
|
229
|
-
let context;
|
|
230
|
-
if (typeof responseOrContext === "string") {
|
|
231
|
-
// Normal call: evaluateResponse(response, context, ...)
|
|
232
|
-
aiResponse = responseOrContext;
|
|
233
|
-
context = contextOrUserQuery;
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
// Provider call pattern: evaluateResponse(contextObject, userQuery, ...)
|
|
237
|
-
context = responseOrContext;
|
|
238
|
-
aiResponse =
|
|
239
|
-
context?.aiResponse ||
|
|
240
|
-
context?.response ||
|
|
241
|
-
String(contextOrUserQuery || "");
|
|
242
|
-
}
|
|
243
|
-
const evalContext = {
|
|
244
|
-
userQuery: (typeof userQuery === "string" ? userQuery : "") ||
|
|
245
|
-
context?.userQuery ||
|
|
246
|
-
(typeof contextOrUserQuery === "string" ? contextOrUserQuery : "") ||
|
|
247
|
-
"Generated response",
|
|
248
|
-
aiResponse,
|
|
249
|
-
context: context,
|
|
250
|
-
};
|
|
251
|
-
return generateUnifiedEvaluation(evalContext);
|
|
301
|
+
// Simplified evaluation function
|
|
302
|
+
export async function evaluateResponse(context) {
|
|
303
|
+
return generateEvaluation(context);
|
|
252
304
|
}
|
|
253
305
|
// Export additional utilities
|
|
254
|
-
export {
|
|
306
|
+
export { getDefaultEvaluation, parseEvaluationResult };
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
interface ProviderModelConfig {
|
|
2
|
+
provider: string;
|
|
3
|
+
models: string[];
|
|
4
|
+
costPerToken?: number | {
|
|
5
|
+
input: number;
|
|
6
|
+
output: number;
|
|
7
|
+
};
|
|
8
|
+
requiresApiKey?: string[];
|
|
9
|
+
performance?: {
|
|
10
|
+
averageLatency?: number;
|
|
11
|
+
reliability?: number;
|
|
12
|
+
speed?: number;
|
|
13
|
+
quality?: number;
|
|
14
|
+
cost?: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
2
17
|
/**
|
|
3
18
|
* Dynamic provider configurations for evaluation
|
|
4
19
|
* Now uses configurable system instead of hardcoded values
|
|
@@ -22,7 +37,7 @@ export declare function sortProvidersByPreference(providers: ProviderModelConfig
|
|
|
22
37
|
* Estimate cost for a specific provider and token usage
|
|
23
38
|
* Now uses the configurable system
|
|
24
39
|
*/
|
|
25
|
-
export declare function estimateProviderCost(providerName: string,
|
|
40
|
+
export declare function estimateProviderCost(providerName: string, input: number, output: number): number;
|
|
26
41
|
/**
|
|
27
42
|
* Check if a provider is available (has required API keys)
|
|
28
43
|
* Now uses the configurable system
|
|
@@ -58,3 +73,4 @@ export declare function getProviderPerformanceAnalytics(): Record<string, {
|
|
|
58
73
|
* @param providerName - (Optional) The name of the provider to reset. If omitted, resets all providers.
|
|
59
74
|
*/
|
|
60
75
|
export declare function resetProviderMetrics(providerName?: string): void;
|
|
76
|
+
export {};
|
|
@@ -12,7 +12,7 @@ const providerMetrics = new Map();
|
|
|
12
12
|
function convertToLegacyFormat(config) {
|
|
13
13
|
return {
|
|
14
14
|
provider: config.provider,
|
|
15
|
-
models: config.models,
|
|
15
|
+
models: Object.keys(config.models || {}),
|
|
16
16
|
costPerToken: config.defaultCost,
|
|
17
17
|
requiresApiKey: config.requiredEnvVars,
|
|
18
18
|
performance: config.performance,
|
|
@@ -57,25 +57,27 @@ export function getAvailableProviders() {
|
|
|
57
57
|
*/
|
|
58
58
|
export function sortProvidersByPreference(providers, preferCheap = true) {
|
|
59
59
|
return providers.sort((a, b) => {
|
|
60
|
+
const aPerf = a.performance || { cost: 0, speed: 0, quality: 0 };
|
|
61
|
+
const bPerf = b.performance || { cost: 0, speed: 0, quality: 0 };
|
|
60
62
|
if (preferCheap) {
|
|
61
63
|
// Cost > Speed > Quality for cheap preference
|
|
62
|
-
if (
|
|
63
|
-
return
|
|
64
|
+
if ((aPerf.cost || 0) !== (bPerf.cost || 0)) {
|
|
65
|
+
return (bPerf.cost || 0) - (aPerf.cost || 0);
|
|
64
66
|
}
|
|
65
|
-
if (
|
|
66
|
-
return
|
|
67
|
+
if ((aPerf.speed || 0) !== (bPerf.speed || 0)) {
|
|
68
|
+
return (bPerf.speed || 0) - (aPerf.speed || 0);
|
|
67
69
|
}
|
|
68
|
-
return
|
|
70
|
+
return (bPerf.quality || 0) - (aPerf.quality || 0);
|
|
69
71
|
}
|
|
70
72
|
else {
|
|
71
73
|
// Quality > Speed > Cost for quality preference
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
74
|
+
if ((aPerf.quality || 0) !== (bPerf.quality || 0)) {
|
|
75
|
+
return (bPerf.quality || 0) - (aPerf.quality || 0);
|
|
74
76
|
}
|
|
75
|
-
if (
|
|
76
|
-
return
|
|
77
|
+
if ((aPerf.speed || 0) !== (bPerf.speed || 0)) {
|
|
78
|
+
return (bPerf.speed || 0) - (aPerf.speed || 0);
|
|
77
79
|
}
|
|
78
|
-
return
|
|
80
|
+
return (bPerf.cost || 0) - (aPerf.cost || 0);
|
|
79
81
|
}
|
|
80
82
|
});
|
|
81
83
|
}
|
|
@@ -83,12 +85,12 @@ export function sortProvidersByPreference(providers, preferCheap = true) {
|
|
|
83
85
|
* Estimate cost for a specific provider and token usage
|
|
84
86
|
* Now uses the configurable system
|
|
85
87
|
*/
|
|
86
|
-
export function estimateProviderCost(providerName,
|
|
88
|
+
export function estimateProviderCost(providerName, input, output) {
|
|
87
89
|
const costInfo = modelConfig.getCostInfo(providerName);
|
|
88
90
|
if (!costInfo) {
|
|
89
91
|
return 0;
|
|
90
92
|
}
|
|
91
|
-
return
|
|
93
|
+
return input * costInfo.input + output * costInfo.output;
|
|
92
94
|
}
|
|
93
95
|
/**
|
|
94
96
|
* Check if a provider is available (has required API keys)
|
|
@@ -132,6 +132,50 @@ export declare class ModelConfigurationManager {
|
|
|
132
132
|
private lastUpdated;
|
|
133
133
|
private constructor();
|
|
134
134
|
static getInstance(): ModelConfigurationManager;
|
|
135
|
+
/**
|
|
136
|
+
* Create Google AI provider configuration
|
|
137
|
+
*/
|
|
138
|
+
private createGoogleAIConfig;
|
|
139
|
+
/**
|
|
140
|
+
* Create Google Vertex AI provider configuration
|
|
141
|
+
*/
|
|
142
|
+
private createVertexConfig;
|
|
143
|
+
/**
|
|
144
|
+
* Create OpenAI provider configuration
|
|
145
|
+
*/
|
|
146
|
+
private createOpenAIConfig;
|
|
147
|
+
/**
|
|
148
|
+
* Create all provider configurations - centralized approach
|
|
149
|
+
*/
|
|
150
|
+
private createAllProviderConfigs;
|
|
151
|
+
/**
|
|
152
|
+
* Create Anthropic provider configuration
|
|
153
|
+
*/
|
|
154
|
+
private createAnthropicConfig;
|
|
155
|
+
/**
|
|
156
|
+
* Create Vertex alternative provider configuration
|
|
157
|
+
*/
|
|
158
|
+
private createVertexAlternativeConfig;
|
|
159
|
+
/**
|
|
160
|
+
* Create Bedrock provider configuration
|
|
161
|
+
*/
|
|
162
|
+
private createBedrockConfig;
|
|
163
|
+
/**
|
|
164
|
+
* Create Azure provider configuration
|
|
165
|
+
*/
|
|
166
|
+
private createAzureConfig;
|
|
167
|
+
/**
|
|
168
|
+
* Create Ollama provider configuration
|
|
169
|
+
*/
|
|
170
|
+
private createOllamaConfig;
|
|
171
|
+
/**
|
|
172
|
+
* Create HuggingFace provider configuration
|
|
173
|
+
*/
|
|
174
|
+
private createHuggingFaceConfig;
|
|
175
|
+
/**
|
|
176
|
+
* Create Mistral provider configuration
|
|
177
|
+
*/
|
|
178
|
+
private createMistralConfig;
|
|
135
179
|
/**
|
|
136
180
|
* Load default configurations (replaces hardcoded values)
|
|
137
181
|
*/
|
|
@@ -174,6 +218,25 @@ export declare class ModelConfigurationManager {
|
|
|
174
218
|
* Update provider configuration (runtime updates)
|
|
175
219
|
*/
|
|
176
220
|
updateProviderConfig(provider: string, config: ProviderConfig): void;
|
|
221
|
+
/**
|
|
222
|
+
* Parse YAML content with basic support
|
|
223
|
+
* For full YAML support, would need a proper YAML library
|
|
224
|
+
*/
|
|
225
|
+
private parseYAMLContent;
|
|
226
|
+
/**
|
|
227
|
+
* Convert simple YAML to JSON object
|
|
228
|
+
* Handles basic key-value pairs only
|
|
229
|
+
*/
|
|
230
|
+
private convertSimpleYAMLToJSON;
|
|
231
|
+
/**
|
|
232
|
+
* Process a single YAML line
|
|
233
|
+
* Returns key-value pair if valid, null otherwise
|
|
234
|
+
*/
|
|
235
|
+
private processYAMLLine;
|
|
236
|
+
/**
|
|
237
|
+
* Convert YAML value to appropriate JavaScript type
|
|
238
|
+
*/
|
|
239
|
+
private convertYAMLValue;
|
|
177
240
|
/**
|
|
178
241
|
* Load configurations from external source
|
|
179
242
|
*/
|