postprocess0110.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import json
  2. with open('zhaoping_rule', 'r') as f:
  3. content = f.read()
  4. import json
  5. obj=json.loads(content)
  6. with open('name_label', 'r') as f:
  7. content = f.read()
  8. import json
  9. name_label=json.loads(content)
  10. baohuceng = ['10-74', '10-75', '10-77', '10-78', '10-80', '10-81', '10-83', '10-84', '10-86', '10-87', '10-90']
  11. from fallback import fallback
  12. def aifilter4(A, #options
  13. B, #data
  14. aiclient,
  15. qwclient,
  16. dw):
  17. options=[]
  18. letters = "ABCDEFGHIJKLMN"
  19. for i in range(len(A)):
  20. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  21. completion = qwclient.chat.completions.create(
  22. #model="glm-z1-flash",
  23. model="Qwen/Qwen3-8B",
  24. #model="ernie-speed-128k",
  25. messages=[
  26. {"role": "system", "content": "You are a helpful assistant."},
  27. {"role": "user", "content": " 背景知识:土建施工中,保温做法有很多种,包括保温砖,保温瓦,保温砂浆,保温板等。保温板有不同材料,比如聚苯乙烯泡沫板,聚苯乙烯挤塑板,聚氨酯保温板等"},
  28. {"role": "user", "content": "问题描述:" + ",".join(options) + "。请问选项中是否有保温板的选项?请回答是或者否"},
  29. ],
  30. #extra_body={"thinking": {"type": "enabled"}},
  31. extra_body={"enable_thinking": True},
  32. stream=True
  33. )
  34. done_thinking = False
  35. json_string=""
  36. thinking_json_string=""
  37. for chunk in completion:
  38. thinking_chunk = chunk.choices[0].delta.reasoning_content
  39. answer_chunk = chunk.choices[0].delta.content
  40. if thinking_chunk != '':
  41. thinking_json_string = thinking_json_string + thinking_chunk
  42. elif answer_chunk != '':
  43. if not done_thinking:
  44. done_thinking = True
  45. json_string = json_string + answer_chunk
  46. #json_string = completion.choices[0].message.content
  47. print(thinking_json_string)
  48. print(json_string)
  49. if len(json_string) < 4:
  50. if '否' in json_string:
  51. return False
  52. return True
  53. completion = aiclient.chat.completions.create(
  54. model="glm-4.5-flash",
  55. messages=[
  56. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  57. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个是或者否的判断,请将该判断输出"},
  58. ],
  59. extra_body={"thinking": {"type": "disabled"}},
  60. #extra_body={"enable_thinking": False},
  61. )
  62. json_string = completion.choices[0].message.content
  63. print(json_string)
  64. if '否' in json_string:
  65. return False
  66. return True
  67. def aifilter3(A, #options
  68. B, #data
  69. aiclient,
  70. qwclient,
  71. dw):
  72. options=[]
  73. letters = "ABCDEFGHIJKLMN"
  74. for i in range(len(A)):
  75. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  76. completion = qwclient.chat.completions.create(
  77. #model="glm-z1-flash",
  78. model="Qwen/Qwen3-8B",
  79. #model="ernie-speed-128k",
  80. messages=[
  81. {"role": "system", "content": "You are a helpful assistant."},
  82. {"role": "user", "content": " 背景知识:土建施工中,保温做法有很多种,包括保温砖,保温瓦,保温砂浆,保温板等。保温板有不同材料,比如聚苯乙烯泡沫板,聚苯乙烯挤塑板,聚氨酯保温板, 岩棉保温板等"},
  83. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + "。请问工作内容的描述中有涉及保温板吗?请回答是或者否"},
  84. ],
  85. #extra_body={"thinking": {"type": "enabled"}},
  86. extra_body={"enable_thinking": True},
  87. stream=True
  88. )
  89. done_thinking = False
  90. json_string=""
  91. thinking_json_string=""
  92. for chunk in completion:
  93. thinking_chunk = chunk.choices[0].delta.reasoning_content
  94. answer_chunk = chunk.choices[0].delta.content
  95. if thinking_chunk != '':
  96. thinking_json_string = thinking_json_string + thinking_chunk
  97. elif answer_chunk != '':
  98. if not done_thinking:
  99. done_thinking = True
  100. json_string = json_string + answer_chunk
  101. #json_string = completion.choices[0].message.content
  102. print(thinking_json_string)
  103. print(json_string)
  104. if len(json_string) < 4:
  105. if '否' in json_string:
  106. return False
  107. return True
  108. completion = aiclient.chat.completions.create(
  109. model="glm-4.5-flash",
  110. messages=[
  111. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  112. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个是或者否的判断,请将该判断输出"},
  113. ],
  114. extra_body={"thinking": {"type": "disabled"}},
  115. #extra_body={"enable_thinking": False},
  116. )
  117. json_string = completion.choices[0].message.content
  118. print(json_string)
  119. if '否' in json_string:
  120. return False
  121. return True
  122. def aifilter1(A, #options
  123. B, #data
  124. aiclient,
  125. qwclient,
  126. dw):
  127. options=[]
  128. letters = "ABCDEFGHIJKLMN"
  129. for i in range(len(A)):
  130. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  131. completion = qwclient.chat.completions.create(
  132. #model="glm-z1-flash",
  133. model="Qwen/Qwen3-8B",
  134. #model="ernie-speed-128k",
  135. messages=[
  136. {"role": "system", "content": "You are a helpful assistant."},
  137. {"role": "user", "content": " 特殊处理要求:如果工作内容描述中没有明确提到素水泥浆,则去掉所有含有“素水泥浆”字样的选项"},
  138. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  139. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  140. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  141. ],
  142. #extra_body={"thinking": {"type": "enabled"}},
  143. extra_body={"enable_thinking": True},
  144. stream=True
  145. )
  146. done_thinking = False
  147. json_string=""
  148. thinking_json_string=""
  149. for chunk in completion:
  150. thinking_chunk = chunk.choices[0].delta.reasoning_content
  151. answer_chunk = chunk.choices[0].delta.content
  152. if thinking_chunk != '':
  153. thinking_json_string = thinking_json_string + thinking_chunk
  154. elif answer_chunk != '':
  155. if not done_thinking:
  156. done_thinking = True
  157. json_string = json_string + answer_chunk
  158. #json_string = completion.choices[0].message.content
  159. print(thinking_json_string)
  160. print(json_string)
  161. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  162. answer=[]
  163. if 'A' in json_string and len(A) > 0:
  164. answer.append(A[0])
  165. if 'B' in json_string and len(A) > 1:
  166. answer.append(A[1])
  167. if 'C' in json_string and len(A) > 2:
  168. answer.append(A[2])
  169. if 'D' in json_string and len(A) > 3:
  170. answer.append(A[3])
  171. if 'E' in json_string and len(A) > 4:
  172. answer.append(A[4])
  173. if 'F' in json_string and len(A) > 5:
  174. answer.append(A[5])
  175. if 'G' in json_string and len(A) > 6:
  176. answer.append(A[6])
  177. if 'H' in json_string and len(A) > 7:
  178. answer.append(A[7])
  179. if 'I' in json_string and len(A) > 8:
  180. answer.append(A[8])
  181. if 'J' in json_string and len(A) > 9:
  182. answer.append(A[9])
  183. return answer
  184. completion = aiclient.chat.completions.create(
  185. model="glm-4.5-flash",
  186. messages=[
  187. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  188. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B,C]的数组作为结果,请将该最终结果输出"},
  189. ],
  190. extra_body={"thinking": {"type": "disabled"}},
  191. #extra_body={"enable_thinking": False},
  192. )
  193. json_string = completion.choices[0].message.content
  194. print(json_string)
  195. answer=[]
  196. if 'A' in json_string and len(A) > 0:
  197. answer.append(A[0])
  198. if 'B' in json_string and len(A) > 1:
  199. answer.append(A[1])
  200. if 'C' in json_string and len(A) > 2:
  201. answer.append(A[2])
  202. if 'D' in json_string and len(A) > 3:
  203. answer.append(A[3])
  204. if 'E' in json_string and len(A) > 4:
  205. answer.append(A[4])
  206. if 'F' in json_string and len(A) > 5:
  207. answer.append(A[5])
  208. if 'G' in json_string and len(A) > 6:
  209. answer.append(A[6])
  210. if 'H' in json_string and len(A) > 7:
  211. answer.append(A[7])
  212. if 'I' in json_string and len(A) > 8:
  213. answer.append(A[8])
  214. if 'J' in json_string and len(A) > 9:
  215. answer.append(A[9])
  216. return answer
  217. def aifilter2(A, #options
  218. B, #data
  219. aiclient,
  220. qwclient,
  221. dw):
  222. hit_wumian = False
  223. for entry in A:
  224. if entry in obj['wumian']:
  225. hit_wumian=True
  226. hit_loumian = False
  227. loumian_entry = ''
  228. for entry in A:
  229. if entry in obj['loumian']:
  230. hit_loumian=True
  231. loumian_entry = entry
  232. if hit_wumian and hit_loumian:
  233. return [x for x in A if x != loumian_entry]
  234. return A
  235. def postprocess0110(selected, data, aiclient, qwclient, label_name, name_dw):
  236. ban = aifilter3(selected, data, aiclient, qwclient, name_dw)
  237. if ban:
  238. ban2 = aifilter4(selected, data, aiclient, qwclient, name_dw)
  239. if not ban2:
  240. if '墙面' in data['mc']:
  241. selected.append('第十一章 保温、隔热、防腐工程 11.1 保温、隔热工程 11.1.2 墙、柱、天棚及其它 外墙外保温 聚苯乙烯挤塑板 厚度25mm 混凝土墙面')
  242. else:
  243. selected.append('第十一章 保温、隔热、防腐工程 11.1 保温、隔热工程 11.1.1 屋、楼地面 屋面、楼地面保温隔热 聚苯乙烯挤塑板(厚25mm)')
  244. prime = aifilter1(selected, data, aiclient, qwclient, name_dw)
  245. if '界面剂' in data['tz']:##保温
  246. if len([x for x in prime if '第十四章 墙柱面工程 14.1 一般抹灰 14.1.3 保温砂浆及抗裂基层 刷界面剂' in x]) == 0:
  247. prime.append('第十四章 墙柱面工程 14.1 一般抹灰 14.1.3 保温砂浆及抗裂基层 刷界面剂 混凝土面') ##需要换
  248. if '玻纤网' in data['tz']:##保温
  249. if '第十四章 墙柱面工程 14.1 一般抹灰 14.1.3 保温砂浆及抗裂基层 墙面耐碱玻纤网格布 一层' not in prime:
  250. prime.append('第十四章 墙柱面工程 14.1 一般抹灰 14.1.3 保温砂浆及抗裂基层 墙面耐碱玻纤网格布 一层') ##需要换
  251. return prime