Skip to content

Commit 13c0407

Browse files
committed
rename current version to latest version and use urlencode, and update release notes
1 parent 0e0c15b commit 13c0407

File tree

4 files changed

+82
-66
lines changed

4 files changed

+82
-66
lines changed

ddtrace/llmobs/_experiment.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Dataset:
107107
_id: str
108108
_records: List[DatasetRecord]
109109
_version: int
110-
_current_version: int
110+
_latest_version: int
111111
_dne_client: "LLMObsExperimentsClient"
112112
_new_records_by_record_id: Dict[str, DatasetRecordRaw]
113113
_updated_record_ids_to_new_fields: Dict[str, UpdatableDatasetRecord]
@@ -122,15 +122,15 @@ def __init__(
122122
dataset_id: str,
123123
records: List[DatasetRecord],
124124
description: str,
125-
current_version: int,
125+
latest_version: int,
126126
version: int,
127127
_dne_client: "LLMObsExperimentsClient",
128128
) -> None:
129129
self.name = name
130130
self.project = project
131131
self.description = description
132132
self._id = dataset_id
133-
self._current_version = current_version
133+
self._latest_version = latest_version
134134
self._version = version
135135
self._dne_client = _dne_client
136136
self._records = records
@@ -171,10 +171,10 @@ def push(self) -> None:
171171
record["record_id"] = record_id # type: ignore
172172

173173
# FIXME: we don't get version numbers in responses to deletion requests
174-
self._current_version = new_version if new_version != -1 else self._current_version + 1
174+
self._latest_version = new_version if new_version != -1 else self._latest_version + 1
175175
# no matter what the version was before the push, pushing will result in the dataset being on the current
176176
# version tracked by the backend
177-
self._version = self._current_version
177+
self._version = self._latest_version
178178
self._new_records_by_record_id = {}
179179
self._deleted_record_ids = []
180180
self._updated_record_ids_to_new_fields = {}
@@ -232,8 +232,8 @@ def url(self) -> str:
232232
return f"{_get_base_url()}/llm/datasets/{self._id}"
233233

234234
@property
235-
def current_version(self) -> int:
236-
return self._current_version
235+
def latest_version(self) -> int:
236+
return self._latest_version
237237

238238
@property
239239
def version(self) -> int:
@@ -448,7 +448,7 @@ def _run_task(self, jobs: int, raise_errors: bool = False, sample_size: Optional
448448
dataset_id=self._dataset._id,
449449
records=subset_records,
450450
description=self._dataset.description,
451-
current_version=self._dataset._current_version,
451+
latest_version=self._dataset._latest_version,
452452
version=self._dataset._version,
453453
_dne_client=self._dataset._dne_client,
454454
)

ddtrace/llmobs/_writer.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import os
55
import tempfile
6+
import urllib
67
from typing import Any
78
from typing import Dict
89
from typing import List
@@ -400,7 +401,16 @@ def dataset_create(
400401
if dataset_id is None or dataset_id == "":
401402
raise ValueError(f"unexpected dataset state, invalid ID (is None: {dataset_id is None})")
402403
curr_version = response_data["data"]["attributes"]["current_version"]
403-
return Dataset(dataset_name, project, dataset_id, [], description, curr_version, curr_version, _dne_client=self)
404+
return Dataset(
405+
name=dataset_name,
406+
project=project,
407+
dataset_id=dataset_id,
408+
records=[],
409+
description=description,
410+
latest_version=curr_version,
411+
version=curr_version,
412+
_dne_client=self,
413+
)
404414

405415
@staticmethod
406416
def _get_record_json(record: Union[UpdatableDatasetRecord, DatasetRecordRaw], is_update: bool) -> JSONType:
@@ -484,12 +494,14 @@ def dataset_get_with_records(
484494
dataset_id = data[0]["id"]
485495

486496
list_base_path = f"/api/unstable/llm-obs/v1/datasets/{dataset_id}/records"
497+
498+
url_options = {}
487499
if version:
488-
list_base_path = f"{list_base_path}?filter[version]={version}"
500+
url_options["filter[version]"] = version
489501

490502
has_next_page = True
491503
class_records: List[DatasetRecord] = []
492-
list_path = list_base_path
504+
list_path = f"{list_base_path}?{urllib.parse.urlencode(url_options, safe='[]')}"
493505
page_num = 0
494506
while has_next_page:
495507
resp = self.request("GET", list_path, timeout=self.LIST_RECORDS_TIMEOUT)
@@ -514,17 +526,18 @@ def dataset_get_with_records(
514526
has_next_page = False
515527
if next_cursor:
516528
has_next_page = True
517-
list_path = f"{list_base_path}{'&' if version else '?'}page[cursor]={next_cursor}"
529+
url_options["page[cursor]"] = next_cursor
530+
list_path = f"{list_base_path}?{urllib.parse.urlencode(url_options, safe='[]')}"
518531
logger.debug("next list records request path %s", list_path)
519532
page_num += 1
520533
return Dataset(
521-
dataset_name,
522-
project,
523-
dataset_id,
524-
class_records,
525-
dataset_description,
526-
curr_version,
527-
version or curr_version,
534+
name=dataset_name,
535+
project=project,
536+
dataset_id=dataset_id,
537+
records=class_records,
538+
description=dataset_description,
539+
latest_version=curr_version,
540+
version=version or curr_version,
528541
_dne_client=self,
529542
)
530543

releasenotes/notes/llmobs-dne-allow-versioned-dataset-pull-c7017f982b2c1f5b.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ features:
33
- |
44
LLM Observability: Previous dataset versions can be optionally pulled by passing the ``version``
55
argument to ``LLMObs.pull_dataset``
6+
- |
7+
LLM Observability: Datasets have new properties ``version`` and ``latest_version`` to provide information on the
8+
version of the dataset that is being worked with and the latest global version of the dataset, respectively

0 commit comments

Comments
 (0)