5a558eb09e
Backend Tests / discover-tests (push) Waiting to run
Backend Tests / ${{ matrix.name }} (push) Blocked by required conditions
Build and Publish SDK / build-and-publish (push) Waiting to run
Build Opik Docker Images / set-version (push) Waiting to run
Build Opik Docker Images / build-backend (push) Blocked by required conditions
Build Opik Docker Images / build-sandbox-executor-python (push) Blocked by required conditions
Build Opik Docker Images / build-python-backend (push) Blocked by required conditions
Build Opik Docker Images / build-frontend (push) Blocked by required conditions
Build Opik Docker Images / create-git-tag (push) Blocked by required conditions
ClickHouse Migration Cluster Check / validate-clickhouse-migrations (push) Waiting to run
Docs - Publish / run (push) Waiting to run
E2E Tests - Post Merge (v2) / 🧪 E2E v2 Tests (${{ github.event.inputs.tier || 't1' }}) (push) Waiting to run
E2E Tests - Post Merge (v2) / 📢 Slack Notification (push) Blocked by required conditions
Frontend Unit Tests / Test on Node 20 (push) Waiting to run
Guardrails E2E Tests / Select Python version matrix (push) Waiting to run
Guardrails E2E Tests / Guardrails E2E Tests ${{matrix.python_version}} (push) Blocked by required conditions
Guardrails E2E Tests / 📢 Slack Notification (push) Blocked by required conditions
Guardrails Backend Unit Tests / Guardrails Backend Unit Tests (push) Waiting to run
Guardrails Backend Unit Tests / 📢 Slack Notification (push) Blocked by required conditions
Lint Opik Helm Chart / lint-helm-chart (Helm v3.21.0) (push) Waiting to run
Lint Opik Helm Chart / lint-helm-chart (Helm v4.2.0) (push) Waiting to run
Lint Opik Helm Chart / unittest-helm-chart (push) Waiting to run
Lint Opik Helm Chart / render-equality (push) Waiting to run
Opik Optimizer - Unit Tests / Opik Optimizer Unit Tests Python ${{matrix.python_version}} (push) Waiting to run
Python BE E2E Tests / Python BE E2E (push) Waiting to run
Python Backend Tests / run-python-backend-tests (push) Waiting to run
Python SDK Unit Tests / Python SDK Unit Tests ${{matrix.python_version}} (push) Waiting to run
Release Drafter / update_release_draft (push) Waiting to run
SDK E2E Libraries Integration Tests / Check Secrets (push) Waiting to run
SDK E2E Libraries Integration Tests / Missed OpenAI API Key Warning (push) Blocked by required conditions
SDK E2E Libraries Integration Tests / build-opik (push) Blocked by required conditions
SDK E2E Libraries Integration Tests / E2E Lib Integration Python ${{matrix.python_version}} (push) Blocked by required conditions
TypeScript SDK Integration Build & Publish / build-and-publish (opik-gemini) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-langchain) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-openai) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-otel) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-vercel) (push) Waiting to run
TypeScript SDK Build & Publish / build-and-publish (push) Waiting to run
TypeScript SDK Unit Tests / Test on Node ${{ matrix.node-version }} (push) Waiting to run
TypeScript SDK Compatibility V1.x E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / TypeScript SDK Compatibility V1.x E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
TypeScript SDK E2E Tests / TypeScript SDK E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
Python SDK E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK E2E Tests / Python SDK E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK E2E Tests / build-opik (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Python SDK Compatibility V1.x E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK E2E Tests / build-opik (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer E2E Tests Python ${{matrix.python_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer Integration Smoke Tests (push) Has been cancelled
🐙 Code Quality / detect (push) Has been cancelled
🐙 Code Quality / lint (${{ matrix.leg.name }}) (push) Has been cancelled
🐙 Code Quality / summary (push) Has been cancelled
TypeScript SDK Library Integration Tests / Check Secrets (push) Has been cancelled
TypeScript SDK Library Integration Tests / opik-vercel (Vercel AI SDK / eve) (push) Has been cancelled
SDK Library Integration Tests Runner / Check Secrets (push) Has been cancelled
SDK Library Integration Tests Runner / Missed OpenAI API Key Warning (push) Has been cancelled
SDK Library Integration Tests Runner / Build (push) Has been cancelled
SDK Library Integration Tests Runner / openai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_legacy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / llama_index_tests (push) Has been cancelled
SDK Library Integration Tests Runner / anthropic_tests (push) Has been cancelled
SDK Library Integration Tests Runner / mistral_tests (push) Has been cancelled
SDK Library Integration Tests Runner / groq_tests (push) Has been cancelled
SDK Library Integration Tests Runner / aisuite_tests (push) Has been cancelled
SDK Library Integration Tests Runner / haystack_tests (push) Has been cancelled
SDK Library Integration Tests Runner / dspy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v1_tests (push) Has been cancelled
SDK Library Integration Tests Runner / genai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_legacy_1_3_0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / evaluation_metrics_tests (push) Has been cancelled
SDK Library Integration Tests Runner / bedrock_tests (push) Has been cancelled
SDK Library Integration Tests Runner / litellm_tests (push) Has been cancelled
SDK Library Integration Tests Runner / harbor_tests (push) Has been cancelled
SDK Library Integration Tests Runner / Slack Notification (push) Has been cancelled
222 lines
7.1 KiB
Python
222 lines
7.1 KiB
Python
import logging
|
|
from types import SimpleNamespace
|
|
from unittest import mock
|
|
|
|
from opik.api_objects.dataset import dataset_item
|
|
from opik.evaluation import helpers
|
|
|
|
|
|
class TestResolveProjectName:
|
|
def test_dataset_has_no_project__user_value_used(self, capture_log):
|
|
resolved = helpers.resolve_project_name(
|
|
value_from_dataset=None,
|
|
value_from_user="caller-project",
|
|
caller_name="evaluate",
|
|
)
|
|
|
|
assert resolved == "caller-project"
|
|
assert capture_log.records == []
|
|
|
|
def test_dataset_has_no_project__user_none__returns_none(self, capture_log):
|
|
resolved = helpers.resolve_project_name(
|
|
value_from_dataset=None,
|
|
value_from_user=None,
|
|
caller_name="evaluate",
|
|
)
|
|
|
|
assert resolved is None
|
|
assert capture_log.records == []
|
|
|
|
def test_dataset_has_project__user_none__returns_dataset_project__no_warning(
|
|
self, capture_log
|
|
):
|
|
resolved = helpers.resolve_project_name(
|
|
value_from_dataset="dataset-project",
|
|
value_from_user=None,
|
|
caller_name="evaluate",
|
|
)
|
|
|
|
assert resolved == "dataset-project"
|
|
assert capture_log.records == []
|
|
|
|
def test_dataset_has_project__user_override__dataset_wins_and_warning_logged(
|
|
self, capture_log
|
|
):
|
|
resolved = helpers.resolve_project_name(
|
|
value_from_dataset="dataset-project",
|
|
value_from_user="caller-project",
|
|
caller_name="evaluate_prompt",
|
|
)
|
|
|
|
assert resolved == "dataset-project"
|
|
warning_records = [
|
|
record
|
|
for record in capture_log.records
|
|
if record.levelno == logging.WARNING
|
|
]
|
|
assert len(warning_records) == 1
|
|
message = warning_records[0].getMessage()
|
|
assert "deprecated" in message
|
|
assert "evaluate_prompt()" in message
|
|
assert "dataset-project" in message
|
|
assert "caller-project" in message
|
|
|
|
|
|
class TestResolveDatasetItems:
|
|
@staticmethod
|
|
def _make_dataset(items, dataset_items_count=None):
|
|
dataset_ = SimpleNamespace()
|
|
dataset_.dataset_items_count = (
|
|
dataset_items_count if dataset_items_count is not None else len(items)
|
|
)
|
|
dataset_.__internal_api__stream_items_as_dataclasses__ = mock.MagicMock(
|
|
return_value=iter(items)
|
|
)
|
|
return dataset_
|
|
|
|
def test_no_sampler__returns_lazy_iterator_and_total(self):
|
|
"""No sampler → lazy stream, total computed from dataset metadata."""
|
|
items = [dataset_item.DatasetItem(id=f"i-{i}") for i in range(3)]
|
|
dataset_ = self._make_dataset(items)
|
|
|
|
items_iter, total = helpers.resolve_dataset_items(
|
|
dataset_=dataset_,
|
|
nb_samples=None,
|
|
dataset_item_ids=None,
|
|
dataset_sampler=None,
|
|
dataset_filter_string=None,
|
|
)
|
|
|
|
# iterator returned as-is (lazy) — consuming it yields the originals
|
|
assert list(items_iter) == items
|
|
assert total == 3
|
|
dataset_.__internal_api__stream_items_as_dataclasses__.assert_called_once_with(
|
|
nb_samples=None,
|
|
dataset_item_ids=None,
|
|
batch_size=helpers.EVALUATION_STREAM_DATASET_BATCH_SIZE,
|
|
filter_string=None,
|
|
)
|
|
|
|
def test_explicit_ids__total_is_len_of_ids(self):
|
|
items = [dataset_item.DatasetItem(id="i-0")]
|
|
dataset_ = self._make_dataset(items)
|
|
|
|
_, total = helpers.resolve_dataset_items(
|
|
dataset_=dataset_,
|
|
nb_samples=None,
|
|
dataset_item_ids=["a", "b", "c"],
|
|
dataset_sampler=None,
|
|
dataset_filter_string=None,
|
|
)
|
|
|
|
assert total == 3
|
|
|
|
def test_nb_samples_capped_by_dataset_count(self):
|
|
items = [dataset_item.DatasetItem(id=f"i-{i}") for i in range(5)]
|
|
dataset_ = self._make_dataset(items, dataset_items_count=5)
|
|
|
|
_, total = helpers.resolve_dataset_items(
|
|
dataset_=dataset_,
|
|
nb_samples=10,
|
|
dataset_item_ids=None,
|
|
dataset_sampler=None,
|
|
dataset_filter_string=None,
|
|
)
|
|
|
|
assert total == 5
|
|
|
|
def test_nb_samples_and_filter_forwarded_to_stream(self):
|
|
items = [dataset_item.DatasetItem(id="i-0")]
|
|
dataset_ = self._make_dataset(items)
|
|
|
|
helpers.resolve_dataset_items(
|
|
dataset_=dataset_,
|
|
nb_samples=2,
|
|
dataset_item_ids=None,
|
|
dataset_sampler=None,
|
|
dataset_filter_string='tags contains "x"',
|
|
)
|
|
|
|
dataset_.__internal_api__stream_items_as_dataclasses__.assert_called_once_with(
|
|
nb_samples=2,
|
|
dataset_item_ids=None,
|
|
batch_size=helpers.EVALUATION_STREAM_DATASET_BATCH_SIZE,
|
|
filter_string='tags contains "x"',
|
|
)
|
|
|
|
def test_with_sampler__materializes_and_returns_iter_plus_length(self):
|
|
items = [dataset_item.DatasetItem(id=f"i-{i}") for i in range(4)]
|
|
dataset_ = self._make_dataset(items)
|
|
sampled = items[:2]
|
|
sampler = SimpleNamespace(sample=lambda xs: sampled)
|
|
|
|
items_iter, total = helpers.resolve_dataset_items(
|
|
dataset_=dataset_,
|
|
nb_samples=None,
|
|
dataset_item_ids=None,
|
|
dataset_sampler=sampler,
|
|
dataset_filter_string=None,
|
|
)
|
|
|
|
assert list(items_iter) == sampled
|
|
assert total == 2
|
|
|
|
def test_with_sampler__non_list_return__raises_type_error(self):
|
|
items = [dataset_item.DatasetItem(id="i-0")]
|
|
dataset_ = self._make_dataset(items)
|
|
sampler = SimpleNamespace(sample=lambda xs: iter(xs))
|
|
|
|
try:
|
|
helpers.resolve_dataset_items(
|
|
dataset_=dataset_,
|
|
nb_samples=None,
|
|
dataset_item_ids=None,
|
|
dataset_sampler=sampler,
|
|
dataset_filter_string=None,
|
|
)
|
|
except TypeError as exc:
|
|
assert "must return a list" in str(exc)
|
|
else:
|
|
raise AssertionError("expected TypeError")
|
|
|
|
|
|
class TestMergeBlueprintIntoConfig:
|
|
@staticmethod
|
|
def _make_blueprint(id, name):
|
|
bp = mock.MagicMock()
|
|
bp.id = id
|
|
bp.name = name
|
|
return bp
|
|
|
|
def test_blueprint_fetched_and_version_stored(self):
|
|
mock_client = mock.Mock()
|
|
mock_client._rest_client.agent_configs.get_blueprint_by_id.return_value = (
|
|
self._make_blueprint("bp-123", "v9")
|
|
)
|
|
|
|
result = helpers.merge_blueprint_into_config(
|
|
mock_client,
|
|
"bp-123",
|
|
{"model": "gpt-4o"},
|
|
)
|
|
|
|
assert result["model"] == "gpt-4o"
|
|
assert result["agent_configuration"] == {
|
|
"_blueprint_id": "bp-123",
|
|
"blueprint_version": "v9",
|
|
}
|
|
|
|
def test_blueprint_fetch_fails_still_stores_id(self):
|
|
mock_client = mock.Mock()
|
|
mock_client._rest_client.agent_configs.get_blueprint_by_id.side_effect = (
|
|
Exception("not found")
|
|
)
|
|
|
|
result = helpers.merge_blueprint_into_config(
|
|
mock_client,
|
|
"bp-456",
|
|
None,
|
|
)
|
|
|
|
assert result["agent_configuration"] == {"_blueprint_id": "bp-456"}
|