Skip to content

Commit 4a0ac3e

Browse files
Make evaluation name optional (#66)
* Make evaluation name optional * Adding tests to check empty evaluation name * Adjust import * Address comments --------- Co-authored-by: Ramon Marques <ramon.marques@toptal.com>
1 parent fed237f commit 4a0ac3e

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

aimon/decorators/evaluate.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from functools import wraps
2-
2+
from datetime import datetime
33
from aimon import Client
44
import inspect
55
import warnings
@@ -144,8 +144,8 @@ def evaluate(
144144
application_name,
145145
model_name,
146146
dataset_collection_name,
147-
evaluation_name,
148-
headers,
147+
evaluation_name=None,
148+
headers=None,
149149
api_key=None,
150150
aimon_client=None,
151151
config=None
@@ -222,6 +222,11 @@ def evaluate(
222222
application = Application(name=application_name, stage="evaluation")
223223
model = Model(name=model_name, model_type="text")
224224

225+
# Auto-generate evaluation name if not provided
226+
if not evaluation_name:
227+
timestamp = datetime.utcnow().strftime("%Y%m%dT%H%M%S")
228+
evaluation_name = f"{application_name}-{model_name}-{timestamp}"
229+
225230
# Validata headers to be non-empty and contain atleast the context_docs column
226231
if not headers:
227232
raise ValueError("Headers must be a non-empty list")

tests/test_evaluate.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,46 @@ def test_evaluate_with_custom_client(self):
531531

532532
except Exception as e:
533533
self.log_info("Test error", str(e))
534-
raise
534+
raise
535+
536+
def test_evaluate_without_evaluation_name(self):
537+
"""Test the evaluate function when no evaluation name is provided."""
538+
if not self.api_key:
539+
pytest.skip("AIMON_API_KEY environment variable not set")
540+
541+
try:
542+
# Create test data
543+
test_data = self.create_test_data()
544+
545+
headers = ["context_docs", "user_query", "output", "prompt", "task_definition"]
546+
config = {'hallucination': {'detector_name': 'default'}}
547+
548+
self.log_info("Starting evaluate test without evaluation_name", {
549+
"Application": self.app_name,
550+
"Model": self.model_name,
551+
"Collection": self.collection_name,
552+
"Headers": headers,
553+
"Config": config
554+
})
555+
556+
# Call evaluate without providing evaluation_name
557+
results = evaluate(
558+
application_name=self.app_name,
559+
model_name=self.model_name,
560+
dataset_collection_name=self.collection_name,
561+
headers=headers, # evaluation_name omitted
562+
api_key=self.api_key,
563+
config=config
564+
)
565+
566+
assert len(results) == 2
567+
assert isinstance(results[0], EvaluateResponse)
568+
assert results[0].output in ["Paris is the capital of France.", "Python is a versatile programming language."]
569+
assert hasattr(results[0].response, 'status')
570+
assert results[0].response.status == 200
571+
572+
self.log_info("Test completed successfully", "Auto-generated evaluation_name handled correctly")
573+
574+
except Exception as e:
575+
self.log_info("Test error", str(e))
576+
raise

0 commit comments

Comments
 (0)