postprocess0111.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. import time
  2. import json
  3. with open('zhaoping_rule', 'r') as f:
  4. content = f.read()
  5. import json
  6. obj=json.loads(content)
  7. with open('name_label', 'r') as f:
  8. content = f.read()
  9. import json
  10. name_label=json.loads(content)
  11. baohuceng = ['10-74', '10-75', '10-77', '10-78', '10-80', '10-81', '10-83', '10-84', '10-86', '10-87', '10-90']
  12. from fallback import fallback
  13. def aifilter3(A, #options
  14. B, #data
  15. aiclient,
  16. qwclient,
  17. sfclient,
  18. dw):
  19. options=[]
  20. letters = "ABCDEFGHIJKLMN"
  21. for i in range(len(A)):
  22. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  23. completion = sfclient.chat.completions.create(
  24. model="THUDM/GLM-4-9B-0414",
  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": "问题描述: 细石混凝土内配钢丝网片是一种常见的施工工艺。给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + "。请问工作内容的描述中有该施工工艺吗?请回答有或者没有"},
  31. ],
  32. extra_body={"thinking": {"type": "disabled"}},
  33. #extra_body={"enable_thinking": True},
  34. #stream=True
  35. )
  36. json_string = completion.choices[0].message.content
  37. print(json_string)
  38. if len(json_string) < 4:
  39. if '没有' in json_string:
  40. return False
  41. return True
  42. completion = sfclient.chat.completions.create(
  43. #model="glm-4.5-flash",
  44. model="THUDM/GLM-4-9B-0414",
  45. messages=[
  46. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  47. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个有或者没有的判断,请将该判断输出"},
  48. ],
  49. extra_body={"thinking": {"type": "disabled"}},
  50. #extra_body={"enable_thinking": False},
  51. )
  52. json_string = completion.choices[0].message.content
  53. print(json_string)
  54. if '没有' in json_string:
  55. return False
  56. return True
  57. def aifilter4(A, #options
  58. B, #data
  59. aiclient,
  60. qwclient,
  61. dw):
  62. options=[]
  63. letters = "ABCDEFGHIJKLMN"
  64. for i in range(len(A)):
  65. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  66. completion = qwclient.chat.completions.create(
  67. #model="glm-z1-flash",
  68. model="Qwen/Qwen3-14B",
  69. #model="ernie-speed-128k",
  70. messages=[
  71. {"role": "system", "content": "You are a helpful assistant."},
  72. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土找平层是不同的施工步骤,不得混淆"},
  73. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土垫层是不同的施工步骤,不得混淆"},
  74. {"role": "user", "content": " 背景知识:混凝土(砼)找平层跟混凝土垫层是不同的施工步骤,不得混淆"},
  75. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆面层是不同的施工步骤,不得混淆"},
  76. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆保护层是不同的施工步骤,不得混淆"},
  77. {"role": "user", "content": " 背景知识:“混凝土楼地面”施工是面层施工,跟“楼地面涂刷一遍901胶素水泥浆”是不同的施工步骤,不得混淆"},
  78. {"role": "user", "content": " 特殊处理要求:如果工作内容描述中明确提到块料面层,比如地砖、石材块料等,则保留楼地面涂刷一遍901胶素水泥浆选项,去掉所有混凝土(砼)整体面层的选项"},
  79. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  80. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  81. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  82. ],
  83. #extra_body={"thinking": {"type": "enabled"}},
  84. extra_body={"enable_thinking": True},
  85. stream=True
  86. )
  87. done_thinking = False
  88. json_string=""
  89. thinking_json_string=""
  90. for chunk in completion:
  91. thinking_chunk = chunk.choices[0].delta.reasoning_content
  92. answer_chunk = chunk.choices[0].delta.content
  93. if thinking_chunk != '':
  94. thinking_json_string = thinking_json_string + thinking_chunk
  95. elif answer_chunk != '':
  96. if not done_thinking:
  97. done_thinking = True
  98. json_string = json_string + answer_chunk
  99. #json_string = completion.choices[0].message.content
  100. print(thinking_json_string)
  101. print(json_string)
  102. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  103. answer=[]
  104. if 'A' in json_string and len(A) > 0:
  105. answer.append(A[0])
  106. if 'B' in json_string and len(A) > 1:
  107. answer.append(A[1])
  108. if 'C' in json_string and len(A) > 2:
  109. answer.append(A[2])
  110. if 'D' in json_string and len(A) > 3:
  111. answer.append(A[3])
  112. if 'E' in json_string and len(A) > 4:
  113. answer.append(A[4])
  114. if 'F' in json_string and len(A) > 5:
  115. answer.append(A[5])
  116. if 'G' in json_string and len(A) > 6:
  117. answer.append(A[6])
  118. if 'H' in json_string and len(A) > 7:
  119. answer.append(A[7])
  120. if 'I' in json_string and len(A) > 8:
  121. answer.append(A[8])
  122. if 'J' in json_string and len(A) > 9:
  123. answer.append(A[9])
  124. return answer
  125. completion = qwclient.chat.completions.create(
  126. model="ZhipuAI/GLM-4.5",
  127. #model="glm-4.5-flash",
  128. messages=[
  129. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  130. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B]的数组作为结果,请将该最终结果输出"},
  131. ],
  132. extra_body={"thinking": {"type": "disabled"}},
  133. #extra_body={"enable_thinking": False},
  134. )
  135. json_string = completion.choices[0].message.content
  136. print(json_string)
  137. answer=[]
  138. if 'A' in json_string and len(A) > 0:
  139. answer.append(A[0])
  140. if 'B' in json_string and len(A) > 1:
  141. answer.append(A[1])
  142. if 'C' in json_string and len(A) > 2:
  143. answer.append(A[2])
  144. if 'D' in json_string and len(A) > 3:
  145. answer.append(A[3])
  146. if 'E' in json_string and len(A) > 4:
  147. answer.append(A[4])
  148. if 'F' in json_string and len(A) > 5:
  149. answer.append(A[5])
  150. if 'G' in json_string and len(A) > 6:
  151. answer.append(A[6])
  152. if 'H' in json_string and len(A) > 7:
  153. answer.append(A[7])
  154. if 'I' in json_string and len(A) > 8:
  155. answer.append(A[8])
  156. if 'J' in json_string and len(A) > 9:
  157. answer.append(A[9])
  158. return answer
  159. def aifilter1(A, #options
  160. B, #data
  161. aiclient,
  162. qwclient,
  163. dw):
  164. options=[]
  165. letters = "ABCDEFGHIJKLMN"
  166. for i in range(len(A)):
  167. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  168. completion = qwclient.chat.completions.create(
  169. #model="glm-z1-flash",
  170. model="Qwen/Qwen3-14B",
  171. #model="ernie-speed-128k",
  172. messages=[
  173. {"role": "system", "content": "You are a helpful assistant."},
  174. {"role": "user", "content": " 背景知识:混凝土楼地面是面层,跟混凝土垫层是不同的施工步骤,不得混淆"},
  175. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土找平层是不同的施工步骤,不得混淆"},
  176. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土垫层是不同的施工步骤,不得混淆"},
  177. {"role": "user", "content": " 背景知识:混凝土(砼)找平层跟混凝土垫层是不同的施工步骤,不得混淆"},
  178. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆面层是不同的施工步骤,不得混淆"},
  179. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆保护层是不同的施工步骤,不得混淆"},
  180. {"role": "user", "content": " 特殊处理要求:如果工作内容描述中没有明确提到踢脚线,则去掉所有踢脚线的选项"},
  181. {"role": "user", "content": " 特殊处理要求:去掉所有模板工程的选项"},
  182. {"role": "user", "content": " 特殊处理要求:如果工作内容描述中没有明确涉及水泥砂浆面层,且没有提及水泥砂浆保护层,则去掉所有20mm水泥砂浆楼地面的选项"},
  183. {"role": "user", "content": " 特殊处理要求:如果工作内容描述中没有明确提到素水泥浆,则去掉所有含有“素水泥浆”字样的选项"},
  184. {"role": "user", "content": " 特殊处理要求:如果工作内容描述中没有明确提到“加浆抹光”,则去掉所有含有“加浆抹光”字样的选项"},
  185. {"role": "user", "content": " 特殊处理要求:如果工作内容描述中没有明确提到混凝土垫层,则去掉所有混凝土垫层的选项"},
  186. {"role": "user", "content": " 特殊处理要求:如果选项中同时存在“冷轧带肋钢筋”选项和“抗裂基层 热镀锌钢丝网”选项,则去掉热镀锌钢丝网的选项"},
  187. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  188. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  189. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  190. ],
  191. #extra_body={"thinking": {"type": "enabled"}},
  192. extra_body={"enable_thinking": True},
  193. stream=True
  194. )
  195. done_thinking = False
  196. json_string=""
  197. thinking_json_string=""
  198. for chunk in completion:
  199. thinking_chunk = chunk.choices[0].delta.reasoning_content
  200. answer_chunk = chunk.choices[0].delta.content
  201. if thinking_chunk != '':
  202. thinking_json_string = thinking_json_string + thinking_chunk
  203. elif answer_chunk != '':
  204. if not done_thinking:
  205. done_thinking = True
  206. json_string = json_string + answer_chunk
  207. #json_string = completion.choices[0].message.content
  208. print(thinking_json_string)
  209. print(json_string)
  210. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  211. answer=[]
  212. if 'A' in json_string and len(A) > 0:
  213. answer.append(A[0])
  214. if 'B' in json_string and len(A) > 1:
  215. answer.append(A[1])
  216. if 'C' in json_string and len(A) > 2:
  217. answer.append(A[2])
  218. if 'D' in json_string and len(A) > 3:
  219. answer.append(A[3])
  220. if 'E' in json_string and len(A) > 4:
  221. answer.append(A[4])
  222. if 'F' in json_string and len(A) > 5:
  223. answer.append(A[5])
  224. if 'G' in json_string and len(A) > 6:
  225. answer.append(A[6])
  226. if 'H' in json_string and len(A) > 7:
  227. answer.append(A[7])
  228. if 'I' in json_string and len(A) > 8:
  229. answer.append(A[8])
  230. if 'J' in json_string and len(A) > 9:
  231. answer.append(A[9])
  232. return answer
  233. completion = qwclient.chat.completions.create(
  234. #model="glm-4.5-flash",
  235. model="ZhipuAI/GLM-4.5",
  236. messages=[
  237. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  238. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B]的数组作为结果,请将该最终结果输出"},
  239. ],
  240. extra_body={"thinking": {"type": "disabled"}},
  241. #extra_body={"enable_thinking": False},
  242. )
  243. json_string = completion.choices[0].message.content
  244. print(json_string)
  245. answer=[]
  246. if 'A' in json_string and len(A) > 0:
  247. answer.append(A[0])
  248. if 'B' in json_string and len(A) > 1:
  249. answer.append(A[1])
  250. if 'C' in json_string and len(A) > 2:
  251. answer.append(A[2])
  252. if 'D' in json_string and len(A) > 3:
  253. answer.append(A[3])
  254. if 'E' in json_string and len(A) > 4:
  255. answer.append(A[4])
  256. if 'F' in json_string and len(A) > 5:
  257. answer.append(A[5])
  258. if 'G' in json_string and len(A) > 6:
  259. answer.append(A[6])
  260. if 'H' in json_string and len(A) > 7:
  261. answer.append(A[7])
  262. if 'I' in json_string and len(A) > 8:
  263. answer.append(A[8])
  264. if 'J' in json_string and len(A) > 9:
  265. answer.append(A[9])
  266. return answer
  267. def aifilter2(A, #options
  268. B, #data
  269. aiclient,
  270. qwclient,
  271. dw):
  272. hit_wumian = False
  273. for entry in A:
  274. if entry in obj['wumian']:
  275. hit_wumian=True
  276. hit_loumian = False
  277. loumian_entry = ''
  278. for entry in A:
  279. if entry in obj['loumian']:
  280. hit_loumian=True
  281. loumian_entry = entry
  282. if hit_wumian and hit_loumian:
  283. return [x for x in A if x != loumian_entry]
  284. return A
  285. def postprocess0111(selected, data, aiclient, qwclient, sfclient, label_name, name_dw):
  286. prime = aifilter1(selected, data, aiclient, qwclient, name_dw)
  287. time.sleep(1)
  288. wangpian = aifilter3(prime, data, aiclient, qwclient, sfclient, name_dw)
  289. if not wangpian:
  290. prime = aifilter4(prime, data, aiclient, qwclient, name_dw)
  291. if '界面剂' in data['tz']:##保温
  292. if len([ x for x in prime if '第十四章 墙柱面工程 14.1 一般抹灰 14.1.3 保温砂浆及抗裂基层 刷界面剂' in x]) == 0:
  293. prime.append('第十四章 墙柱面工程 14.1 一般抹灰 14.1.3 保温砂浆及抗裂基层 刷界面剂 混凝土面') ##需要换
  294. return prime