跳到主要内容

如何在单个评估器中返回多个分数

有时,自定义评估器函数摘要评估器函数返回多个指标会很有用。例如,如果您有多个指标由 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 }, ...]};

这些字典中的每个都可以包含反馈字段的任意或所有内容;请查看链接文档以获取更多信息。

示例

需要 langsmith>=0.2.0

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},
]

结果实验中的行将显示每个分数。


此页面有用吗?


您可以在 GitHub 上留下详细反馈.