一键导入
opik-eval
Create and run evaluations on your LLM outputs. Use when testing prompts, measuring quality, comparing models, or creating evaluation datasets.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Create and run evaluations on your LLM outputs. Use when testing prompts, measuring quality, comparing models, or creating evaluation datasets.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Manage prompt versions and run comparisons. Use when versioning prompts, comparing prompt variations, or optimizing prompt performance.
Configure Opik SDK for LLM observability. Use when setting up a new project, connecting to Opik Cloud, or configuring self-hosted Opik.
Add LLM tracing and observability to your code. Use when instrumenting functions, integrating frameworks (LangChain, OpenAI, etc.), or adding custom spans.
| name | opik-eval |
| description | Create and run evaluations on your LLM outputs. Use when testing prompts, measuring quality, comparing models, or creating evaluation datasets. |
Dataset: client.get_or_create_dataset("my-dataset")
Evaluate: evaluate(dataset, task_fn, metrics)
Metrics: Hallucination, AnswerRelevance, ContextPrecision, ContextRecall, Equals
Note: Evaluation APIs are Python-primary in the Opik SDK. TypeScript support is limited for evaluation workflows.
Python: Run opik healthcheck
TypeScript: Verify config exists at ~/.opik.config or env vars are set
✅ "Connection successful" / config exists → Continue below
❌ "Connection failed" / no config → Run /opik-setup first, then return here
Note: OPIK_PROJECT_NAME is optional - evaluations go to "default" project if unset.
from opik import Opik
client = Opik()
dataset = client.get_or_create_dataset("my-eval-dataset")
# Add items
dataset.insert([
{"input": "What is Python?", "expected_output": "A programming language"},
{"input": "What is JavaScript?", "expected_output": "A programming language"},
])
from openai import OpenAI
openai_client = OpenAI()
def my_llm_task(item):
# Your LLM call here
response = openai_client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": item["input"]}]
)
return {
"output": response.choices[0].message.content,
"context": ["Retrieved context here"] # Optional, for context-based metrics
}
from opik.evaluation import evaluate
from opik.evaluation.metrics import Equals, AnswerRelevance
result = evaluate(
dataset=dataset,
task=my_llm_task,
scoring_metrics=[Equals(), AnswerRelevance()]
)
print(f"Average score: {result.average_score}")
| Metric | Description | Use When |
|---|---|---|
Hallucination | Detects factual errors | Checking output accuracy |
AnswerRelevance | Measures response relevance | Q&A systems |
ContextPrecision | Context retrieval quality | RAG applications |
ContextRecall | Context coverage | RAG applications |
Equals | Exact match comparison | Deterministic outputs |
See METRICS.md for detailed metric documentation.
Evaluate different prompts against the same dataset:
from opik.evaluation import evaluate_prompt
result = evaluate_prompt(
dataset=dataset,
prompt_template="Answer this question: {input}",
model="gpt-4",
scoring_metrics=[AnswerRelevance()]
)
from opik.evaluation.metrics import (
Hallucination,
AnswerRelevance,
ContextPrecision
)
result = evaluate(
dataset=dataset,
task=my_task,
scoring_metrics=[
Hallucination(),
AnswerRelevance(),
ContextPrecision()
]
)
# Evaluate model A
result_a = evaluate(dataset=dataset, task=model_a_task, scoring_metrics=metrics)
# Evaluate model B
result_b = evaluate(dataset=dataset, task=model_b_task, scoring_metrics=metrics)
# Compare results in Opik dashboard