Skip to content

Commit 55fe06d

Browse files
e06084shijinpjlabdaniel5u
authored
sync main to dev (#398)
* docs: update wechat (#390) * docs: update wechat (#392) * docs: update wechat (#395) * Isolate evaluator dynamic configs (#396) --------- Co-authored-by: sjshailab <shijinpjlab@163.com> Co-authored-by: daniel5u <danielsuuuuuu@gmail.com>
1 parent e19fad1 commit 55fe06d

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

dingo/model/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def load_model(cls):
157157
def set_config_rule(cls, rule: BaseRule, rule_config: EvaluatorRuleArgs):
158158
if not rule_config:
159159
return
160-
config_default = getattr(rule, 'dynamic_config')
160+
config_default = rule.dynamic_config.model_copy(deep=True)
161161
# Iterate over rule_config fields using Pydantic's model_dump()
162162
for k, v in rule_config.model_dump().items():
163163
if v is not None:
@@ -168,7 +168,7 @@ def set_config_rule(cls, rule: BaseRule, rule_config: EvaluatorRuleArgs):
168168
def set_config_llm(cls, llm: BaseLLM, llm_config: EvaluatorLLMArgs):
169169
if not llm_config:
170170
return
171-
config_default = getattr(llm, 'dynamic_config')
171+
config_default = llm.dynamic_config.model_copy(deep=True)
172172
# Iterate over llm_config fields using Pydantic's model_dump()
173173
for k, v in llm_config.model_dump().items():
174174
if v is not None:

docs/assets/wechat.jpg

3.03 KB
Loading
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)