diff --git a/validmind/ai/test_descriptions.py b/validmind/ai/test_descriptions.py index b240b6206..b40ef9d7b 100644 --- a/validmind/ai/test_descriptions.py +++ b/validmind/ai/test_descriptions.py @@ -79,15 +79,11 @@ def generate_description( "No tables, unit metric or figures provided - cannot generate description" ) - # # TODO: fix circular import - # from validmind.ai.utils import get_client_and_model - client, model = get_client_and_model() # get last part of test id test_name = title or test_id.split(".")[-1] - # TODO: fully support metrics if metric is not None: tables = [] if not tables else tables tables.append( diff --git a/validmind/vm_models/result/result.py b/validmind/vm_models/result/result.py index eebf0fc62..82da5edeb 100644 --- a/validmind/vm_models/result/result.py +++ b/validmind/vm_models/result/result.py @@ -172,10 +172,9 @@ class TestResult(Result): _was_description_generated: bool = False _unsafe: bool = False - @property - def test_name(self) -> str: - """Get the test name, using custom title if available.""" - return self.title or test_id_to_name(self.result_id) + def __post_init__(self): + if self.ref_id is None: + self.ref_id = str(uuid4()) def __repr__(self) -> str: attrs = [ @@ -199,9 +198,21 @@ def __repr__(self) -> str: return f'TestResult("{self.result_id}", {", ".join(attrs)})' - def __post_init__(self): - if self.ref_id is None: - self.ref_id = str(uuid4()) + def __getattribute__(self, name): + # lazy load description if its a DescriptionFuture (generated in background) + if name == "description": + description = super().__getattribute__("description") + + if isinstance(description, DescriptionFuture): + self._was_description_generated = True + self.description = description.get_description() + + return super().__getattribute__(name) + + @property + def test_name(self) -> str: + """Get the test name, using custom title if available.""" + return self.title or test_id_to_name(self.result_id) def _get_flat_inputs(self): # remove duplicates by `input_id` @@ -292,10 +303,6 @@ def remove_figure(self, index: int = 0): self.figures.pop(index) def to_widget(self): - if isinstance(self.description, DescriptionFuture): - self.description = self.description.get_description() - self._was_description_generated = True - if self.metric is not None and not self.tables and not self.figures: return HTML(f"
{self.metric}