Skip to content

Commit 92b53d9

Browse files
Added support to include task_definition in the aimon_payload (#53)
* 1. Added support to include task_definition in the aimon_payload 2. Added a safety check for the case where only RR is specified in config but task_definition is not declared in the dataset. * updated logic to check for task_definition every time when RR is specified in config
1 parent 43d8f37 commit 92b53d9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

aimon/decorators/detect.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ def wrapper(*args, **kwargs):
194194
if 'instructions' in result_dict:
195195
aimon_payload['instructions'] = result_dict['instructions']
196196

197+
if 'retrieval_relevance' in self.config:
198+
if 'task_definition' in result_dict:
199+
aimon_payload['task_definition'] = result_dict['task_definition']
200+
else:
201+
raise ValueError( "When retrieval_relevance is specified in the config, "
202+
"'task_definition' must be present in the result of the wrapped function.")
203+
204+
197205
aimon_payload['config'] = self.config
198206
aimon_payload['publish'] = self.publish
199207
aimon_payload['async_mode'] = self.async_mode

aimon/decorators/evaluate.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ def evaluate(
301301
if "instructions" in record and "instruction_adherence" in config:
302302
# Only pass instructions if instruction_adherence is specified in the config
303303
payload["instructions"] = record["instructions"] or ""
304+
305+
if "retrieval_relevance" in config:
306+
if "task_definition" in record:
307+
payload["task_definition"] = record["task_definition"]
308+
else:
309+
raise ValueError( "When retrieval_relevance is specified in the config, "
310+
"'task_definition' must be present in the dataset")
311+
304312
payload["config"] = config
305313
results.append(EvaluateResponse(record['output'], client.analyze.create(body=[payload])))
306314

@@ -447,6 +455,14 @@ def _run_eval(self, func, args, kwargs):
447455
if "instructions" in record and "instruction_adherence" in self.config:
448456
# Only pass instructions if instruction_adherence is specified in the config
449457
payload["instructions"] = record["instructions"] or ""
458+
459+
if "retrieval_relevance" in self.config:
460+
if "task_definition" in record:
461+
payload["task_definition"] = record["task_definition"]
462+
else:
463+
raise ValueError( "When retrieval_relevance is specified in the config, "
464+
"'task_definition' must be present in the dataset")
465+
450466
payload["config"] = self.config
451467
results.append((result, self.client.analyze.create(body=[payload])))
452468
return results
@@ -489,6 +505,11 @@ def __init__(self, application, model, values_returned, api_key=None, config=Non
489505
if "instruction_adherence" in self.config and "instructions" not in self.values_returned:
490506
raise ValueError(
491507
"When instruction_adherence is specified in the config, 'instructions' must be returned by the decorated function")
508+
509+
if "retrieval_relevance" in self.config and "task_definition" not in self.values_returned:
510+
raise ValueError( "When retrieval_relevance is specified in the config, "
511+
"'task_definition' must be returned by the decorated function")
512+
492513
if "instructions" in self.values_returned and "instruction_adherence" not in self.config:
493514
raise ValueError(
494515
"instruction_adherence must be specified in the config for returning 'instructions' by the decorated function")
@@ -522,6 +543,8 @@ def _run_production_analysis(self, func, args, kwargs):
522543
aimon_payload['instructions'] = result_dict['instructions']
523544
if 'actual_request_timestamp' in result_dict:
524545
aimon_payload["actual_request_timestamp"] = result_dict['actual_request_timestamp']
546+
if 'task_definition' in result_dict:
547+
aimon_payload['task_definition'] = result_dict['task_definition']
525548

526549
aimon_payload['config'] = self.config
527550
aimon_response = self.client.analyze.create(body=[aimon_payload])

0 commit comments

Comments
 (0)