Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OPIK-390]: [SDK] add a project name to creation of traces; #607

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sdks/python/src/opik/api_objects/opik_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ def _initialize_streamer(
)

def _display_trace_url(self, workspace: str, project_name: str) -> None:
projects_url = url_helpers.get_projects_url(workspace=workspace)
project_url = url_helpers.get_project_url(
workspace=workspace, project_name=project_name
)

if (
self._project_name_most_recent_trace is None
or self._project_name_most_recent_trace != project_name
):
LOGGER.info(
f'Started logging traces to the "{project_name}" project at {projects_url}.'
f'Started logging traces to the "{project_name}" project at {project_url}.'
)
self._project_name_most_recent_trace = project_name

Expand Down
25 changes: 22 additions & 3 deletions sdks/python/src/opik/url_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
URL_ACCOUNT_DETAILS_POSTFIX: Final[str] = "api/rest/v2/account-details"
URL_WORKSPACE_GET_LIST_POSTFIX: Final[str] = "api/rest/v2/workspaces"
HEALTH_CHECK_URL_POSTFIX: Final[str] = "/is-alive/ping"
ALLOWED_URL_CHARACTERS: Final[str] = ":/&?="


def get_ui_url() -> str:
config = opik.config.OpikConfig()
opik_url_override = config.url_override

return opik_url_override.rstrip("/api")
return opik_url_override.rstrip("/api") + "/"


def get_experiment_url(dataset_name: str, experiment_id: str) -> str:
Expand All @@ -27,12 +28,30 @@ def get_experiment_url(dataset_name: str, experiment_id: str) -> str:
config = opik.config.OpikConfig()
ui_url = get_ui_url()

return f"{ui_url}/{config.workspace}/experiments/{dataset_id}/compare?experiments=%5B%22{experiment_id}%22%5D"
experiment_path = urllib.parse.quote(
f'{config.workspace}/experiments/{dataset_id}/compare?experiments=["{experiment_id}"]',
safe=ALLOWED_URL_CHARACTERS,
)

return urllib.parse.urljoin(ui_url, experiment_path)


def get_projects_url(workspace: str) -> str:
ui_url = get_ui_url()
return f"{ui_url}/{workspace}/projects/"

projects_path = "{workspace}/projects"

return urllib.parse.urljoin(ui_url, projects_path)


def get_project_url(workspace: str, project_name: str) -> str:
ui_url = get_ui_url()

project_path = urllib.parse.quote(
f"{workspace}/redirect/projects?name={project_name}",
safe=ALLOWED_URL_CHARACTERS,
)
return urllib.parse.urljoin(ui_url, project_path)


def get_base_url(url: str) -> str:
Expand Down