有时,自定义评估器或摘要评估器返回多个指标很有用。例如,如果您有 LLM 评判者生成的多个指标,您可以通过进行生成多个指标的单个 LLM 调用来节省时间和金钱,而不是进行多个 LLM 调用。 要使用 Python SDK 返回多个分数,只需返回以下形式的字典/对象列表:
[
    # 'key' is the metric name
    # 'score' is the value of a numerical metric
    {"key": string, "score": number},
    # 'value' is the value of a categorical metric
    {"key": string, "value": string},
    ... # You may log as many as you wish
]
要使用 JS/TS SDK 执行此操作,请返回一个带有 ‘results’ 键的对象,然后是上述形式的列表
{results: [{ key: string, score: number }, ...]};
这些字典中的每一个都可以包含任何或所有反馈字段;查看链接的文档以获取更多信息。 示例:
  • Python:需要 langsmith>=0.2.0
  • TypeScript:langsmith@0.1.32 及更高版本支持多个分数
def multiple_scores(outputs: dict, reference_outputs: dict) -> list[dict]:
    # Replace with real evaluation logic.
    precision = 0.8
    recall = 0.9
    f1 = 0.85
    return [
        {"key": "precision", "score": precision},
        {"key": "recall", "score": recall},
        {"key": "f1", "score": f1},
    ]
结果实验的行将显示每个分数。 multiple_scores.png

相关


Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.