All files / api/src/connectors/evaluations/latency types.ts

100% Statements 10/10
100% Branches 1/1
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 371x                           1x 1x         1x           1x 1x 1x 1x 1x 1x          
import { z } from 'zod';
 
/**
 * Parameters for latency evaluation (Time-to-First-Token / TTFT)
 *
 * This evaluation measures how quickly the AI provider starts responding.
 * For streaming requests: Uses first_token_time - start_time
 * For non-streaming requests: Uses the full duration as a proxy
 *
 * The score is normalized based on target_latency_ms and max_latency_ms:
 * - Responses at or below target_latency_ms score 1.0 (perfect)
 * - Responses at or above max_latency_ms score 0.0 (worst)
 * - Responses in between are scored linearly
 */
export const LatencyEvaluationParameters = z
  .object({
    /**
     * Target latency in milliseconds (ideal time-to-first-token)
     * Responses at or below this threshold score 1.0
     */
    target_latency_ms: z.number().positive().default(10_000),
 
    /**
     * Maximum acceptable latency in milliseconds
     * Responses at or above this threshold score 0.0
     */
    max_latency_ms: z.number().positive().default(30_000),
  })
  .refine((data) => data.target_latency_ms < data.max_latency_ms, {
    message: 'Target latency must be less than max latency',
    path: ['target_latency_ms'],
  });
 
export type LatencyEvaluationParameters = z.infer<
  typeof LatencyEvaluationParameters
>;