Skip to main content

如何获取实验的性能指标

实验、项目和会话

跟踪项目和实验在我们的后端使用相同的底层数据结构,称为 “session”。

您可能会在我们的文档中互换看到这些术语,但它们都引用相同的底层数据结构。

我们正在努力统一文档和 API 中的术语。

当您使用evaluate使用 Python 或 TypeScript SDK,您可以使用read_project/readProject方法。

实验详细信息的有效负载包括以下值:

{
"start_time": "2024-06-06T01:02:51.299960",
"end_time": "2024-06-06T01:03:04.557530+00:00",
"extra": {
"metadata": {
"git": {
"tags": null,
"dirty": true,
"branch": "ankush/agent-eval",
"commit": "...",
"repo_name": "...",
"remote_url": "...",
"author_name": "Ankush Gola",
"commit_time": "...",
"author_email": "..."
},
"revision_id": null,
"dataset_splits": ["base"],
"dataset_version": "2024-06-05T04:57:01.535578+00:00",
"num_repetitions": 3
}
},
"name": "SQL Database Agent-ae9ad229",
"description": null,
"default_dataset_id": null,
"reference_dataset_id": "...",
"id": "...",
"run_count": 9,
"latency_p50": 7.896,
"latency_p99": 13.09332,
"first_token_p50": null,
"first_token_p99": null,
"total_tokens": 35573,
"prompt_tokens": 32711,
"completion_tokens": 2862,
"total_cost": 0.206485,
"prompt_cost": 0.163555,
"completion_cost": 0.04293,
"tenant_id": "...",
"last_run_start_time": "2024-06-06T01:02:51.366397",
"last_run_start_time_live": null,
"feedback_stats": {
"cot contextual accuracy": {
"n": 9,
"avg": 0.6666666666666666,
"values": {
"CORRECT": 6,
"INCORRECT": 3
}
}
},
"session_feedback_stats": {},
"run_facets": [],
"error_rate": 0,
"streaming_rate": 0,
"test_run_number": 11
}

在这里,您可以提取性能指标,例如:

  • latency_p50:第 50 个百分位延迟(以秒为单位)。
  • latency_p99:第 99 个百分位延迟(以秒为单位)。
  • total_tokens:使用的令牌总数。
  • prompt_tokens:使用的提示令牌数量。
  • completion_tokens:使用的完成令牌数。
  • total_cost:实验的总成本。
  • prompt_cost:提示令牌的成本。
  • completion_cost:完成令牌的成本。
  • feedback_stats:实验的反馈统计信息。
  • error_rate:实验的错误率。
  • first_token_p50:生成第一个令牌的时间的第 50 个百分位延迟(如果使用流式处理)。
  • first_token_p99:生成第一个令牌的时间的第 99 个百分位延迟(如果使用流式处理)。

以下示例说明了如何使用 Python 和 TypeScript 开发工具包获取实验的性能指标。

首先,作为先决条件,我们将创建一个普通数据集。在这里,我们只在 Python 中演示这一点,但你可以在 TypeScript 中做同样的事情。 有关更多详细信息,请查看评估操作指南

from langsmith import Client

client = Client()

# Create a dataset

dataset_name = "HelloDataset"
dataset = client.create_dataset(dataset_name=dataset_name)
examples = [
{
"inputs": {"input": "Harrison"},
"outputs": {"expected": "Hello Harrison"},
},
{
"inputs": {"input": "Ankush"},
"outputs": {"expected": "Hello Ankush"},
},
]
client.create_examples(dataset_id=dataset.id, examples=examples)

接下来,我们将创建一个 Experiment,从evaluate,然后获取实验的性能指标。

from langsmith.schemas import Example, Run

dataset_name = "HelloDataset"

def foo_label(root_run: Run, example: Example) -> dict:
return {"score": 1, "key": "foo"}

from langsmith import evaluate

results = evaluate(
lambda inputs: "Hello " + inputs["input"],
data=dataset_name,
evaluators=[foo_label],
experiment_prefix="Hello",
)

resp = client.read_project(project_name=results.experiment_name, include_stats=True)

print(resp.json(indent=2))

这个页面有帮助吗?


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