> ## 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.

# 如何异步运行评估

<Info>
  [评估](/langsmith/evaluation-concepts#evaluation-lifecycle) | [评估器](/langsmith/evaluation-concepts#evaluators) | [数据集](/langsmith/evaluation-concepts#datasets) | [实验](/langsmith/evaluation-concepts#experiment)
</Info>

我们可以通过 SDK 使用 [aevaluate()](https://docs.smith.langchain.com/reference/python/evaluation/langsmith.evaluation._arunner.aevaluate) 异步运行评估，该函数接受与 [evaluate()](https://docs.smith.langchain.com/reference/python/evaluation/langsmith.evaluation._runner.evaluate) 相同的所有参数，但要求应用程序函数是异步的。了解更多信息，请参阅[如何使用 `evaluate()` 函数](/langsmith/evaluate-llm-application)。

<Info>
  本指南仅在使用 Python SDK 时相关。在 JS/TS 中，`evaluate()` 函数已经是异步的。更多信息，请参阅[评估 LLM 应用程序](/langsmith/evaluate-llm-application)。
</Info>

## 使用 `aevaluate()`

* Python

需要 `langsmith>=0.3.13`

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langsmith import wrappers, Client
from openai import AsyncOpenAI

# 可选：包装 OpenAI 客户端以追踪所有模型调用。
oai_client = wrappers.wrap_openai(AsyncOpenAI())

# 可选：添加 'traceable' 装饰器以追踪此函数的输入/输出。
@traceable
async def researcher_app(inputs: dict) -> str:
    instructions = """你是一名优秀的研究员。给定一个高层次的研究想法，\
列出 5 个具体问题，这些问题应被研究以确定该想法是否值得推进。"""

    response = await oai_client.chat.completions.create(
        model="gpt-4.1-mini",
        messages=[
            {"role": "system", "content": instructions},
            {"role": "user", "content": inputs["idea"]},
        ],
    )
    return response.choices[0].message.content

# 评估器函数可以是同步或异步的
def concise(inputs: dict, outputs: dict) -> bool:
    return len(outputs["output"]) < 3 * len(inputs["idea"])

ls_client = Client()
ideas = [
    "universal basic income",
    "nuclear fusion",
    "hyperloop",
    "nuclear powered rockets",
]
dataset = ls_client.create_dataset("research ideas")
ls_client.create_examples(
    dataset_name=dataset.name,
    examples=[{"inputs": {"idea": i}} for i in ideas],
)

# 也可以直接使用 'aevaluate' 函数：
# from langsmith import aevaluate
# await aevaluate(...)
results = await ls_client.aevaluate(
    researcher_app,
    data=dataset,
    evaluators=[concise],
    # 可选，添加并发。
    max_concurrency=2,  # 可选，添加并发。
    experiment_prefix="gpt-4.1-mini-baseline"  # 可选，默认为随机。
)
```

## 相关

* [运行评估（同步）](/langsmith/evaluate-llm-application)
* [处理模型速率限制](/langsmith/rate-limiting)

***

<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\evaluation-async.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>
