diff --git a/parea/client.py b/parea/client.py index 92a0d195..531dffc2 100644 --- a/parea/client.py +++ b/parea/client.py @@ -34,6 +34,7 @@ RECORD_FEEDBACK_ENDPOINT = "/feedback" EXPERIMENT_ENDPOINT = "/experiment" EXPERIMENT_STATS_ENDPOINT = "/experiment/{experiment_uuid}/stats" +EXPERIMENT_FINISHED_ENDPOINT = "/experiment/{experiment_uuid}/finished" @define @@ -147,6 +148,20 @@ async def aget_experiment_stats(self, experiment_uuid: str) -> ExperimentStatsSc ) return structure(r.json(), ExperimentStatsSchema) + def finish_experiment(self, experiment_uuid: str) -> ExperimentStatsSchema: + r = self._client.request( + "POST", + EXPERIMENT_FINISHED_ENDPOINT.format(experiment_uuid=experiment_uuid), + ) + return structure(r.json(), ExperimentStatsSchema) + + async def afinish_experiment(self, experiment_uuid: str) -> ExperimentSchema: + r = await self._client.request_async( + "POST", + EXPERIMENT_FINISHED_ENDPOINT.format(experiment_uuid=experiment_uuid), + ) + return structure(r.json(), ExperimentStatsSchema) + _initialized_parea_wrapper = False diff --git a/parea/experiment/experiment.py b/parea/experiment/experiment.py index 62784f8e..010aa935 100644 --- a/parea/experiment/experiment.py +++ b/parea/experiment/experiment.py @@ -67,8 +67,8 @@ def experiment(name: str, data: Iterable[Dict], func: Callable) -> ExperimentSta asyncio.run(func(**data_input)) else: func(**data_input) - time.sleep(5) # wait for all trace logs to be written to DB - experiment_stats: ExperimentStatsSchema = p.get_experiment_stats(experiment_uuid) + time.sleep(5) # wait for any evaluation to finish which is executed in the background + experiment_stats: ExperimentStatsSchema = p.finish_experiment(experiment_uuid) stat_name_to_avg_std = calculate_avg_std_for_experiment(experiment_stats) print(f"Experiment stats:\n{json.dumps(stat_name_to_avg_std, indent=2)}\n\n") print(f"View experiment & its traces at: https://app.parea.ai/experiments/{experiment_uuid}\n") diff --git a/pyproject.toml b/pyproject.toml index 12cb7de8..bba6c61e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "parea-ai" packages = [{ include = "parea" }] -version = "0.2.31" +version = "0.2.32" description = "Parea python sdk" readme = "README.md" authors = ["joel-parea-ai "]