-
Notifications
You must be signed in to change notification settings - Fork 873
fix: Change attributes datasets and experiment on client to lazyloading and mark datasets as deprecated #3646
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,8 @@ | ||
| import sys | ||
| import os | ||
| from deprecated import deprecated | ||
|
|
||
| from traceloop.sdk.annotation.user_feedback import UserFeedback | ||
| from traceloop.sdk.datasets.datasets import Datasets | ||
| from traceloop.sdk.experiment.experiment import Experiment | ||
| from traceloop.sdk.client.http import HTTPClient | ||
| from traceloop.sdk.version import __version__ | ||
| from traceloop.sdk.associations.associations import Associations | ||
|
|
@@ -25,8 +24,6 @@ class Client: | |
| api_endpoint: str | ||
| api_key: str | ||
| user_feedback: UserFeedback | ||
| datasets: Datasets | ||
| experiment: Experiment | ||
| associations: Associations | ||
| guardrails: Guardrails | ||
| _http: HTTPClient | ||
|
|
@@ -65,9 +62,45 @@ def __init__( | |
| timeout=httpx.Timeout(120.0), | ||
| ) | ||
| self.user_feedback = UserFeedback(self._http, self.app_name) | ||
| self.datasets = Datasets(self._http) | ||
| experiment_slug = os.getenv("TRACELOOP_EXP_SLUG") | ||
| self._datasets = None | ||
| self._experiment = None | ||
| # TODO: Fix type - Experiment constructor should accept Optional[str] | ||
| self.experiment = Experiment(self._http, self._async_http, experiment_slug) # type: ignore[arg-type] | ||
| self.associations = Associations() | ||
| self.guardrails = Guardrails(self._async_http) | ||
|
|
||
| @property | ||
| def experiment(self): | ||
| # Lazy load only if accessed. | ||
| if self._experiment is None: | ||
| from traceloop.sdk.experiment.experiment import Experiment | ||
| experiment_slug = os.getenv("TRACELOOP_EXP_SLUG") | ||
| self._experiment = Experiment(self._http, self._async_http, experiment_slug) # type: ignore[arg-type] | ||
| return self._experiment | ||
|
|
||
| @property | ||
| @deprecated( | ||
| reason="datasets as client attribute is deprecated. Use a dedicated instance " | ||
| "of Datasets from traceloop.sdk.datasets" | ||
| ) | ||
| def datasets(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you pls explain why you need this change ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As laid out already in my initial PR description (see section You let everybody who has pandas installed pay a 35 MB tax, when loading this library, where it is not clear why the experimental and datasets should be loaded alongside the main client. If it is experimental code, it should not be loaded automatically into the environment of consumers of the library.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the detailed explanation @tassadarius , this is a valid concern. |
||
| # Lazy load only if accessed. | ||
| if self._datasets is None: | ||
| from traceloop.sdk.datasets.datasets import Datasets | ||
| self._datasets = Datasets(self._http) | ||
| return self._datasets | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @datasets.setter | ||
| @deprecated( | ||
| reason="datasets as client attribute is deprecated. Use a dedicated instance " | ||
| "of Datasets from traceloop.sdk.datasets" | ||
| ) | ||
| def datasets(self, datasets: "Datasets"): | ||
| self._datasets = datasets | ||
|
|
||
| @datasets.deleter | ||
| @deprecated( | ||
| reason="datasets as client attribute is deprecated. Use a dedicated instance " | ||
| "of Datasets from traceloop.sdk.datasets" | ||
| ) | ||
| def datasets(self): | ||
| self._datasets = None | ||
Uh oh!
There was an error while loading. Please reload this page.