in src/dfcx_scrapi/core/experiments.py [0:0]
def list_experiments(self, environment_id: str = None):
"""List out experiments.
Args:
environment_id: (Optional) The ID for the environment from which
the list of experiments will be retrieved.
Returns:
A list of experiment JSON objects.
"""
environment_path = f"{self.agent_id}/environments/{environment_id}"
logging.info("environment_path %s", environment_path)
request = types.experiment.ListExperimentsRequest()
request.parent = environment_path
client_options = self._set_region(environment_path)
client = services.experiments.ExperimentsClient(
client_options=client_options, credentials=self.creds
)
response = client.list_experiments(request)
blob = scrapi_base.ScrapiBase.cx_object_to_json(response)
if len(blob) < 1:
logging.warning(
"no experiments found for environment: %s", environment_id
)
return None
experiments: list = blob["experiments"]
results = [
{
"environment_id": environment_id,
"experiment_id": ex["name"].split("/").pop(),
"displayName": ex["displayName"],
"name": ex["name"],
}
for ex in experiments
]
logging.info("results %s", json.dumps(results, indent=2))
return experiments