> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
> Use this file to discover all available pages before exploring further.

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

有时，自定义评估器或总结评估器返回多个指标会很有用。例如，如果有一个由 LLM 评判生成的多个指标，通过单次 LLM 调用生成多个指标，而不是进行多次 LLM 调用，可以节省时间和成本。

要使用 Python SDK 返回多个分数，只需返回以下形式的字典/对象列表：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
[
    # 'key' 是指标名称
    # 'score' 是数值指标的值
    {"key": string, "score": number},
    # 'value' 是分类指标的值
    {"key": string, "value": string},
    ... # 您可以记录任意多个
]
```

要使用 JS/TS SDK 实现，返回一个包含 'results' 键的对象，然后是一个上述形式的列表

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{results: [{ key: string, score: number }, ...]};
```

这些字典中的每一个都可以包含[反馈字段](/langsmith/feedback-data-format)中的任意或全部字段；请查看链接文档以获取更多信息。

示例：

* Python：需要 `langsmith>=0.2.0`
* TypeScript：`langsmith@0.1.32` 及更高版本支持多个分数

<CodeGroup>
  ```python Python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  def multiple_scores(outputs: dict, reference_outputs: dict) -> list[dict]:
      # 替换为实际的评估逻辑。
      precision = 0.8
      recall = 0.9
      f1 = 0.85
      return [
          {"key": "precision", "score": precision},
          {"key": "recall", "score": recall},
          {"key": "f1", "score": f1},
      ]
  ```

  ```typescript TypeScript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  import type { Run, Example } from "langsmith/schemas";

  function multipleScores(rootRun: Run, example: Example) {
    // 在此处添加您的评估逻辑
    return {
        results: [
            { key: "precision", score: 0.8 },
            { key: "recall", score: 0.9 },
            { key: "f1", score: 0.85 },
        ],
    };
  }
  ```
</CodeGroup>

生成的实验中的行将显示每个分数。

<img src="https://mintcdn.com/hhh-8c10bf0c/lQoj_T05pUgIcyPg/langsmith/images/multiple-scores.png?fit=max&auto=format&n=lQoj_T05pUgIcyPg&q=85&s=50d52c5999fcff7c449c950b4171b958" alt="multiple_scores.png" width="1622" height="1020" data-path="langsmith/images/multiple-scores.png" />

## 相关

* [返回分类与数值指标](/langsmith/metric-type)

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\langsmith\multiple-scores.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
