postprocess0112.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. import time
  2. from fallback import fallback
  3. from config import simplemodel
  4. from template import xuanxiang
  5. import json
  6. with open('zhaoping_rule', 'r') as f:
  7. content = f.read()
  8. import json
  9. obj=json.loads(content)
  10. with open('name_label', 'r') as f:
  11. content = f.read()
  12. import json
  13. name_label=json.loads(content)
  14. baohuceng = ['10-74', '10-75', '10-77', '10-78', '10-80', '10-81', '10-83', '10-84', '10-86', '10-87', '10-90']
  15. pair=[
  16. [name_label['14-1'],name_label['14-2']],
  17. [name_label['14-8'],name_label['14-10']],
  18. [name_label['14-9'],name_label['14-11']],
  19. [name_label['14-25'],name_label['14-26']],
  20. [name_label['14-37'],name_label['14-39']],
  21. [name_label['14-38'],name_label['14-40']],
  22. [name_label['14-48'],name_label['14-49']],
  23. [name_label['14-50'],name_label['14-52']],
  24. [name_label['14-51'],name_label['14-53']],
  25. ]
  26. from fallback import fallback
  27. def aifilter5(A, #options
  28. B, #data
  29. aiclient,
  30. qwclient,
  31. sfclient,
  32. dw):
  33. options=[]
  34. letters = "ABCDEFGHIJKLMN"
  35. for i in range(len(A)):
  36. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  37. completion = aiclient.chat.completions.create(
  38. #model="THUDM/GLM-4-9B-0414",
  39. model="glm-4.5-air",
  40. #model="Qwen/Qwen3-8B",
  41. #model="ernie-speed-128k",
  42. messages=[
  43. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  44. {"role": "user", "content": "问题描述: " ",".join(options) + "。请问选项中是否有龙骨选项?" + '''
  45. 如果有,请回答
  46. {
  47. 'answer': '有'
  48. }
  49. 如果没有,请回答
  50. {
  51. 'answer': '没有'
  52. }
  53. '''
  54. },
  55. ],
  56. extra_body={"thinking": {"type": "disabled"}},
  57. #extra_body={"enable_thinking": True},
  58. #stream=True
  59. )
  60. json_string = completion.choices[0].message.content
  61. print(json_string)
  62. if len(json_string.replace(" ", "")) < 10:
  63. if '没有' in json_string:
  64. return False
  65. return True
  66. completion = sfclient.chat.completions.create(
  67. model=simplemodel(),
  68. messages=[
  69. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  70. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个“有”或者“没有”的判断,请将该中文判断输出" + '''
  71. 如果有,请回答
  72. {
  73. 'answer': '有'
  74. }
  75. 如果没有,请回答
  76. {
  77. 'answer': '没有'
  78. }
  79. 你只需要输出结果,不要输出分析过程
  80. '''
  81. },
  82. ],
  83. extra_body={"thinking": {"type": "disabled"}},
  84. #extra_body={"enable_thinking": False},
  85. )
  86. json_string = completion.choices[0].message.content
  87. print(json_string)
  88. if '没有' in json_string:
  89. return False
  90. return True
  91. def aifilter6(A, #options
  92. B, #data
  93. aiclient,
  94. qwclient,
  95. sfclient,
  96. dw):
  97. options=[]
  98. letters = "ABCDEFGHIJKLMN"
  99. for i in range(len(A)):
  100. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  101. completion = aiclient.chat.completions.create(
  102. #model="THUDM/GLM-4-9B-0414",
  103. model="glm-4.5-air",
  104. #model="Qwen/Qwen3-8B",
  105. #model="ernie-speed-128k",
  106. messages=[
  107. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  108. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + "。请问该工作内容的描述中有提及混凝土墙、柱面免除抹灰吗?" + '''
  109. 如果有提及,请回答
  110. {
  111. 'answer': '有'
  112. }
  113. 如果没有提及,请回答
  114. {
  115. 'answer': '没有'
  116. }
  117. '''
  118. },
  119. ],
  120. extra_body={"thinking": {"type": "disabled"}},
  121. #extra_body={"enable_thinking": True},
  122. #stream=True
  123. )
  124. json_string = completion.choices[0].message.content
  125. print(json_string)
  126. if len(json_string.replace(" ", "")) < 10:
  127. if '没有' in json_string:
  128. return False
  129. return True
  130. completion = sfclient.chat.completions.create(
  131. model=simplemodel(),
  132. messages=[
  133. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  134. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个“有”或者“没有”的判断,请将该中文判断输出" + '''
  135. 如果有,请回答
  136. {
  137. 'answer': '有'
  138. }
  139. 如果没有,请回答
  140. {
  141. 'answer': '没有'
  142. }
  143. 你只需要输出结果,不要输出分析过程
  144. '''
  145. },
  146. ],
  147. extra_body={"thinking": {"type": "disabled"}},
  148. #extra_body={"enable_thinking": False},
  149. )
  150. json_string = completion.choices[0].message.content
  151. print(json_string)
  152. if '没有' in json_string:
  153. return False
  154. return True
  155. def aifilter3(A, #options
  156. B, #data
  157. aiclient,
  158. qwclient,
  159. sfclient,
  160. dw):
  161. options=[]
  162. letters = "ABCDEFGHIJKLMN"
  163. for i in range(len(A)):
  164. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  165. completion = aiclient.chat.completions.create(
  166. #model="THUDM/GLM-4-9B-0414",
  167. model="glm-4.5-air",
  168. #model="Qwen/Qwen3-8B",
  169. #model="ernie-speed-128k",
  170. messages=[
  171. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  172. {"role": "user", "content": "问题描述: 墙面装饰工程可分为外墙装饰或者内墙装饰。给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + "。请问该工作内容的描述指的是内墙还是外墙?" + '''
  173. 如果是外墙,请回答
  174. {
  175. 'answer': '外墙'
  176. }
  177. 如果是内墙,请回答
  178. {
  179. 'answer': '内墙'
  180. }
  181. 如果无法确定,请回答
  182. {
  183. 'answer': '不确定'
  184. }
  185. '''
  186. },
  187. ],
  188. extra_body={"thinking": {"type": "disabled"}},
  189. #extra_body={"enable_thinking": True},
  190. #stream=True
  191. )
  192. json_string = completion.choices[0].message.content
  193. print(json_string)
  194. if len(json_string.replace(" ", "")) < 10:
  195. if '外墙' in json_string:
  196. return False
  197. return True
  198. completion = sfclient.chat.completions.create(
  199. model=simplemodel(),
  200. messages=[
  201. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  202. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个“外墙”或者“内墙”的判断,请将该中文判断输出" + '''
  203. 如果是外墙,请回答
  204. {
  205. 'answer': '外墙'
  206. }
  207. 如果是内墙,请回答
  208. {
  209. 'answer': '内墙'
  210. }
  211. 如果无法确定,请回答
  212. {
  213. 'answer': '不确定'
  214. }
  215. 你只需要输出结果,不要输出分析过程
  216. '''
  217. },
  218. ],
  219. extra_body={"thinking": {"type": "disabled"}},
  220. #extra_body={"enable_thinking": False},
  221. )
  222. json_string = completion.choices[0].message.content
  223. print(json_string)
  224. if '外墙' in json_string:
  225. return False
  226. return True
  227. def aifilter4(A, #options
  228. B, #data
  229. aiclient,
  230. qwclient,
  231. sfclient,
  232. dw):
  233. options=[]
  234. letters = "ABCDEFGHIJKLMN"
  235. for i in range(len(A)):
  236. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  237. completion = aiclient.chat.completions.create(
  238. model="glm-4.5-air",
  239. #model="THUDM/GLM-Z1-9B-0414",
  240. #model="ernie-speed-128k",
  241. messages=[
  242. {"role": "system", "content": "You are a helpful assistant."},
  243. {"role": "user", "content": " 特殊处理要求一:如果工作内容没有提及界面剂,则去掉所有含有“界面剂”字样的选项"},
  244. {"role": "user", "content": " 特殊处理要求二:如果选项中既有墙柱面一般抹灰的选项(夹板基层**不**属于一般抹灰,龙骨**不**属于一般抹灰,刷界面剂**不**属于一般抹灰),又有镶贴块料面层及幕墙的选项,则去掉墙柱面一般抹灰的选项"},
  245. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  246. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  247. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果, 删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  248. ],
  249. extra_body={"thinking": {"type": "disabled"}},
  250. #extra_body={"enable_thinking": True},
  251. #stream=True
  252. )
  253. #done_thinking = False
  254. #json_string=""
  255. #thinking_json_string=""
  256. #for chunk in completion:
  257. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  258. # answer_chunk = chunk.choices[0].delta.content
  259. # if thinking_chunk != '':
  260. # thinking_json_string = thinking_json_string + thinking_chunk
  261. # elif answer_chunk != '':
  262. # if not done_thinking:
  263. # done_thinking = True
  264. # json_string = json_string + answer_chunk
  265. json_string = completion.choices[0].message.content
  266. #print(completion.choices[0].message.reasoning_content)
  267. print(json_string)
  268. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  269. answer=[]
  270. if 'A' in json_string and len(A) > 0:
  271. answer.append(A[0])
  272. if 'B' in json_string and len(A) > 1:
  273. answer.append(A[1])
  274. if 'C' in json_string and len(A) > 2:
  275. answer.append(A[2])
  276. if 'D' in json_string and len(A) > 3:
  277. answer.append(A[3])
  278. if 'E' in json_string and len(A) > 4:
  279. answer.append(A[4])
  280. if 'F' in json_string and len(A) > 5:
  281. answer.append(A[5])
  282. if 'G' in json_string and len(A) > 6:
  283. answer.append(A[6])
  284. if 'H' in json_string and len(A) > 7:
  285. answer.append(A[7])
  286. if 'I' in json_string and len(A) > 8:
  287. answer.append(A[8])
  288. if 'J' in json_string and len(A) > 9:
  289. answer.append(A[9])
  290. return answer
  291. completion = sfclient.chat.completions.create(
  292. #model="glm-4.5-flash",
  293. model=simplemodel(),
  294. messages=xuanxiang(json_string),
  295. extra_body={"thinking": {"type": "disabled"}},
  296. #extra_body={"enable_thinking": False},
  297. )
  298. json_string = completion.choices[0].message.content
  299. print(json_string)
  300. answer=[]
  301. if 'A' in json_string and len(A) > 0:
  302. answer.append(A[0])
  303. if 'B' in json_string and len(A) > 1:
  304. answer.append(A[1])
  305. if 'C' in json_string and len(A) > 2:
  306. answer.append(A[2])
  307. if 'D' in json_string and len(A) > 3:
  308. answer.append(A[3])
  309. if 'E' in json_string and len(A) > 4:
  310. answer.append(A[4])
  311. if 'F' in json_string and len(A) > 5:
  312. answer.append(A[5])
  313. if 'G' in json_string and len(A) > 6:
  314. answer.append(A[6])
  315. if 'H' in json_string and len(A) > 7:
  316. answer.append(A[7])
  317. if 'I' in json_string and len(A) > 8:
  318. answer.append(A[8])
  319. if 'J' in json_string and len(A) > 9:
  320. answer.append(A[9])
  321. return answer
  322. def aifilter1(A, #options
  323. B, #data
  324. aiclient,
  325. qwclient,
  326. sfclient,
  327. dw):
  328. options=[]
  329. letters = "ABCDEFGHIJKLMN"
  330. for i in range(len(A)):
  331. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  332. completion = aiclient.chat.completions.create(
  333. model="glm-4.5-air",
  334. #model="THUDM/GLM-Z1-9B-0414",
  335. #model="ernie-speed-128k",
  336. messages=[
  337. {"role": "system", "content": "You are a helpful assistant."},
  338. {"role": "user", "content": " 特殊处理要求一:去掉所有刷素水泥浆的选项"},
  339. {"role": "user", "content": " 特殊处理要求二:去掉所有精确含有“天棚工程”四个字的选项,不得删除含有“天棚及其他”五个字的选项"},
  340. {"role": "user", "content": " 特殊处理要求三:如果工作内容中没有提及铝板、铝单板,则删除含有“铝板幕墙”四个字的选项"},
  341. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  342. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  343. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果, 删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  344. ],
  345. extra_body={"thinking": {"type": "disabled"}},
  346. #extra_body={"enable_thinking": True},
  347. #stream=True
  348. )
  349. #done_thinking = False
  350. #json_string=""
  351. #thinking_json_string=""
  352. #for chunk in completion:
  353. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  354. # answer_chunk = chunk.choices[0].delta.content
  355. # if thinking_chunk != '':
  356. # thinking_json_string = thinking_json_string + thinking_chunk
  357. # elif answer_chunk != '':
  358. # if not done_thinking:
  359. # done_thinking = True
  360. # json_string = json_string + answer_chunk
  361. json_string = completion.choices[0].message.content
  362. #print(completion.choices[0].message.reasoning_content)
  363. print(json_string)
  364. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  365. answer=[]
  366. if 'A' in json_string and len(A) > 0:
  367. answer.append(A[0])
  368. if 'B' in json_string and len(A) > 1:
  369. answer.append(A[1])
  370. if 'C' in json_string and len(A) > 2:
  371. answer.append(A[2])
  372. if 'D' in json_string and len(A) > 3:
  373. answer.append(A[3])
  374. if 'E' in json_string and len(A) > 4:
  375. answer.append(A[4])
  376. if 'F' in json_string and len(A) > 5:
  377. answer.append(A[5])
  378. if 'G' in json_string and len(A) > 6:
  379. answer.append(A[6])
  380. if 'H' in json_string and len(A) > 7:
  381. answer.append(A[7])
  382. if 'I' in json_string and len(A) > 8:
  383. answer.append(A[8])
  384. if 'J' in json_string and len(A) > 9:
  385. answer.append(A[9])
  386. return answer
  387. completion = sfclient.chat.completions.create(
  388. #model="glm-4.5-flash",
  389. model=simplemodel(),
  390. messages=xuanxiang(json_string),
  391. extra_body={"thinking": {"type": "disabled"}},
  392. #extra_body={"enable_thinking": False},
  393. )
  394. json_string = completion.choices[0].message.content
  395. print(json_string)
  396. answer=[]
  397. if 'A' in json_string and len(A) > 0:
  398. answer.append(A[0])
  399. if 'B' in json_string and len(A) > 1:
  400. answer.append(A[1])
  401. if 'C' in json_string and len(A) > 2:
  402. answer.append(A[2])
  403. if 'D' in json_string and len(A) > 3:
  404. answer.append(A[3])
  405. if 'E' in json_string and len(A) > 4:
  406. answer.append(A[4])
  407. if 'F' in json_string and len(A) > 5:
  408. answer.append(A[5])
  409. if 'G' in json_string and len(A) > 6:
  410. answer.append(A[6])
  411. if 'H' in json_string and len(A) > 7:
  412. answer.append(A[7])
  413. if 'I' in json_string and len(A) > 8:
  414. answer.append(A[8])
  415. if 'J' in json_string and len(A) > 9:
  416. answer.append(A[9])
  417. return answer
  418. def aifilter2(A, #options
  419. B, #data
  420. aiclient,
  421. qwclient,
  422. dw):
  423. hit_wumian = False
  424. for entry in A:
  425. if entry in obj['wumian']:
  426. hit_wumian=True
  427. hit_loumian = False
  428. loumian_entry = ''
  429. for entry in A:
  430. if entry in obj['loumian']:
  431. hit_loumian=True
  432. loumian_entry = entry
  433. if hit_wumian and hit_loumian:
  434. return [x for x in A if x != loumian_entry]
  435. return A
  436. def postprocess0112(selected, data, aiclient, qwclient, sfclient, label_name, name_dw, candidates):
  437. hit=[]
  438. hit_pair=[]
  439. for entry in selected:
  440. for p in pair:
  441. if p[1] == entry:
  442. hit = [entry]
  443. hit_pair = p
  444. if len(hit)>0:
  445. mian = aifilter6(selected, data, aiclient, qwclient, sfclient, name_dw)
  446. if mian:
  447. selected = [x for x in selected if not x == hit[0]]
  448. selected.append(hit_pair[0])
  449. selected = [x for x in selected if '木地板' not in x]
  450. selected = [x for x in selected if '铁件安装' not in x]
  451. selected = [x for x in selected if '铁件制作' not in x]
  452. if '防水砂浆' in data['tz'] or '防潮层' in data['tz']:
  453. if '第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.2 防水砂浆 (防水砂浆 1:2)防水砂浆 立面' not in selected:
  454. selected.append('第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.2 防水砂浆 (防水砂浆 1:2)防水砂浆 立面')
  455. neiqiang = aifilter3(selected, data, aiclient, qwclient, sfclient, name_dw)
  456. if neiqiang and len([x for x in selected if '外墙釉面砖' in x]) > 0:
  457. selected = [x for x in selected if not '外墙釉面砖' in x]
  458. selected.append('第十四章 墙柱面工程 14.3 镶贴块料面层及幕墙 14.3.1 瓷砖 单块面积0.18m2以内墙砖 砂浆粘贴 墙面')
  459. prime = aifilter1(selected, data, aiclient, qwclient, sfclient, name_dw)
  460. prime = aifilter4(prime, data, aiclient, qwclient, sfclient, name_dw)
  461. if len([x for x in prime if '钢骨架安装' in x or '钢骨架制作' in x or '钉在龙骨上' in x]) > 0:
  462. if data['dw'] == 'm2':
  463. t = [x for x in prime if '钢骨架安装' not in x and '钢骨架制作' not in x and '钉在龙骨上' not in x]
  464. longgu = aifilter5(t, data, aiclient, qwclient, sfclient, name_dw)
  465. if not longgu:
  466. prime = prime + [name_label['14-180']]
  467. prime = [x for x in prime if '钢骨架安装' not in x and '钢骨架制作' not in x]
  468. if len(prime) == 0:
  469. selected = fallback(candidates, data, aiclient, qwclient, sfclient, None, None)
  470. return selected
  471. if '界面剂' in data['tz']:
  472. if len([x for x in prime if '界面剂' in x])==0:
  473. prime.append('第十四章 墙柱面工程 14.1 一般抹灰 14.1.3 保温砂浆及抗裂基层 刷界面剂 混凝土面')
  474. return prime