Skip to content

Commit

Permalink
[Evals] Support list examples by dataset version tag (langchain-ai#18534
Browse files Browse the repository at this point in the history
)

previously only supported by timestamp
  • Loading branch information
hinthornw authored and thebhulawat committed Mar 6, 2024
1 parent a214958 commit 14f3978
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
13 changes: 4 additions & 9 deletions libs/langchain/langchain/smith/evaluation/runner_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,20 +979,15 @@ def _prepare_eval_run(
) -> Tuple[MCF, TracerSession, Dataset, List[Example]]:
wrapped_model = _wrap_in_chain_factory(llm_or_chain_factory, dataset_name)
dataset = client.read_dataset(dataset_name=dataset_name)
as_of = dataset_version if isinstance(dataset_version, datetime) else None
if isinstance(dataset_version, str):
raise NotImplementedError(
"Selecting dataset_version by tag is not yet supported."
" Please use a datetime object."
)
examples = list(client.list_examples(dataset_id=dataset.id, as_of=as_of))

examples = list(client.list_examples(dataset_id=dataset.id, as_of=dataset_version))
if not examples:
raise ValueError(f"Dataset {dataset_name} has no example rows.")
modified_at = [ex.modified_at for ex in examples if ex.modified_at]
# Should always be defined in practice when fetched,
# but the typing permits None
max_modified_at = max(modified_at) if modified_at else None
dataset_version = max_modified_at.isoformat() if max_modified_at else None
inferred_version = max_modified_at.isoformat() if max_modified_at else None

try:
project_metadata = project_metadata or {}
Expand All @@ -1003,7 +998,7 @@ def _prepare_eval_run(
"git": git_info,
}

project_metadata["dataset_version"] = dataset_version
project_metadata["dataset_version"] = inferred_version
project = client.create_project(
project_name,
reference_dataset_id=dataset.id,
Expand Down
8 changes: 4 additions & 4 deletions libs/langchain/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/langchain/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ python = ">=3.8.1,<4.0"
langchain-core = ">=0.1.28,<0.2"
langchain-text-splitters = ">=0.0.1,<0.1"
langchain-community = ">=0.0.25,<0.1"
langsmith = "^0.1.14"
langsmith = "^0.1.17"
pydantic = ">=1,<3"
SQLAlchemy = ">=1.4,<3"
requests = "^2"
Expand Down

0 comments on commit 14f3978

Please sign in to comment.