( question: string, tracker?: TokenTracker )
| 372 | const TOOL_NAME = 'evaluator'; |
| 373 | |
| 374 | export async function evaluateQuestion( |
| 375 | question: string, |
| 376 | tracker?: TokenTracker |
| 377 | ): Promise<EvaluationType[]> { |
| 378 | try { |
| 379 | const generator = new ObjectGeneratorSafe(tracker); |
| 380 | |
| 381 | const result = await generator.generateObject({ |
| 382 | model: TOOL_NAME, |
| 383 | schema: questionEvaluationSchema, |
| 384 | prompt: getQuestionEvaluationPrompt(question), |
| 385 | }); |
| 386 | |
| 387 | console.log('Question Evaluation:', result.object); |
| 388 | |
| 389 | // Always include definitive in types |
| 390 | const types: EvaluationType[] = ['definitive']; |
| 391 | if (result.object.needsFreshness) types.push('freshness'); |
| 392 | if (result.object.needsPlurality) types.push('plurality'); |
| 393 | |
| 394 | console.log('Question Metrics:', types); |
| 395 | |
| 396 | // Always evaluate definitive first, then freshness (if needed), then plurality (if needed) |
| 397 | return types; |
| 398 | |
| 399 | } catch (error) { |
| 400 | console.error('Error in question evaluation:', error); |
| 401 | // Default to all evaluation types in case of error |
| 402 | return ['definitive', 'freshness', 'plurality']; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | |
| 407 | async function performEvaluation<T>( |
no test coverage detected