Skip to content

Commit

Permalink
[OPIK-192]: [SDK] add a link to create dataset (#641)
Browse files Browse the repository at this point in the history
* [OPIK-192]: add a dataset redirect link to creation;

* [OPIK-192]: run linter;

* [OPIK-192]: add link to a created dataset;

---------

Co-authored-by: Sasha <[email protected]>
  • Loading branch information
aadereiko and Sasha authored Nov 18, 2024
1 parent 46be232 commit ad35cf7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sdks/python/src/opik/api_objects/opik_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ def _display_trace_url(self, workspace: str, project_name: str) -> None:
)
self._project_name_most_recent_trace = project_name

def _display_created_dataset_url(self, workspace: str, dataset_name: str) -> None:
dataset_url = url_helpers.get_dataset_url(
workspace=workspace, dataset_name=dataset_name
)

LOGGER.info(f'Created a "{dataset_name}" dataset at {dataset_url}.')

def trace(
self,
id: Optional[str] = None,
Expand Down Expand Up @@ -406,6 +413,8 @@ def create_dataset(
rest_client=self._rest_client,
)

self._display_created_dataset_url(workspace=self._workspace, dataset_name=name)

return result

def get_or_create_dataset(
Expand Down
11 changes: 11 additions & 0 deletions sdks/python/src/opik/url_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ def get_project_url(workspace: str, project_name: str) -> str:
return urllib.parse.urljoin(ui_url, project_path)


def get_dataset_url(workspace: str, dataset_name: str) -> str:
ui_url = get_ui_url()

dataset_path = urllib.parse.quote(
f"{workspace}/redirect/datasets?name={dataset_name}",
safe=ALLOWED_URL_CHARACTERS,
)

return urllib.parse.urljoin(ui_url, dataset_path)


def get_base_url(url: str) -> str:
parsed = urllib.parse.urlparse(url)
base_url = f"{parsed.scheme}://{parsed.netloc}/"
Expand Down

0 comments on commit ad35cf7

Please sign in to comment.