All files / api/src/connectors/evaluations/turn-relevancy types.ts

100% Statements 27/27
100% Branches 0/0
100% Functions 0/0
100% Lines 27/27

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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 671x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                               1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x          
import { z } from 'zod';
 
export const TurnRelevancyResultSchema = z.object({
  score: z.number().min(0).max(1),
  reasoning: z.string().optional(),
  metadata: z
    .object({
      relevant: z.boolean().optional(),
      relevance_reasons: z.array(z.string()).optional(),
    })
    .partial()
    .optional(),
});
 
export type TurnRelevancyResult = z.infer<typeof TurnRelevancyResultSchema>;
 
export interface TurnRelevancyAverageResult {
  average_score: number;
  total_logs: number;
  passed_count: number;
  failed_count: number;
  threshold_used: number;
  evaluation_run_id: string;
  // Additional statistics
  min_score?: number;
  max_score?: number;
  median_score?: number;
  valid_results_count?: number;
  error_results_count?: number;
}
 
export interface TurnRelevancyMetadata {
  conversation_history?: string;
  current_turn?: string;
  instructions?: string;
  criteria?: {
    description?: string;
    strict_mode?: boolean;
    verbose_mode?: boolean;
    include_reason?: boolean;
  };
}
 
// AI-modifiable parameters - none needed, evaluation works automatically
export const TurnRelevancyEvaluationAIParameters = z.object({}).strict();
 
// Full parameters including user-modifiable settings
// Note: model is configured via evaluation.model_id, not in parameters
export const TurnRelevancyEvaluationParameters =
  TurnRelevancyEvaluationAIParameters.extend({
    threshold: z.number().min(0).max(1).default(0.7),
    temperature: z.number().min(0).max(2).default(0.1),
    max_tokens: z.number().int().positive().default(1000),
    include_reason: z.boolean().default(true),
    strict_mode: z.boolean().default(false),
    async_mode: z.boolean().default(true),
    verbose_mode: z.boolean().default(false),
    batch_size: z.number().int().positive().default(10),
    conversation_history: z.string().optional(),
    current_turn: z.string().optional(),
    instructions: z.string().optional(),
  });
 
export type TurnRelevancyEvaluationParameters = z.infer<
  typeof TurnRelevancyEvaluationParameters
>;