Skip to content

Commit 4bc058d

Browse files
Benny ChenBenny Chen
authored andcommitted
fix ruff
1 parent 9a81f7e commit 4bc058d

File tree

5 files changed

+59
-41
lines changed

5 files changed

+59
-41
lines changed

eval_protocol/adapters/langchain.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ def _dbg_print(*args):
2121

2222

2323
def serialize_lc_message_to_ep(msg: BaseMessage) -> Message:
24-
_dbg_print("[EP-Ser] Input LC msg:", type(msg).__name__, {
25-
"has_additional_kwargs": isinstance(getattr(msg, "additional_kwargs", None), dict),
26-
"content_type": type(getattr(msg, "content", None)).__name__,
27-
})
24+
_dbg_print(
25+
"[EP-Ser] Input LC msg:",
26+
type(msg).__name__,
27+
{
28+
"has_additional_kwargs": isinstance(getattr(msg, "additional_kwargs", None), dict),
29+
"content_type": type(getattr(msg, "content", None)).__name__,
30+
},
31+
)
2832

2933
if isinstance(msg, HumanMessage):
3034
ep_msg = Message(role="user", content=str(msg.content))
@@ -65,11 +69,13 @@ def _normalize_tool_calls(tc_list: list) -> list[dict]:
6569
import json as _json
6670

6771
fn_args = _json.dumps(fn_args or {}, ensure_ascii=False)
68-
mapped.append({
69-
"id": call_id,
70-
"type": "function",
71-
"function": {"name": fn_name, "arguments": fn_args},
72-
})
72+
mapped.append(
73+
{
74+
"id": call_id,
75+
"type": "function",
76+
"function": {"name": fn_name, "arguments": fn_args},
77+
}
78+
)
7379
except Exception:
7480
continue
7581
return mapped
@@ -92,16 +98,23 @@ def _normalize_tool_calls(tc_list: list) -> list[dict]:
9298
# Extract reasoning/thinking parts into reasoning_content
9399
reasoning_content = None
94100
if isinstance(msg.content, list):
95-
collected = [it.get("thinking", "") for it in msg.content if isinstance(it, dict) and it.get("type") == "thinking"]
101+
collected = [
102+
it.get("thinking", "") for it in msg.content if isinstance(it, dict) and it.get("type") == "thinking"
103+
]
96104
if collected:
97105
reasoning_content = "\n\n".join([s for s in collected if s]) or None
98106

99-
ep_msg = Message(role="assistant", content=content, tool_calls=tool_calls_payload, reasoning_content=reasoning_content)
100-
_dbg_print("[EP-Ser] -> EP Message:", {
101-
"role": ep_msg.role,
102-
"content_len": len(ep_msg.content or ""),
103-
"tool_calls": len(ep_msg.tool_calls or []) if isinstance(ep_msg.tool_calls, list) else 0,
104-
})
107+
ep_msg = Message(
108+
role="assistant", content=content, tool_calls=tool_calls_payload, reasoning_content=reasoning_content
109+
)
110+
_dbg_print(
111+
"[EP-Ser] -> EP Message:",
112+
{
113+
"role": ep_msg.role,
114+
"content_len": len(ep_msg.content or ""),
115+
"tool_calls": len(ep_msg.tool_calls or []) if isinstance(ep_msg.tool_calls, list) else 0,
116+
},
117+
)
105118
return ep_msg
106119

107120
if isinstance(msg, ToolMessage):
@@ -113,13 +126,13 @@ def _normalize_tool_calls(tc_list: list) -> list[dict]:
113126
role="tool",
114127
name=tool_name,
115128
tool_call_id=tool_call_id,
116-
content=f"<{tool_name} status=\"{status}\">\n{content}\n</{tool_name}>",
129+
content=f'<{tool_name} status="{status}">\n{content}\n</{tool_name}>',
130+
)
131+
_dbg_print(
132+
"[EP-Ser] -> EP Message:", {"role": ep_msg.role, "name": ep_msg.name, "has_id": bool(ep_msg.tool_call_id)}
117133
)
118-
_dbg_print("[EP-Ser] -> EP Message:", {"role": ep_msg.role, "name": ep_msg.name, "has_id": bool(ep_msg.tool_call_id)})
119134
return ep_msg
120135

121136
ep_msg = Message(role=getattr(msg, "type", "assistant"), content=str(getattr(msg, "content", "")))
122137
_dbg_print("[EP-Ser] -> EP Message (fallback):", {"role": ep_msg.role, "len": len(ep_msg.content or "")})
123138
return ep_msg
124-
125-

eval_protocol/models.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ class ChatCompletionContentPartTextParam(BaseModel):
223223
type: Literal["text"] = Field("text", description="The type of the content part.")
224224

225225

226-
227-
228226
class Message(BaseModel):
229227
"""Chat message model with trajectory evaluation support."""
230228

eval_protocol/pytest/default_langchain_rollout_processor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __call__(self, rows: List[EvaluationRow], config: RolloutProcessorConfig):
2626
async def _process_row(row: EvaluationRow) -> EvaluationRow:
2727
# Build LC messages from EP row
2828
from langchain_core.messages import HumanMessage
29+
2930
lm_messages: List[BaseMessage] = []
3031
if row.messages:
3132
last_user = [m for m in row.messages if m.role == "user"]
@@ -42,6 +43,7 @@ async def _process_row(row: EvaluationRow) -> EvaluationRow:
4243
elif hasattr(target, "ainvoke"):
4344
invoke_fn = target.ainvoke
4445
elif callable(target):
46+
4547
async def _invoke_wrapper(payload):
4648
return await target(payload)
4749

@@ -56,6 +58,7 @@ def _serialize_message(msg: BaseMessage) -> Message:
5658
# Prefer SDK-level serializer
5759
try:
5860
from eval_protocol.adapters.langchain import serialize_lc_message_to_ep as _ser
61+
5962
return _ser(msg)
6063
except Exception:
6164
# Minimal fallback: best-effort string content only
@@ -72,5 +75,3 @@ def _serialize_message(msg: BaseMessage) -> Message:
7275

7376
def cleanup(self) -> None:
7477
return None
75-
76-

eval_protocol/pytest/default_single_turn_rollout_process.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,29 @@ async def process_row(row: EvaluationRow) -> EvaluationRow:
7474
converted_tool_calls = []
7575
for tool_call in tool_calls:
7676
try:
77-
converted_tool_calls.append({
78-
"id": tool_call.id,
79-
"type": tool_call.type,
80-
"function": {
81-
"name": tool_call.function.name,
82-
"arguments": tool_call.function.arguments,
83-
},
84-
})
77+
converted_tool_calls.append(
78+
{
79+
"id": tool_call.id,
80+
"type": tool_call.type,
81+
"function": {
82+
"name": tool_call.function.name,
83+
"arguments": tool_call.function.arguments,
84+
},
85+
}
86+
)
8587
except Exception:
8688
# best-effort: fallback to dict form
8789
try:
88-
converted_tool_calls.append({
89-
"id": getattr(tool_call, "id", "toolcall_0"),
90-
"type": getattr(tool_call, "type", "function"),
91-
"function": {
92-
"name": getattr(getattr(tool_call, "function", None), "name", "tool"),
93-
"arguments": getattr(getattr(tool_call, "function", None), "arguments", "{}"),
94-
},
95-
})
90+
converted_tool_calls.append(
91+
{
92+
"id": getattr(tool_call, "id", "toolcall_0"),
93+
"type": getattr(tool_call, "type", "function"),
94+
"function": {
95+
"name": getattr(getattr(tool_call, "function", None), "name", "tool"),
96+
"arguments": getattr(getattr(tool_call, "function", None), "arguments", "{}"),
97+
},
98+
}
99+
)
96100
except Exception:
97101
pass
98102

eval_protocol/pytest/evaluation_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ async def _collect_result(config, lst): # pyright: ignore[reportUnknownParamete
452452
{
453453
"role": m.role,
454454
"len": len(m.content or "") if isinstance(m.content, str) else None,
455-
"tool_calls": len(m.tool_calls or []) if hasattr(m, "tool_calls") and isinstance(m.tool_calls, list) else 0,
455+
"tool_calls": len(m.tool_calls or [])
456+
if hasattr(m, "tool_calls") and isinstance(m.tool_calls, list)
457+
else 0,
456458
"tool_call_id": getattr(m, "tool_call_id", None),
457459
"name": getattr(m, "name", None),
458460
}

0 commit comments

Comments
 (0)