LangSmith 支持分类指标和数值指标,在编写自定义评估器时你可以返回其中任意一种。
要使评估器结果被记录为数值指标,必须按以下形式返回:
- * (仅 Python)
int,float, orbool - * 一个如下形式的字典
{"key": "metric_name", "score": int | float | bool}
要使评估器结果被记录为分类指标,必须按以下形式返回:
- * (仅 Python)
str - * 一个如下形式的字典
{"key": "metric_name", "value": str | int | float | bool}
以下是一些示例:
- - Python:需要
langsmith>=0.2.0 - - TypeScript:多个分数的支持可在
langsmith@0.1.32及更高版本中使用
def numerical_metric(inputs: dict, outputs: dict, reference_outputs: dict) -> float:
# Evaluation logic...
return 0.8
# Equivalently
# return {"score": 0.8}
# Or
# return {"key": "numerical_metric", "score": 0.8}
def categorical_metric(inputs: dict, outputs: dict, reference_outputs: dict) -> str:
# Evaluation logic...
return "english"
# Equivalently
# return {"key": "categorical_metric", "score": "english"}
# Or
# return {"score": "english"}
function numericalMetric(run: Run, example: Example) {
// Your evaluation logic here
return { key: "numerical_metric", score: 0.8};
}
function categoricalMetric(run: Run, example: Example) {
// Your evaluation logic here
return { key: "categorical_metric", value: "english"};
}