Skip to content

Commit e49deaf

Browse files
committed
avoid modifyng _scorers internal state when normalizing weights (create copy instead)
1 parent 97afac1 commit e49deaf

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

src/runloop_api_client/sdk/async_scenario_builder.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,16 +401,15 @@ def _build_params(self) -> ScenarioCreateParams:
401401

402402
# Normalize weights to sum to 1.0
403403
total_weight = sum(s["weight"] for s in self._scorers)
404-
for s in self._scorers:
405-
s["weight"] = s["weight"] / total_weight
404+
normalized_scorers: List[ScoringFunctionParam] = [{**s, "weight": s["weight"] / total_weight} for s in self._scorers]
406405

407406
params: ScenarioCreateParams = {
408407
"name": self._name,
409408
"input_context": {
410409
"problem_statement": self._problem_statement,
411410
},
412411
"scoring_contract": {
413-
"scoring_function_parameters": self._scorers,
412+
"scoring_function_parameters": normalized_scorers,
414413
},
415414
}
416415

src/runloop_api_client/sdk/scenario_builder.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,16 +401,15 @@ def _build_params(self) -> ScenarioCreateParams:
401401

402402
# Normalize weights to sum to 1.0
403403
total_weight = sum(s["weight"] for s in self._scorers)
404-
for s in self._scorers:
405-
s["weight"] = s["weight"] / total_weight
404+
normalized_scorers: List[ScoringFunctionParam] = [{**s, "weight": s["weight"] / total_weight} for s in self._scorers]
406405

407406
params: ScenarioCreateParams = {
408407
"name": self._name,
409408
"input_context": {
410409
"problem_statement": self._problem_statement,
411410
},
412411
"scoring_contract": {
413-
"scoring_function_parameters": self._scorers,
412+
"scoring_function_parameters": normalized_scorers,
414413
},
415414
}
416415

0 commit comments

Comments
 (0)