Skip to content

Commit f6ee12e

Browse files
authored
allow extra field (#128)
* allow extra field * add ut * format
1 parent c0bece6 commit f6ee12e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

eval_protocol/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ class EvaluationRow(BaseModel):
496496
supporting both row-wise batch evaluation and trajectory-based RL evaluation.
497497
"""
498498

499+
model_config = ConfigDict(extra="allow")
500+
499501
# Core OpenAI ChatCompletion compatible conversation data
500502
messages: List[Message] = Field(description="List of messages in the conversation. Also known as a trajectory.")
501503

tests/test_models.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
from typing import Dict
34

45
import pytest
@@ -660,3 +661,36 @@ def test_stable_hash_across_subprocess():
660661

661662
assert isinstance(child_hash, int)
662663
assert parent_hash == child_hash
664+
665+
666+
def test_evaluation_row_extra_fields():
667+
example = {
668+
"messages": [
669+
{"role": "user", "content": "What is the capital of France?"},
670+
{"role": "assistant", "content": "The capital of France is Paris."},
671+
],
672+
"ground_truth": "Paris",
673+
"evaluation_result": {"score": 1.0, "reason": "Correct"},
674+
"input_metadata": {"model": "gpt-4"},
675+
"eval": {"score": 0.5},
676+
"eval_details": {
677+
"score": 0.5,
678+
"reason": "Correct",
679+
"is_score_valid": True,
680+
"metrics": {
681+
"accuracy": {
682+
"score": 1.0,
683+
"reason": "Correct",
684+
"is_score_valid": True,
685+
},
686+
},
687+
},
688+
"extra_fields": {
689+
"test": "test",
690+
},
691+
}
692+
row = EvaluationRow(**example)
693+
dictionary = json.loads(row.model_dump_json())
694+
assert "eval" in dictionary
695+
assert "accuracy" in dictionary["eval_details"]["metrics"]
696+
assert "test" in dictionary["extra_fields"]

0 commit comments

Comments
 (0)