Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

1.6 KB
Raw Blame
import type {
  EvaluatorSetupDraft,
  ManagedTemplate,
} from "@/src/features/evals/v2/types/templateGallery";

function managedTemplateDefinition(
  evaluator: ManagedTemplate["evaluator"],
): EvaluatorSetupDraft["definition"] {
  switch (evaluator.type) {
    case "LLM_AS_JUDGE":
      return {
        type: evaluator.type,
        promptMessages: evaluator.promptMessages,
        provider: null,
        model: null,
        modelParams: null,
        vars: evaluator.variables.map(({ name }) => name),
        variableMapping: evaluator.variables.map(
          ({ name, defaultMapping }) => ({
            templateVariable: name,
            selectedColumnId: defaultMapping.field,
            jsonSelector: null,
          }),
        ),
        outputDefinition: evaluator.outputDefinition,
      };
    case "CODE":
      return {
        type: evaluator.type,
        sourceCode: evaluator.source,
        sourceCodeLanguage: evaluator.language,
      };
    case "DECISION_MODEL":
      return {
        type: evaluator.type,
        questions: evaluator.questions,
        provider: "",
        model: "",
        vars: evaluator.state.map(({ key }) => key),
        variableMapping: evaluator.state.map(({ key, defaultMapping }) => ({
          templateVariable: key,
          selectedColumnId: defaultMapping.field,
          jsonSelector: null,
        })),
      };
  }
}

export function managedTemplateToEvaluatorSetupDraft(
  template: ManagedTemplate,
): EvaluatorSetupDraft {
  return {
    name: template.name,
    description: template.description,
    definition: managedTemplateDefinition(template.evaluator),
  };
}