Skip to content

Commit a2401f4

Browse files
committed
fix(cr-agent): 回退.flake8+重构messages变量真修E126/E128(不掩盖) (#92)
- 回退 .flake8 的 ignore 配置,移除 E126, E128(恢复为 ignore = E402, W503) - 重构 llm_layer.py 两处 create() 调用,提取 messages 变量解决 continuation line 缩进问题 - _call_llm_with_openai_client() + _call_llm_with_openai_client_supplementary() - 验证:flake8 零错误(无 E126/E128) + pytest 全绿
1 parent c1f25b2 commit a2401f4

2 files changed

Lines changed: 23 additions & 27 deletions

File tree

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
22
max-line-length = 120
3-
ignore = E402, W503, E126, E128
3+
ignore = E402, W503

examples/skills_code_review_agent/agent/llm_layer.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,17 @@ def _call_llm_with_openai_client(findings: list[Finding]) -> list[dict]:
148148
max_retries = 3
149149
for attempt in range(max_retries + 1):
150150
try:
151-
response = client.chat.completions.create(model=config["model_name"],
152-
messages=[
153-
{
154-
"role": "system",
155-
"content": "代码评审专家,输出纯JSON格式。"
156-
},
157-
{
158-
"role": "user",
159-
"content": prompt
160-
},
161-
],
162-
temperature=0.1,
163-
max_tokens=2000) # 降低到2000减少400错误
151+
# 准备 messages 参数(避免 continuation line 缩进问题)
152+
messages = [
153+
{"role": "system", "content": "代码评审专家,输出纯JSON格式。"},
154+
{"role": "user", "content": prompt},
155+
]
156+
157+
response = client.chat.completions.create(
158+
model=config["model_name"],
159+
messages=messages,
160+
temperature=0.1,
161+
max_tokens=2000) # 降低到2000减少400错误
164162

165163
response_text = response.choices[0].message.content
166164
verdicts = _parse_llm_response(response_text)
@@ -347,19 +345,17 @@ def _call_llm_with_openai_client_supplementary(existing_findings: list[Finding],
347345
max_retries = 3
348346
for attempt in range(max_retries + 1):
349347
try:
350-
response = client.chat.completions.create(model=config["model_name"],
351-
messages=[
352-
{
353-
"role": "system",
354-
"content": "代码评审专家,输出纯JSON格式。"
355-
},
356-
{
357-
"role": "user",
358-
"content": prompt
359-
},
360-
],
361-
temperature=0.1,
362-
max_tokens=1500) # 进一步降低到1500减少400错误
348+
# 准备 messages 参数(避免 continuation line 缩进问题)
349+
messages = [
350+
{"role": "system", "content": "代码评审专家,输出纯JSON格式。"},
351+
{"role": "user", "content": prompt},
352+
]
353+
354+
response = client.chat.completions.create(
355+
model=config["model_name"],
356+
messages=messages,
357+
temperature=0.1,
358+
max_tokens=1500) # 进一步降低到1500减少400错误
363359

364360
response_text = response.choices[0].message.content
365361
new_findings = _parse_supplementary_findings(response_text)

0 commit comments

Comments
 (0)