실험에 대한 성능 지표 가져오기
실험에 대한 성능 지표 가져오기
Python 또는 TypeScript SDK로 evaluate를 사용해 실험을 실행하면, read_project/readProject 메서드를 사용해 실험의 성능 지표를 가져올 수 있어요.
추적 프로젝트와 실험은 백엔드에서 동일한 기본 데이터 구조("세션"(session))를 사용해요. 문서에서 이 용어들이 서로 바뀌어 쓰일 수 있지만, 모두 동일한 기본 데이터 구조를 가리킵니다. 우리는 문서와 API 전반에 걸쳐 용어를 통일하려고 노력하고 있어요.
출처: 문서
본문
실험 상세 정보 페이로드는 다음 값들을 포함합니다:
{
"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 SDK를 사용해 실험의 성능 지표를 가져오는 예시입니다.
먼저, 전제 조건으로 간단한 데이터셋을 만들겠습니다. 여기서는 Python으로만 보여드리지만, TypeScript에서도 동일하게 할 수 있어요. 자세한 내용은 평가에 대한 하우투 가이드를 참고하세요.
from langsmith import Client
client = Client()
# 데이터셋 생성
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)
이제 실험을 만들고, evaluate 결과에서 실험 이름을 가져온 다음, 실험의 성능 지표를 가져오겠습니다.
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.model_dump_json(indent=2))
```typescript TypeScript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { Client } from "langsmith";
import { evaluate } from "langsmith/evaluation";
import type { EvaluationResult } from "langsmith/evaluation";
import type { Run, Example } from "langsmith/schemas";
// 행 단위 평가기
function fooLabel(rootRun: Run, example: Example): EvaluationResult {
return {score: 1, key: "foo"};
}
const client = new Client();
const results = await evaluate(
(inputs) => {
return { output: "Hello " + inputs.input };
},
{
data: "HelloDataset",
experimentPrefix: "Hello",
evaluators: [fooLabel],
}
);
const resp = await client.readProject({
projectName: results.experimentName,
includeStats: true
})
console.log(JSON.stringify(resp, null, 2))
더 알아보기 (Learn more)
- 이 문서들을 사용하기 — MCP를 통해 Claude, VSCode 등에 연결하여 실시간 답변을 받아 보세요.
- GitHub에서 이 페이지 편집 또는 이슈 등록