跳到主要内容
有时,自定义评估器或摘要评估器返回多个指标会很有用。例如,如果您的 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
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.