|
| 1 | +from dingo.config.input_args import EvaluatorLLMArgs, EvaluatorRuleArgs |
| 2 | +from dingo.model.llm.text_quality.llm_text_quality_v5 import LLMTextQualityV5 |
| 3 | +from dingo.model.model import Model |
| 4 | +from dingo.model.rule.rule_common import RulePatternSearch |
| 5 | + |
| 6 | + |
| 7 | +def test_set_config_rule_copies_dynamic_config_per_rule_object(): |
| 8 | + rule_a = RulePatternSearch() |
| 9 | + rule_b = RulePatternSearch() |
| 10 | + |
| 11 | + Model.set_config_rule(rule_a, EvaluatorRuleArgs(pattern="apple")) |
| 12 | + Model.set_config_rule(rule_b, EvaluatorRuleArgs(pattern="banana")) |
| 13 | + |
| 14 | + assert rule_a.dynamic_config is not rule_b.dynamic_config |
| 15 | + assert rule_a.dynamic_config.pattern == "apple" |
| 16 | + assert rule_b.dynamic_config.pattern == "banana" |
| 17 | + assert RulePatternSearch.dynamic_config.pattern == "your pattern" |
| 18 | + |
| 19 | + |
| 20 | +def test_set_config_llm_copies_dynamic_config_per_llm_object(): |
| 21 | + # This verifies config object isolation only. Existing classmethod LLM evaluators |
| 22 | + # still read cls.dynamic_config at runtime unless separately refactored. |
| 23 | + llm_a = LLMTextQualityV5() |
| 24 | + llm_b = LLMTextQualityV5() |
| 25 | + |
| 26 | + Model.set_config_llm( |
| 27 | + llm_a, |
| 28 | + EvaluatorLLMArgs(model="model-a", parameters={"temperature": 0.1}), |
| 29 | + ) |
| 30 | + Model.set_config_llm( |
| 31 | + llm_b, |
| 32 | + EvaluatorLLMArgs(model="model-b", parameters={"temperature": 0.9}), |
| 33 | + ) |
| 34 | + |
| 35 | + assert llm_a.dynamic_config is not llm_b.dynamic_config |
| 36 | + assert llm_a.dynamic_config.model == "model-a" |
| 37 | + assert llm_b.dynamic_config.model == "model-b" |
| 38 | + assert llm_a.dynamic_config.parameters == {"temperature": 0.1} |
| 39 | + assert llm_b.dynamic_config.parameters == {"temperature": 0.9} |
| 40 | + assert LLMTextQualityV5.dynamic_config.model is None |
| 41 | + assert LLMTextQualityV5.dynamic_config.model_dump().get("parameters") is None |
0 commit comments