(args: {
input: string;
output: string;
expected?: string;
})
| 79 | |
| 80 | // Wrapper that retries the Factuality scorer on failure |
| 81 | export const Factuality = async (args: { |
| 82 | input: string; |
| 83 | output: string; |
| 84 | expected?: string; |
| 85 | }): Promise<{ name: string; score: number | null; metadata?: Record<string, unknown> }> => { |
| 86 | let lastError: Error | null = null; |
| 87 | |
| 88 | for (let attempt = 1; attempt <= MAX_SCORER_RETRIES; attempt++) { |
| 89 | try { |
| 90 | const result = await FactualityBaseScorer({ ...args, maxTokens: 10_000 }); |
| 91 | // If score is null, treat as failure and retry |
| 92 | if (result.score === null) { |
| 93 | lastError = new Error('Scorer returned null score'); |
| 94 | continue; |
| 95 | } |
| 96 | return result; |
| 97 | } catch (error) { |
| 98 | lastError = error instanceof Error ? error : new Error(String(error)); |
| 99 | // Continue to next attempt |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // All retries exhausted - return error result |
| 104 | return { |
| 105 | name: 'Factuality', |
| 106 | score: null, |
| 107 | metadata: { |
| 108 | error: lastError?.message || 'Unknown error after retries', |
| 109 | retries: MAX_SCORER_RETRIES, |
| 110 | }, |
| 111 | }; |
| 112 | }; |
| 113 | |
| 114 | import { runAgentInWorker } from '../src/agents/run-in-worker.js'; |
| 115 | import { defaultErrorScoreHandler, type Span } from 'braintrust'; |
nothing calls this directly
no outgoing calls
no test coverage detected