29 lines
3.3 KiB
Python
29 lines
3.3 KiB
Python
from pathlib import Path
|
||
root=Path('C:/kefu')
|
||
p=root/'wechat_rpa/knowledge_worker.py';s=p.read_text(encoding='utf-8')
|
||
s=s.replace('from knowledge_processing import feed, finish, redact', 'from knowledge_processing import feed, finish\nfrom knowledge_model_output import ModelOutputError, normalize_output, original_draft')
|
||
s=s.replace('"保留限制条件;个人医疗处置不得改成普遍建议。只返回 JSON:"', '''"保留限制条件;个人医疗处置不得改成普遍建议。"
|
||
"question 和 answer 必须为非空字符串,分别不超过 4000 和 8000 字符;"
|
||
"title 不超过 160 字符,category 不超过 100 字符,conditions 不超过 2000 字符。"
|
||
"无法确认适用条件时 conditions 返回空字符串,不得编造。只返回 JSON:"''')
|
||
start=s.index(' if result.get("error") or not result.get("text"):')
|
||
end=s.index('\n\n\nclass KnowledgeWorker:',start)
|
||
s=s[:start]+''' if result.get("error"):
|
||
raise ValueError(safe_model_error(result['error']))
|
||
return normalize_output(candidate, result.get('text'), len(prompt))
|
||
'''+s[end:]
|
||
s=s.replace(" candidate, input_chars, output_chars = enhance(candidate, self.store.database, options)", ''' try:
|
||
candidate, input_chars, output_chars = enhance(candidate, self.store.database, options)
|
||
except ModelOutputError as exc:
|
||
candidate = original_draft(candidate, exc)
|
||
input_chars, output_chars = exc.input_chars, exc.output_chars
|
||
options['model_format_fallbacks'] = options.get('model_format_fallbacks', 0) + 1
|
||
options['model_last_warning'] = str(exc)
|
||
# A bad response affects this draft only. Transport/auth/budget errors still stop the job.''')
|
||
s=s.replace("duplicates=duplicates+?,input_chars=input_chars+?,output_chars=output_chars+?,updated_at=?", "duplicates=duplicates+?,input_chars=input_chars+?,output_chars=output_chars+?,options_json=?,updated_at=?")
|
||
s=s.replace("int(created), int(not created), input_chars, output_chars, utc_now(), job['id']))", "int(created), int(not created), input_chars, output_chars, json_text(options), utc_now(), job['id']))")
|
||
p.write_text(s,encoding='utf-8',newline='\n')
|
||
p=root/'admin-web/apps/web-antd/src/api/knowledge.ts';s=p.read_text(encoding='utf-8').replace('model_timeout_seconds?: number; max_messages:', 'model_timeout_seconds?: number; model_format_fallbacks?: number; model_last_warning?: string; max_messages:');p.write_text(s,encoding='utf-8',newline='\n')
|
||
p=root/'admin-web/apps/web-antd/src/views/knowledge/center.vue';s=p.read_text(encoding='utf-8').replace('<div>草稿 {{ record.created_items }} · 重复 {{ record.duplicates }} · 无效消息 {{ record.skipped }}</div>', '''<div>草稿 {{ record.created_items }} · 重复 {{ record.duplicates }} · 无效消息 {{ record.skipped }}</div>
|
||
<div v-if="record.options.model_format_fallbacks" class="max-w-xs text-amber-500">模型格式异常 {{ record.options.model_format_fallbacks }} 条,已保留原文待审,任务继续处理。<span v-if="record.options.model_last_warning">最近原因:{{ record.options.model_last_warning }}</span></div>''');p.write_text(s,encoding='utf-8',newline='\n')
|