postprocess0109.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. import json
  2. from config import simplemodel
  3. from template import xuanxiang
  4. with open('zhaoping_rule', 'r') as f:
  5. content = f.read()
  6. import json
  7. obj=json.loads(content)
  8. with open('name_label', 'r') as f:
  9. content = f.read()
  10. import json
  11. name_label=json.loads(content)
  12. baohuceng = ['10-74', '10-75', '10-77', '10-78', '10-80', '10-81', '10-83', '10-84', '10-86', '10-87', '10-90']
  13. from fallback import fallback
  14. def shuangceng(data,aiclient,sfclient):
  15. completion = aiclient.chat.completions.create(
  16. model='glm-4.5-air',
  17. messages=[
  18. {"role": "system", "content": "You are a helpful assistant."},
  19. {"role": "user", "content": " 在屋面卷材施工中,卷材可做一层(一道),可做两层(两道)。给你一段文字如下, " + data['tz'] + ",其中提及卷材施工,请问其中明确提及做两层(两道)吗?请回答是或者否"},
  20. ],
  21. extra_body={"thinking": {"type": "disabled"}},
  22. #extra_body={"enable_thinking": False},
  23. )
  24. json_string = completion.choices[0].message.content
  25. print(json_string)
  26. if len(json_string) < 4:
  27. if '否' in json_string:
  28. return False
  29. return True
  30. completion = sfclient.chat.completions.create(
  31. model=simplemodel(),
  32. messages=[
  33. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  34. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个是否施工两层卷材的判断,请将该判断输出,请输出是或者否"},
  35. ],
  36. extra_body={"thinking": {"type": "disabled"}},
  37. #extra_body={"enable_thinking": False},
  38. )
  39. json_string = completion.choices[0].message.content
  40. print(json_string)
  41. if '否' in json_string:
  42. return False
  43. return True
  44. def zhaopingceng(data,aiclient,sfclient):
  45. completion = aiclient.chat.completions.create(
  46. model='glm-4.5-air',
  47. messages=[
  48. {"role": "system", "content": "You are a helpful assistant."},
  49. {"role": "user", "content": " 在屋面防水施工中,细石混凝土可能做找平(找坡)层,也可能做面层(保护层)。给你一段文字如下, " + data['tz'] + ",其中提及细石混凝土,请问其中提及细石混凝土是做找平(找坡)层吗?请回答是或者否"},
  50. ],
  51. extra_body={"thinking": {"type": "disabled"}},
  52. #extra_body={"enable_thinking": False},
  53. )
  54. json_string = completion.choices[0].message.content
  55. print(json_string)
  56. if len(json_string) < 4:
  57. if '否' in json_string:
  58. return False
  59. return True
  60. completion = sfclient.chat.completions.create(
  61. model=simplemodel(),
  62. messages=[
  63. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  64. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个是否为细石混凝土找平层的判断,请将该判断输出,请输出是或者否"},
  65. ],
  66. extra_body={"thinking": {"type": "disabled"}},
  67. #extra_body={"enable_thinking": False},
  68. )
  69. json_string = completion.choices[0].message.content
  70. print(json_string)
  71. if '否' in json_string:
  72. return False
  73. return True
  74. def aifilter3(A, #options
  75. B, #data
  76. aiclient,
  77. qwclient,
  78. sfclient,
  79. dw):
  80. options=[]
  81. letters = "ABCDEFGHIJK"
  82. for i in range(len(baohuceng)):
  83. options.append("给定选项" + letters[i]+",内容为"+name_label[baohuceng[i]] )
  84. completion = aiclient.chat.completions.create(
  85. model="glm-4.5-flash",
  86. #model="Qwen/Qwen3-14B",
  87. messages=[
  88. {"role": "system", "content": "You are a helpful assistant."},
  89. {"role": "user", "content": " 重要提示:匹配保护层做法时,优先考虑材料的匹配性,比如,特征中描述是水泥砂浆,则优先选择水泥砂浆选项而不是防水砂浆选项"},
  90. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",其中包含了屋面保护层的做法。".join(options) + "。请根据工作内容中保护层的描述,选择最匹配的选项并返回结果。例如,如果C选项最匹配,请返回C"},
  91. ],
  92. extra_body={"thinking": {"type": "disabled"}},
  93. #extra_body={"enable_thinking": False},
  94. )
  95. json_string = completion.choices[0].message.content
  96. print(json_string)
  97. completion = sfclient.chat.completions.create(
  98. model=simplemodel(),
  99. messages=[
  100. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  101. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于A或者B的选项作为结果,请将该最终结果输出"},
  102. ],
  103. extra_body={"thinking": {"type": "disabled"}},
  104. #extra_body={"enable_thinking": False},
  105. )
  106. json_string = completion.choices[0].message.content
  107. print(json_string)
  108. answer=[]
  109. if 'A' in json_string:
  110. answer.append(name_label[baohuceng[0]])
  111. if 'B' in json_string:
  112. answer.append(name_label[baohuceng[1]])
  113. if 'C' in json_string:
  114. answer.append(name_label[baohuceng[2]])
  115. if 'D' in json_string:
  116. answer.append(name_label[baohuceng[3]])
  117. if 'E' in json_string:
  118. answer.append(name_label[baohuceng[4]])
  119. if 'F' in json_string:
  120. answer.append(name_label[baohuceng[5]])
  121. if 'G' in json_string:
  122. answer.append(name_label[baohuceng[6]])
  123. if 'H' in json_string:
  124. answer.append(name_label[baohuceng[7]])
  125. if 'I' in json_string:
  126. answer.append(name_label[baohuceng[8]])
  127. if 'J' in json_string:
  128. answer.append(name_label[baohuceng[9]])
  129. if 'K' in json_string:
  130. answer.append(name_label[baohuceng[10]])
  131. return answer
  132. def aifilter4(A, #options
  133. B, #data
  134. aiclient,
  135. qwclient,
  136. sfclient,
  137. dw):
  138. options=[]
  139. letters = "ABCDEFGHIJKLMN"
  140. for i in range(len(A)):
  141. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  142. completion = aiclient.chat.completions.create(
  143. model="glm-4.5-air",
  144. #model="Qwen/Qwen3-14B",
  145. messages=[
  146. {"role": "system", "content": "You are a helpful assistant."},
  147. {"role": "user", "content": " 背景知识:石油沥青,沥青马蹄脂,渗透结晶防水材料等都是防水涂料。砂浆隔离层、混凝土防水层不是防水涂料"},
  148. {"role": "user", "content": " 特殊处理要求:如果选项中有多个防水涂料的选项(砂浆隔离层、混凝土防水层不是防水涂料),则只能选择一个防水涂料选项,且优先选择渗透结晶防水材料;与防水涂料无关的选项全部保留"},
  149. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  150. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  151. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果,删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  152. ],
  153. extra_body={"thinking": {"type": "disabled"}},
  154. #extra_body={"enable_thinking": False},
  155. )
  156. json_string = completion.choices[0].message.content
  157. print(json_string)
  158. completion = sfclient.chat.completions.create(
  159. model=simplemodel(),
  160. messages=xuanxiang(json_string),
  161. extra_body={"thinking": {"type": "disabled"}},
  162. #extra_body={"enable_thinking": False},
  163. )
  164. json_string = completion.choices[0].message.content
  165. print(json_string)
  166. answer=[]
  167. if 'A' in json_string:
  168. answer.append(A[0])
  169. if 'B' in json_string:
  170. answer.append(A[1])
  171. if 'C' in json_string:
  172. answer.append(A[2])
  173. if 'D' in json_string:
  174. answer.append(A[3])
  175. if 'E' in json_string:
  176. answer.append(A[4])
  177. if 'F' in json_string:
  178. answer.append(A[5])
  179. if 'G' in json_string:
  180. answer.append(A[6])
  181. if 'H' in json_string:
  182. answer.append(A[7])
  183. if 'I' in json_string:
  184. answer.append(A[8])
  185. if 'J' in json_string:
  186. answer.append(A[9])
  187. return answer
  188. def aifilter1_1(A, #options
  189. B, #data
  190. aiclient,
  191. qwclient,
  192. sfclient,
  193. dw):
  194. options=[]
  195. letters = "ABCDEFGHIJKLMN"
  196. for i in range(len(A)):
  197. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  198. completion = aiclient.chat.completions.create(
  199. model="glm-4.5-air",
  200. #model="Qwen/Qwen3-8B",
  201. #model="ernie-speed-128k",
  202. messages=[
  203. {"role": "system", "content": "You are a helpful assistant."},
  204. {"role": "user", "content": " 特殊处理要求一:去掉所有含有“干铺卷材”字样的选项"},
  205. {"role": "user", "content": " 特殊处理要求二:如果工作内容描述中没有明确提到玻纤网格布,则去掉所有含有“玻纤网格布”字样的选项"},
  206. {"role": "user", "content": " 特殊处理要求三:如果工作内容描述的是屋面刚性层,则去掉所有精确含有‘卷材’字样的选项"},
  207. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  208. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  209. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果,删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  210. ],
  211. extra_body={"thinking": {"type": "disabled"}},
  212. #extra_body={"enable_thinking": True},
  213. #stream=True
  214. )
  215. #done_thinking = False
  216. #json_string=""
  217. #thinking_json_string=""
  218. #for chunk in completion:
  219. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  220. # answer_chunk = chunk.choices[0].delta.content
  221. # if thinking_chunk != '':
  222. # thinking_json_string = thinking_json_string + thinking_chunk
  223. # elif answer_chunk != '':
  224. # if not done_thinking:
  225. # done_thinking = True
  226. # json_string = json_string + answer_chunk
  227. json_string = completion.choices[0].message.content
  228. #print(thinking_json_string)
  229. print(json_string)
  230. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  231. answer=[]
  232. if 'A' in json_string and len(A) > 0:
  233. answer.append(A[0])
  234. if 'B' in json_string and len(A) > 1:
  235. answer.append(A[1])
  236. if 'C' in json_string and len(A) > 2:
  237. answer.append(A[2])
  238. if 'D' in json_string and len(A) > 3:
  239. answer.append(A[3])
  240. if 'E' in json_string and len(A) > 4:
  241. answer.append(A[4])
  242. if 'F' in json_string and len(A) > 5:
  243. answer.append(A[5])
  244. if 'G' in json_string and len(A) > 6:
  245. answer.append(A[6])
  246. if 'H' in json_string and len(A) > 7:
  247. answer.append(A[7])
  248. if 'I' in json_string and len(A) > 8:
  249. answer.append(A[8])
  250. if 'J' in json_string and len(A) > 9:
  251. answer.append(A[9])
  252. return answer
  253. completion = sfclient.chat.completions.create(
  254. model=simplemodel(),
  255. messages=xuanxiang(json_string),
  256. extra_body={"thinking": {"type": "disabled"}},
  257. #extra_body={"enable_thinking": False},
  258. )
  259. json_string = completion.choices[0].message.content
  260. print(json_string)
  261. answer=[]
  262. if 'A' in json_string:
  263. answer.append(A[0])
  264. if 'B' in json_string:
  265. answer.append(A[1])
  266. if 'C' in json_string:
  267. answer.append(A[2])
  268. if 'D' in json_string:
  269. answer.append(A[3])
  270. if 'E' in json_string:
  271. answer.append(A[4])
  272. if 'F' in json_string:
  273. answer.append(A[5])
  274. if 'G' in json_string:
  275. answer.append(A[6])
  276. if 'H' in json_string:
  277. answer.append(A[7])
  278. if 'I' in json_string:
  279. answer.append(A[8])
  280. if 'J' in json_string:
  281. answer.append(A[9])
  282. return answer
  283. def aifilter1_2(A, #options
  284. B, #data
  285. aiclient,
  286. qwclient,
  287. sfclient,
  288. dw):
  289. options=[]
  290. letters = "ABCDEFGHIJKLMN"
  291. for i in range(len(A)):
  292. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  293. completion = aiclient.chat.completions.create(
  294. model="glm-4.5-air",
  295. #model="Qwen/Qwen3-8B",
  296. #model="ernie-speed-128k",
  297. messages=[
  298. {"role": "system", "content": "You are a helpful assistant."},
  299. {"role": "user", "content": " 特殊处理要求一:如果工作内容描述没有明确的“加浆抹光”字样,则去掉所有含有“加浆抹光”字样的选项"},
  300. {"role": "user", "content": " 特殊处理要求二:如果工作内容描述没有单独的一道“素水泥浆”工序,则去掉所有含有“素水泥浆”字样的选项"},
  301. {"role": "user", "content": " 特殊处理要求三:如果选项中同时存在保温砂浆选项跟水泥砂浆选项,则去掉水泥砂浆的选项"},
  302. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  303. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  304. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果,删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  305. ],
  306. extra_body={"thinking": {"type": "disabled"}},
  307. #extra_body={"enable_thinking": True},
  308. #stream=True
  309. )
  310. #done_thinking = False
  311. #json_string=""
  312. #thinking_json_string=""
  313. #for chunk in completion:
  314. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  315. # answer_chunk = chunk.choices[0].delta.content
  316. # if thinking_chunk != '':
  317. # thinking_json_string = thinking_json_string + thinking_chunk
  318. # elif answer_chunk != '':
  319. # if not done_thinking:
  320. # done_thinking = True
  321. # json_string = json_string + answer_chunk
  322. json_string = completion.choices[0].message.content
  323. #print(thinking_json_string)
  324. print(json_string)
  325. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  326. answer=[]
  327. if 'A' in json_string and len(A) > 0:
  328. answer.append(A[0])
  329. if 'B' in json_string and len(A) > 1:
  330. answer.append(A[1])
  331. if 'C' in json_string and len(A) > 2:
  332. answer.append(A[2])
  333. if 'D' in json_string and len(A) > 3:
  334. answer.append(A[3])
  335. if 'E' in json_string and len(A) > 4:
  336. answer.append(A[4])
  337. if 'F' in json_string and len(A) > 5:
  338. answer.append(A[5])
  339. if 'G' in json_string and len(A) > 6:
  340. answer.append(A[6])
  341. if 'H' in json_string and len(A) > 7:
  342. answer.append(A[7])
  343. if 'I' in json_string and len(A) > 8:
  344. answer.append(A[8])
  345. if 'J' in json_string and len(A) > 9:
  346. answer.append(A[9])
  347. return answer
  348. completion = sfclient.chat.completions.create(
  349. model=simplemodel(),
  350. messages=xuanxiang(json_string),
  351. extra_body={"thinking": {"type": "disabled"}},
  352. #extra_body={"enable_thinking": False},
  353. )
  354. json_string = completion.choices[0].message.content
  355. print(json_string)
  356. answer=[]
  357. if 'A' in json_string:
  358. answer.append(A[0])
  359. if 'B' in json_string:
  360. answer.append(A[1])
  361. if 'C' in json_string:
  362. answer.append(A[2])
  363. if 'D' in json_string:
  364. answer.append(A[3])
  365. if 'E' in json_string:
  366. answer.append(A[4])
  367. if 'F' in json_string:
  368. answer.append(A[5])
  369. if 'G' in json_string:
  370. answer.append(A[6])
  371. if 'H' in json_string:
  372. answer.append(A[7])
  373. if 'I' in json_string:
  374. answer.append(A[8])
  375. if 'J' in json_string:
  376. answer.append(A[9])
  377. return answer
  378. def aifilter2(A, #options
  379. B, #data
  380. aiclient,
  381. qwclient,
  382. sfclient,
  383. dw):
  384. hit_wumian = False
  385. for entry in A:
  386. if entry in obj['wumian']:
  387. hit_wumian=True
  388. hit_loumian = False
  389. loumian_entry = ''
  390. for entry in A:
  391. if entry in obj['loumian']:
  392. hit_loumian=True
  393. loumian_entry = entry
  394. if hit_wumian and hit_loumian:
  395. return [x for x in A if x != loumian_entry]
  396. return A
  397. def postprocess0109(selected, data, aiclient, qwclient, sfclient, label_name, name_dw):
  398. juancai = [x for x in selected if 'SBS改性沥青防水卷材' in x or 'APP改性沥青防水卷材' in x]
  399. no_juancai = [x for x in selected if x not in juancai]
  400. group_juancai = [
  401. [name_label['10-30'],name_label['10-31']],
  402. [name_label['10-32'],name_label['10-33']],
  403. [name_label['10-34'],name_label['10-35']],
  404. [name_label['10-36'],name_label['10-37']],
  405. [name_label['10-38'],name_label['10-39']],
  406. [name_label['10-40'],name_label['10-41']],
  407. [name_label['10-42'],name_label['10-43']],
  408. [name_label['10-44'],name_label['10-45']],
  409. ]
  410. if len(juancai) > 0:
  411. hit_group=[]
  412. for entry in group_juancai:
  413. if juancai[0] in entry:
  414. hit_group=entry
  415. shuang = shuangceng(data,aiclient,sfclient)
  416. if shuang:
  417. selected = no_juancai + [hit_group[1]]
  418. else:
  419. selected = no_juancai + [hit_group[0]]
  420. if len([x for x in selected if '屋面找平层' in x and '细石混凝土' in x]) > 0:
  421. zhaoping = zhaopingceng(data,aiclient,sfclient)
  422. if not zhaoping:
  423. selected = [x for x in selected if not ('屋面找平层' in x and '细石混凝土' in x)]
  424. prime = aifilter1_1(selected, data, aiclient, qwclient, sfclient, name_dw)
  425. prime = aifilter1_2(prime, data, aiclient, qwclient, sfclient, name_dw)
  426. if data['bianma'].startswith("010902") and '高聚物' in data['tz'] and '改性沥青防水涂料' in data['tz']:##屋面防水
  427. if '第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.1 涂刷油类 水泥基渗透结晶 防水材料 二~三遍(厚2mm)' not in prime:
  428. prime.append('第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.1 涂刷油类 水泥基渗透结晶 防水材料 二~三遍(厚2mm)') ##需要换
  429. if data['bianma'].startswith("010902") and '非固化' in data['tz'] and '沥青防水涂料' in data['tz']:##屋面防水
  430. if '第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.1 涂刷油类 水泥基渗透结晶 防水材料 二~三遍(厚2mm)' not in prime:
  431. prime.append('第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.1 涂刷油类 水泥基渗透结晶 防水材料 二~三遍(厚2mm)') ##需要换
  432. prime = aifilter2(prime, data, aiclient, qwclient, sfclient, name_dw)##找平层去重
  433. prime = aifilter4(prime, data, aiclient, qwclient, sfclient, name_dw)##沥青去重
  434. if data['bianma'].startswith("010902") and '保护层' in data['tz']:##屋面防水保护层
  435. l = len([x for x in prime if '刚性防水屋面' in x])
  436. if l==0:
  437. answer = aifilter3(prime, data, aiclient, qwclient, sfclient, name_dw)
  438. prime.append(answer[0])
  439. if '南通补充定额 南通补充定额2016 第十章 屋面及防水工程 干铺法施工水泥彩瓦屋面(砼屋面板上钉钢挂瓦条、顺水条)' in prime:
  440. prime.append('南通补充定额 南通补充定额2016 第十章 屋面及防水工程 干铺法施工水泥彩瓦屋面(铺瓦)')
  441. return prime