跳到主要内容
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:
    # 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"}

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.