This commit is contained in:
zyp
2026-11-18 16:01:50 +08:00
parent 0dc48ad092
commit 0c3d0c1ce4
30 changed files with 1525 additions and 93 deletions
+35 -3
View File
@@ -119,6 +119,35 @@ class DraftTable(Strict):
return self
def promises_bid_outcome(text):
# Match an explicit promise, not the noun "保证金" or obligations after winning.
promise = re.compile(
r'(?:确保|保证)(?:(?:我方|我们|本公司|本企业|本项目|本次投标|本次评审|本次|'
r'投标人|供应商|投标文件|评审得分|技术标|商务标|评审|评标|评分|'
r'一定|必定|必然|能够|可以|最终|顺利|成功|获得|取得|达到|拿到|得到|将|会|能|可)\s*){0,8}'
r'(?:高分|满分|中标)(?!后|人|单位|项目|通知书)')
for clause in re.split(r'[,,。;;!?!?\n]', text):
for match in promise.finditer(clause):
prefix = clause[:match.start()].rstrip()
if re.search(r'(?:不|未|无法|不能|不得|不应|不会|并非|禁止|严禁)(?:作出|承诺|声称)?$', prefix):
continue
return True
return False
def validation_summary(error):
"""Explain content/shape errors without exposing Pydantic input values or URLs."""
if not isinstance(error, ValidationError):
return str(error)[:500]
messages = []
for item in error.errors(include_input=False, include_url=False, include_context=False)[:5]:
message = (item['msg'].removeprefix('Value error, ') if item['type'] == 'value_error'
else '章节返回格式不完整或字段超出范围,请重新生成本节。')
if message not in messages:
messages.append(message)
return ';'.join(messages)[:500]
class Draft(Strict):
title: str = Field(min_length=1, max_length=150)
paragraphs: list[str] = Field(min_length=1, max_length=30)
@@ -137,7 +166,10 @@ class Draft(Strict):
sentences = [s.strip() for p in self.paragraphs for s in re.split(r'[。!?]', p) if len(s.strip()) >= 25]
if len(sentences) >= 8 and len(sentences)-len(set(sentences)) > len(sentences)*0.2:
raise ValueError("章节存在大段重复,需修订后发布")
if any(re.search(r'(?:确保|保证).{0,20}(?:高分|满分|中标)', p) for p in self.paragraphs):
prose = self.paragraphs + [cell for table in self.tables
for row in [table.columns, table.before, table.after] + table.rows
for cell in row]
if any(promises_bid_outcome(p) for p in prose):
raise ValueError("不得保证评审分数或中标结果")
return self
@@ -1140,7 +1172,7 @@ def _bid_step(request: BidStep, *, invoke=complete_json):
failures = progress.state.get('workbench_validation_failures', 0) + 1
progress.state['workbench_validation_failures'] = failures
if failures >= 6:
message = '本步骤已保留结果,连续校验仍未通过,请核对后重试:' + str(exc)[:900]
message = '本节草稿已保留,请修正后重试:' + validation_summary(exc)
progress.state['workbench_failure'] = message
progress.persist(True)
raise JobValidationBlocked(message) from exc
@@ -1155,7 +1187,7 @@ def _bid_step(request: BidStep, *, invoke=complete_json):
progress.persist(True)
if made_progress and attempt + 1 >= max_attempts:
raise JobDeferred()
detail = str(exc)
detail = validation_summary(exc)
code = next((name for phrase,name in [('重复段落','repeated_paragraph'),('大段重复','repeated_text'),
('评审分数','score_claim'),('原文','citation'),('超过章节','chapter_size'),
('表格','table_shape'),('终审','quality')] if phrase in detail), 'schema')