-
Notifications
You must be signed in to change notification settings - Fork 220
feat(client): add methods to langfuse client to fetch and delete dataset runs #1453
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 |
|---|---|---|
|
|
@@ -79,6 +79,11 @@ | |
| from langfuse._utils.parse_error import handle_fern_exception | ||
| from langfuse._utils.prompt_cache import PromptCache | ||
| from langfuse.api.resources.commons.errors.error import Error | ||
| from langfuse.api.resources.commons.types import DatasetRunWithItems | ||
| from langfuse.api.resources.datasets.types import ( | ||
| DeleteDatasetRunResponse, | ||
| PaginatedDatasetRuns, | ||
| ) | ||
| from langfuse.api.resources.ingestion.types.score_body import ScoreBody | ||
| from langfuse.api.resources.prompts.types import ( | ||
| CreatePromptRequest_Chat, | ||
|
|
@@ -2456,6 +2461,78 @@ def get_dataset( | |
| handle_fern_exception(e) | ||
| raise e | ||
|
|
||
| def get_dataset_run( | ||
| self, dataset_name: str, *, run_name: str | ||
| ) -> DatasetRunWithItems: | ||
| """Fetch a dataset run by dataset name and run name. | ||
|
|
||
| Args: | ||
| dataset_name (str): The name of the dataset. | ||
| run_name (str): The name of the run. | ||
|
|
||
| Returns: | ||
| DatasetRunWithItems: The dataset run with its items. | ||
| """ | ||
| try: | ||
| return self.api.datasets.get_run( | ||
| dataset_name=self._url_encode(dataset_name), | ||
| run_name=self._url_encode(run_name), | ||
|
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. If run_name is being passed as a query param, we would have to set In any case, we should add a few tests here to cover all works as expected with the encoding 👍🏾 |
||
| request_options=None, | ||
| ) | ||
| except Error as e: | ||
| handle_fern_exception(e) | ||
| raise e | ||
|
|
||
| def get_dataset_runs( | ||
| self, | ||
| dataset_name: str, | ||
|
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. We should have all arguments here as keyword arguments |
||
| *, | ||
| page: Optional[int] = None, | ||
| limit: Optional[int] = None, | ||
| ) -> PaginatedDatasetRuns: | ||
| """Fetch all runs for a dataset. | ||
|
|
||
| Args: | ||
| dataset_name (str): The name of the dataset. | ||
| page (Optional[int]): Page number, starts at 1. | ||
| limit (Optional[int]): Limit of items per page. | ||
|
|
||
| Returns: | ||
| PaginatedDatasetRuns: Paginated list of dataset runs. | ||
| """ | ||
| try: | ||
| return self.api.datasets.get_runs( | ||
| dataset_name=self._url_encode(dataset_name), | ||
| page=page, | ||
| limit=limit, | ||
| request_options=None, | ||
| ) | ||
| except Error as e: | ||
| handle_fern_exception(e) | ||
| raise e | ||
|
|
||
| def delete_dataset_run( | ||
| self, dataset_name: str, *, run_name: str | ||
|
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. We should have all arguments here as keyword arguments |
||
| ) -> DeleteDatasetRunResponse: | ||
| """Delete a dataset run and all its run items. This action is irreversible. | ||
|
|
||
| Args: | ||
| dataset_name (str): The name of the dataset. | ||
| run_name (str): The name of the run. | ||
|
|
||
| Returns: | ||
| DeleteDatasetRunResponse: Confirmation of deletion. | ||
| """ | ||
| try: | ||
| return self.api.datasets.delete_run( | ||
| dataset_name=self._url_encode(dataset_name), | ||
| run_name=self._url_encode(run_name), | ||
| request_options=None, | ||
| ) | ||
| except Error as e: | ||
| handle_fern_exception(e) | ||
| raise e | ||
|
|
||
| def run_experiment( | ||
| self, | ||
| *, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have all arguments here as keyword arguments