> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/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 = """You are an excellent researcher. Given a high-level research idea, \
list 5 concrete questions that should be investigated to determine if the idea is worth pursuing."""

    response = await oai_client.chat.completions.create(
        model="gpt-5.4-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-5.4-mini-baseline"  # 可选，默认随机。
)
```

## 相关内容

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

***

<div className="source-links">
  <Callout icon="terminal-2">
    [连接这些文档](/use-these-docs) 到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/langsmith/evaluation-async.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
