postprocess0110.py 11 KB

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