Skip to main content
LangSmith 同时支持分类指标和数值指标,在编写自定义评估器时,您可以返回任意一种类型。 若要将评估器结果记录为数值指标,必须返回以下形式之一:
  • (仅限 Python)intfloatbool 类型
  • 形式为 {"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:
    # 评估逻辑...
    return 0.8
    # 等效写法
    # return {"score": 0.8}
    # 或
    # return {"key": "numerical_metric", "score": 0.8}

def categorical_metric(inputs: dict, outputs: dict, reference_outputs: dict) -> str:
    # 评估逻辑...
    return "english"
    # 等效写法
    # return {"key": "categorical_metric", "score": "english"}
    # 或
    # return {"score": "english"}

相关链接