Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions validmind/ai/test_descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
35 changes: 18 additions & 17 deletions validmind/vm_models/result/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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`
Expand Down Expand Up @@ -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"<h3>{self.test_name}: <code>{self.metric}</code></h3>")

Expand All @@ -310,8 +317,6 @@ def to_widget(self):
),
"show_metric": self.metric is not None,
"metric": self.metric,
"tables": self.tables,
"figures": self.figures,
}
rendered = get_result_template().render(**template_data)

Expand Down Expand Up @@ -409,10 +414,6 @@ async def log_async(
)

if self.description:
if isinstance(self.description, DescriptionFuture):
self.description = self.description.get_description()
self._was_description_generated = True

revision_name = (
AI_REVISION_NAME
if self._was_description_generated
Expand Down
Loading