Skip to content

Commit 266d3f6

Browse files
Benny ChenBenny Chen
authored andcommitted
pyright round 4
1 parent 0644511 commit 266d3f6

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

eval_protocol/rewards/apps_coding_reward.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def evaluate_apps_solution(messages: List[Message], ground_truth: Optional[str],
8484
reason="No messages provided.",
8585
)
8686

87-
raw_solution_content = messages[-1].content
87+
raw_solution_content = messages[-1].content if isinstance(messages[-1].content, str) else ""
8888
code_solution = _extract_python_code(raw_solution_content)
8989

9090
if not code_solution or not code_solution.strip():

eval_protocol/rewards/bfcl_reward.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ def bfcl_reward(
262262
assistant_message_found = True
263263
total_assistant_messages += 1
264264
# Check for any content or any tool_call
265-
if (msg.content and msg.content.strip()) or msg.tool_calls:
265+
content_str = msg.content if isinstance(msg.content, str) else ""
266+
if (content_str and content_str.strip()) or msg.tool_calls:
266267
valid_assistant_messages += 1
267268

268269
if not assistant_message_found:

eval_protocol/rewards/length.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def length_reward(
9393
)
9494
},
9595
)
96-
text = response.content
96+
text = response.content if isinstance(response.content, str) else ""
9797
elif isinstance(response, dict):
9898
if response.get("role") != "assistant" or not response.get("content"):
9999
return EvaluateResult(
@@ -107,7 +107,8 @@ def length_reward(
107107
)
108108
},
109109
)
110-
text = response.get("content", "")
110+
text_val = response.get("content", "")
111+
text = text_val if isinstance(text_val, str) else ""
111112
else:
112113
return EvaluateResult(
113114
score=0.0,
@@ -294,7 +295,7 @@ def cosine_length_reward(
294295
)
295296
},
296297
)
297-
text = response.content
298+
text = response.content if isinstance(response.content, str) else ""
298299
elif isinstance(response, dict):
299300
if response.get("role") != "assistant" or not response.get("content"):
300301
return EvaluateResult(
@@ -308,7 +309,8 @@ def cosine_length_reward(
308309
)
309310
},
310311
)
311-
text = response.get("content", "")
312+
text_val = response.get("content", "")
313+
text = text_val if isinstance(text_val, str) else ""
312314
else:
313315
return EvaluateResult(
314316
score=0.0,

eval_protocol/rewards/reasoning_steps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def reasoning_steps_reward(
6060
)
6161
},
6262
)
63-
text: str = response.content
63+
text: str = response.content if isinstance(response.content, str) else ""
6464

6565
# Default patterns for detecting reasoning steps
6666
default_patterns = [
@@ -199,7 +199,7 @@ def sequence_reward(
199199
)
200200
},
201201
)
202-
text: str = response.content
202+
text: str = response.content if isinstance(response.content, str) else ""
203203

204204
if not sequence_terms:
205205
sequence_terms = [

eval_protocol/rewards/repetition.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def diversity_reward(
248248
)
249249
},
250250
)
251-
text = response.content or ""
251+
text = _to_text(response.content)
252252
elif isinstance(response, dict):
253253
if response.get("role") != "assistant":
254254
return EvaluateResult(
@@ -262,7 +262,8 @@ def diversity_reward(
262262
)
263263
},
264264
)
265-
text = response.get("content", "")
265+
text_val = response.get("content", "")
266+
text = text_val if isinstance(text_val, str) else ""
266267
else:
267268
return EvaluateResult(
268269
score=0.0,

0 commit comments

Comments
 (0)