Skip to content

Commit f6becc8

Browse files
committed
feat: rule base default value
1 parent 4fa75c3 commit f6becc8

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

dingo/model/model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,23 @@ def load_model(cls):
154154
cls.module_loaded = True
155155

156156
@classmethod
157-
def set_config_rule(self, rule: BaseRule, rule_config: EvaluatorRuleArgs):
157+
def set_config_rule(cls, rule: BaseRule, rule_config: EvaluatorRuleArgs):
158158
if not rule_config:
159159
return
160160
config_default = getattr(rule, 'dynamic_config')
161-
for k, v in rule_config:
161+
# Iterate over rule_config fields using Pydantic's model_dump()
162+
for k, v in rule_config.model_dump().items():
162163
if v is not None:
163164
setattr(config_default, k, v)
164165
setattr(rule, 'dynamic_config', config_default)
165166

166167
@classmethod
167-
def set_config_llm(self, llm: BaseLLM, llm_config: EvaluatorLLMArgs):
168+
def set_config_llm(cls, llm: BaseLLM, llm_config: EvaluatorLLMArgs):
168169
if not llm_config:
169170
return
170171
config_default = getattr(llm, 'dynamic_config')
171-
for k, v in llm_config:
172+
# Iterate over llm_config fields using Pydantic's model_dump()
173+
for k, v in llm_config.model_dump().items():
172174
if v is not None:
173175
setattr(config_default, k, v)
174176
setattr(llm, 'dynamic_config', config_default)

dingo/model/rule/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77

88
class BaseRule:
9-
metric_type: str # This will be set by the decorator
10-
group: List[str] # This will be set by the decorator
11-
dynamic_config: EvaluatorRuleArgs
9+
metric_type: str = '' # This will be set by the decorator
10+
group: List[str] = [] # This will be set by the decorator
11+
dynamic_config: EvaluatorRuleArgs = EvaluatorRuleArgs() # Default config, can be overridden by subclasses
1212

1313
@classmethod
1414
def eval(cls, input_data: Data) -> EvalDetail:

0 commit comments

Comments
 (0)