postprocess0109.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 aifilter3(A, #options
  13. B, #data
  14. aiclient,
  15. qwclient,
  16. dw):
  17. options=[]
  18. letters = "ABCDEFGHIJK"
  19. for i in range(len(baohuceng)):
  20. options.append("给定选项" + letters[i]+",内容为"+name_label[baohuceng[i]] )
  21. completion = aiclient.chat.completions.create(
  22. model="glm-4.5-flash",
  23. #model="Qwen/Qwen3-14B",
  24. messages=[
  25. {"role": "system", "content": "You are a helpful assistant."},
  26. {"role": "user", "content": " 重要提示:匹配保护层做法时,优先考虑材料的匹配性,比如,特征中描述是水泥砂浆,则优先选择水泥砂浆选项而不是防水砂浆选项"},
  27. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",其中包含了屋面保护层的做法。".join(options) + "。请根据工作内容中保护层的描述,选择最匹配的选项并返回结果。例如,如果C选项最匹配,请返回C"},
  28. ],
  29. extra_body={"thinking": {"type": "disabled"}},
  30. #extra_body={"enable_thinking": False},
  31. )
  32. json_string = completion.choices[0].message.content
  33. print(json_string)
  34. completion = aiclient.chat.completions.create(
  35. model="glm-4.5-flash",
  36. messages=[
  37. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  38. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于A或者B的选项作为结果,请将该最终结果输出"},
  39. ],
  40. extra_body={"thinking": {"type": "disabled"}},
  41. #extra_body={"enable_thinking": False},
  42. )
  43. json_string = completion.choices[0].message.content
  44. print(json_string)
  45. answer=[]
  46. if 'A' in json_string:
  47. answer.append(name_label[baohuceng[0]])
  48. if 'B' in json_string:
  49. answer.append(name_label[baohuceng[1]])
  50. if 'C' in json_string:
  51. answer.append(name_label[baohuceng[2]])
  52. if 'D' in json_string:
  53. answer.append(name_label[baohuceng[3]])
  54. if 'E' in json_string:
  55. answer.append(name_label[baohuceng[4]])
  56. if 'F' in json_string:
  57. answer.append(name_label[baohuceng[5]])
  58. if 'G' in json_string:
  59. answer.append(name_label[baohuceng[6]])
  60. if 'H' in json_string:
  61. answer.append(name_label[baohuceng[7]])
  62. if 'I' in json_string:
  63. answer.append(name_label[baohuceng[8]])
  64. if 'J' in json_string:
  65. answer.append(name_label[baohuceng[9]])
  66. if 'K' in json_string:
  67. answer.append(name_label[baohuceng[10]])
  68. return answer
  69. def aifilter4(A, #options
  70. B, #data
  71. aiclient,
  72. qwclient,
  73. dw):
  74. options=[]
  75. letters = "ABCDEFGHIJKLMN"
  76. for i in range(len(A)):
  77. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  78. completion = aiclient.chat.completions.create(
  79. model="glm-z1-air",
  80. #model="Qwen/Qwen3-14B",
  81. messages=[
  82. {"role": "system", "content": "You are a helpful assistant."},
  83. {"role": "user", "content": " 背景知识:石油沥青,沥青马蹄脂,渗透结晶防水材料等都是防水涂料。"},
  84. {"role": "user", "content": " 特殊处理要求:如果选项中有多个防水涂料的选项,则只能选择一个防水涂料选项,且优先选择渗透结晶防水材料;与防水涂料无关的选项全部保留"},
  85. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  86. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  87. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  88. ],
  89. extra_body={"thinking": {"type": "enabled"}},
  90. #extra_body={"enable_thinking": False},
  91. )
  92. json_string = completion.choices[0].message.content
  93. print(json_string)
  94. completion = aiclient.chat.completions.create(
  95. model="glm-4.5-flash",
  96. messages=[
  97. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  98. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B,C]的数组作为结果,请将该最终结果输出"},
  99. ],
  100. extra_body={"thinking": {"type": "disabled"}},
  101. #extra_body={"enable_thinking": False},
  102. )
  103. json_string = completion.choices[0].message.content
  104. print(json_string)
  105. answer=[]
  106. if 'A' in json_string:
  107. answer.append(A[0])
  108. if 'B' in json_string:
  109. answer.append(A[1])
  110. if 'C' in json_string:
  111. answer.append(A[2])
  112. if 'D' in json_string:
  113. answer.append(A[3])
  114. if 'E' in json_string:
  115. answer.append(A[4])
  116. if 'F' in json_string:
  117. answer.append(A[5])
  118. if 'G' in json_string:
  119. answer.append(A[6])
  120. if 'H' in json_string:
  121. answer.append(A[7])
  122. if 'I' in json_string:
  123. answer.append(A[8])
  124. if 'J' in json_string:
  125. answer.append(A[9])
  126. return answer
  127. def aifilter1(A, #options
  128. B, #data
  129. aiclient,
  130. qwclient,
  131. dw):
  132. options=[]
  133. letters = "ABCDEFGHIJKLMN"
  134. for i in range(len(A)):
  135. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  136. completion = qwclient.chat.completions.create(
  137. #model="glm-z1-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": " 特殊处理要求:如果工作内容描述中没有明确提到玻纤网格布,则去掉所有含有“玻纤网格布”字样的选项"},
  144. {"role": "user", "content": " 特殊处理要求:如果工作内容描述的是屋面刚性层,则去掉所有含有卷材字样的选项"},
  145. {"role": "user", "content": " 特殊处理要求:如果工作内容描述没有明确的“加浆抹光”字样,则去掉所有含有“加浆抹光”字样的选项"},
  146. {"role": "user", "content": " 特殊处理要求:如果工作内容描述没有单独的一道“素水泥浆”工序,则去掉所有含有“素水泥浆”字样的选项"},
  147. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  148. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  149. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  150. ],
  151. #extra_body={"thinking": {"type": "enabled"}},
  152. extra_body={"enable_thinking": True},
  153. stream=True
  154. )
  155. done_thinking = False
  156. json_string=""
  157. thinking_json_string=""
  158. for chunk in completion:
  159. thinking_chunk = chunk.choices[0].delta.reasoning_content
  160. answer_chunk = chunk.choices[0].delta.content
  161. if thinking_chunk != '':
  162. thinking_json_string = thinking_json_string + thinking_chunk
  163. elif answer_chunk != '':
  164. if not done_thinking:
  165. done_thinking = True
  166. json_string = json_string + answer_chunk
  167. #json_string = completion.choices[0].message.content
  168. print(thinking_json_string)
  169. print(json_string)
  170. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  171. answer=[]
  172. if 'A' in json_string and len(A) > 0:
  173. answer.append(A[0])
  174. if 'B' in json_string and len(A) > 1:
  175. answer.append(A[1])
  176. if 'C' in json_string and len(A) > 2:
  177. answer.append(A[2])
  178. if 'D' in json_string and len(A) > 3:
  179. answer.append(A[3])
  180. if 'E' in json_string and len(A) > 4:
  181. answer.append(A[4])
  182. if 'F' in json_string and len(A) > 5:
  183. answer.append(A[5])
  184. if 'G' in json_string and len(A) > 6:
  185. answer.append(A[6])
  186. if 'H' in json_string and len(A) > 7:
  187. answer.append(A[7])
  188. if 'I' in json_string and len(A) > 8:
  189. answer.append(A[8])
  190. if 'J' in json_string and len(A) > 9:
  191. answer.append(A[9])
  192. return answer
  193. completion = aiclient.chat.completions.create(
  194. model="glm-4.5-flash",
  195. messages=[
  196. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  197. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B,C]的数组作为结果,请将该最终结果输出"},
  198. ],
  199. extra_body={"thinking": {"type": "disabled"}},
  200. #extra_body={"enable_thinking": False},
  201. )
  202. json_string = completion.choices[0].message.content
  203. print(json_string)
  204. answer=[]
  205. if 'A' in json_string:
  206. answer.append(A[0])
  207. if 'B' in json_string:
  208. answer.append(A[1])
  209. if 'C' in json_string:
  210. answer.append(A[2])
  211. if 'D' in json_string:
  212. answer.append(A[3])
  213. if 'E' in json_string:
  214. answer.append(A[4])
  215. if 'F' in json_string:
  216. answer.append(A[5])
  217. if 'G' in json_string:
  218. answer.append(A[6])
  219. if 'H' in json_string:
  220. answer.append(A[7])
  221. if 'I' in json_string:
  222. answer.append(A[8])
  223. if 'J' in json_string:
  224. answer.append(A[9])
  225. return answer
  226. def aifilter2(A, #options
  227. B, #data
  228. aiclient,
  229. qwclient,
  230. dw):
  231. hit_wumian = False
  232. for entry in A:
  233. if entry in obj['wumian']:
  234. hit_wumian=True
  235. hit_loumian = False
  236. loumian_entry = ''
  237. for entry in A:
  238. if entry in obj['loumian']:
  239. hit_loumian=True
  240. loumian_entry = entry
  241. if hit_wumian and hit_loumian:
  242. return [x for x in A if x != loumian_entry]
  243. return A
  244. def postprocess0109(selected, data, aiclient, qwclient, label_name, name_dw):
  245. prime = aifilter1(selected, data, aiclient, qwclient, name_dw)
  246. if data['bianma'].startswith("010902") and '高聚物' in data['tz'] and '改性沥青防水涂料' in data['tz']:##屋面防水
  247. if '第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.1 涂刷油类 水泥基渗透结晶 防水材料 二~三遍(厚2mm)' not in prime:
  248. prime.append('第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.1 涂刷油类 水泥基渗透结晶 防水材料 二~三遍(厚2mm)') ##需要换
  249. if data['bianma'].startswith("010902") and '非固化' in data['tz'] and '沥青防水涂料' in data['tz']:##屋面防水
  250. if '第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.1 涂刷油类 水泥基渗透结晶 防水材料 二~三遍(厚2mm)' not in prime:
  251. prime.append('第十章 屋面及防水工程 10.2 平面立面及其它防水 10.2.1 涂刷油类 水泥基渗透结晶 防水材料 二~三遍(厚2mm)') ##需要换
  252. prime = aifilter2(prime, data, aiclient, qwclient, name_dw)##找平层去重
  253. prime = aifilter4(prime, data, aiclient, qwclient, name_dw)##沥青去重
  254. if data['bianma'].startswith("010902") and '保护层' in data['tz']:##屋面防水保护层
  255. l = len([x for x in prime if '刚性防水屋面' in x])
  256. if l==0:
  257. answer = aifilter3(prime, data, aiclient, qwclient, name_dw)
  258. prime.append(answer[0])
  259. if '南通补充定额 南通补充定额2016 第十章 屋面及防水工程 干铺法施工水泥彩瓦屋面(砼屋面板上钉钢挂瓦条、顺水条)' in prime:
  260. prime.append('南通补充定额 南通补充定额2016 第十章 屋面及防水工程 干铺法施工水泥彩瓦屋面(铺瓦)')
  261. return prime