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

80% Statements 20/25
33.33% Branches 1/3
100% Functions 1/1
80% Lines 20/25

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 411x           2x 2x 2x   2x               2x 2x 2x 2x 2x       2x 2x 2x 2x 2x 2x     2x   2x   2x 2x  
export function getTurnRelevancyTemplate(input: {
  conversation_history: string;
  current_turn: string;
  strict_mode?: boolean;
  verbose_mode?: boolean;
  include_reason?: boolean;
}): { systemPrompt: string; userPrompt: string } {
  const { conversation_history, current_turn, strict_mode, include_reason } =
    input;
 
  const systemPrompt = `You are an evaluator assessing whether a conversation turn is relevant to the preceding context.
Return a JSON object with fields:
{
  "score": <number between 0 and 1>,
  "reasoning": "<concise explanation>",
  "metadata": { "relevant": <true|false>, "relevance_reasons": ["<bullet reasons>"] }
}`;
 
  const lines: string[] = [];
  lines.push(`Conversation History:\n${conversation_history}`);
  lines.push(`\nCurrent Turn:\n${current_turn}`);
  lines.push(`\nInstructions:`);
  if (strict_mode) {
    lines.push(
      '- Use strict criteria; minimal deviation counts as irrelevant.',
    );
  } else {
    lines.push('- Use balanced criteria; minor deviations are acceptable.');
  }
  if (include_reason) {
    lines.push('- Provide a concise reasoning.');
  } else {
    lines.push('- You may omit reasoning if clear.');
  }
  lines.push('- Output strictly in JSON.');
 
  const userPrompt = lines.join('\n');
 
  return { systemPrompt, userPrompt };
}