Skip to content

Commit 77451b2

Browse files
committed
coderabbit suggestions
1 parent 1af4148 commit 77451b2

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

backend/app/crud/evaluations/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ def update_evaluation_run(
200200
semantics), so callers don't accidentally clear unrelated columns.
201201
`updated_at` is always bumped.
202202
"""
203-
for key, value in update.model_dump(exclude_unset=True).items():
204-
setattr(eval_run, key, value)
203+
for field_name, new_value in update.model_dump(exclude_unset=True).items():
204+
setattr(eval_run, field_name, new_value)
205205

206206
eval_run.updated_at = now()
207207

backend/app/crud/evaluations/cost.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,28 @@ def attach_cost(
144144
) -> None:
145145
"""Compute cost for the given stage(s) and attach to `eval_run.cost`, never raising.
146146
147-
Caller is responsible for persisting `eval_run` afterwards. When only the
148-
embedding stage is provided, a previously-computed response entry on
149-
`eval_run.cost` is preserved.
147+
Caller is responsible for persisting `eval_run` afterwards. Either stage's
148+
previously-computed entry on `eval_run.cost` is preserved when that stage's
149+
inputs are not supplied, so partial updates never clobber prior data.
150150
"""
151151
try:
152+
existing_cost = eval_run.cost or {}
153+
152154
if response_model is not None and response_results is not None:
153155
response_entry = _build_response_cost_entry(
154156
session=session, model=response_model, results=response_results
155157
)
156158
else:
157-
response_entry = (eval_run.cost or {}).get("response")
159+
response_entry = existing_cost.get("response")
158160

159-
embedding_entry: dict[str, Any] | None = None
160161
if embedding_model is not None and embedding_raw_results is not None:
161162
embedding_entry = _build_embedding_cost_entry(
162163
session=session,
163164
model=embedding_model,
164165
raw_results=embedding_raw_results,
165166
)
167+
else:
168+
embedding_entry = existing_cost.get("embedding")
166169

167170
eval_run.cost = _build_cost_dict(
168171
response_entry=response_entry,

0 commit comments

Comments
 (0)