postprocess0106.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. tuliaos=[
  2. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 薄型 0.5小时',
  3. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 薄型 1小时',
  4. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 薄型 1.5小时',
  5. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 薄型 2小时',
  6. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 厚型 2小时',
  7. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 厚型 2.5小时',
  8. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 厚型 3小时',
  9. ]
  10. tuliao_options=[]
  11. tuliao_letters='ABCDEFG'
  12. for i in range(len(tuliaos)):
  13. tuliao_options.append('给定选项'+tuliao_letters[i]+', 内容为' + tuliaos[i])
  14. import json
  15. with open('nantong_rule', 'r') as f:
  16. content = f.read()
  17. import json
  18. obj=json.loads(content)
  19. from fallback import fallback
  20. def fanghuotuliao(A, #options
  21. B, #data
  22. aiclient,
  23. qwclient,
  24. dw):
  25. options=[]
  26. letters = "ABCDEFGHIJKLMN"
  27. for i in range(len(A)):
  28. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  29. completion = aiclient.chat.completions.create(
  30. model="glm-4.5-flash",
  31. #model="Qwen/Qwen3-14B",
  32. messages=[
  33. {"role": "system", "content": "You are a helpful assistant."},
  34. {"role": "user", "content": "问题描述: " + ','.join(options) + "。请问选项中是否有防火涂料相关选项,请回答是或者否"},
  35. ],
  36. extra_body={"thinking": {"type": "disabled"}},
  37. #extra_body={"enable_thinking": False},
  38. )
  39. json_string = completion.choices[0].message.content
  40. print(json_string)
  41. if len(json_string) < 4:
  42. if '是' in json_string:
  43. return True
  44. else:
  45. return False
  46. completion = aiclient.chat.completions.create(
  47. model="glm-4.5-flash",
  48. messages=[
  49. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  50. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个是或者否的判断作为结果,请将该最终结果输出"},
  51. ],
  52. extra_body={"thinking": {"type": "disabled"}},
  53. #extra_body={"enable_thinking": False},
  54. )
  55. json_string = completion.choices[0].message.content
  56. print(json_string)
  57. answer=[]
  58. if '否' in json_string:
  59. return False
  60. return True
  61. def fanghuo(A, #options
  62. B, #data
  63. aiclient,
  64. qwclient,
  65. dw):
  66. options=[]
  67. letters = "ABCDEFGHIJKLMN"
  68. for i in range(len(A)):
  69. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  70. completion = aiclient.chat.completions.create(
  71. model="glm-4.5-flash",
  72. #model="Qwen/Qwen3-14B",
  73. messages=[
  74. {"role": "system", "content": "You are a helpful assistant."},
  75. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + "。请问工作内容是否提及防火要求,请回答是或者否"},
  76. ],
  77. extra_body={"thinking": {"type": "disabled"}},
  78. #extra_body={"enable_thinking": False},
  79. )
  80. json_string = completion.choices[0].message.content
  81. print(json_string)
  82. if len(json_string) < 4:
  83. if '是' in json_string:
  84. return True
  85. else:
  86. return False
  87. completion = aiclient.chat.completions.create(
  88. model="glm-4.5-flash",
  89. messages=[
  90. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  91. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个是或者否的判断作为结果,请将该最终结果输出"},
  92. ],
  93. extra_body={"thinking": {"type": "disabled"}},
  94. #extra_body={"enable_thinking": False},
  95. )
  96. json_string = completion.choices[0].message.content
  97. print(json_string)
  98. answer=[]
  99. if '否' in json_string:
  100. return False
  101. return True
  102. def tuliaofilter(A, #options
  103. B, #data
  104. aiclient,
  105. qwclient,
  106. dw):
  107. completion = aiclient.chat.completions.create(
  108. model="glm-4.5-flash",
  109. #model="Qwen/Qwen3-14B",
  110. messages=[
  111. {"role": "system", "content": "You are a helpful assistant."},
  112. {"role": "user", "content": "问题描述: 给定一段涉及防火涂料的工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(tuliao_options) + "。请选出最恰当的选项。请返回类似A或者B或者C这样的结果"},
  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 len(json_string) < 4:
  120. if 'A' in json_string:
  121. return tuliaos[0]
  122. if 'B' in json_string:
  123. return tuliaos[1]
  124. if 'C' in json_string:
  125. return tuliaos[2]
  126. if 'D' in json_string:
  127. return tuliaos[3]
  128. if 'E' in json_string:
  129. return tuliaos[4]
  130. if 'F' in json_string:
  131. return tuliaos[5]
  132. if 'G' in json_string:
  133. return tuliaos[6]
  134. completion = aiclient.chat.completions.create(
  135. model="glm-4.5-flash",
  136. messages=[
  137. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  138. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于A或者B的字母作为结果,请将该最终结果输出"},
  139. ],
  140. extra_body={"thinking": {"type": "disabled"}},
  141. #extra_body={"enable_thinking": False},
  142. )
  143. json_string = completion.choices[0].message.content
  144. print(json_string)
  145. if 'A' in json_string:
  146. return tuliaos[0]
  147. if 'B' in json_string:
  148. return tuliaos[1]
  149. if 'C' in json_string:
  150. return tuliaos[2]
  151. if 'D' in json_string:
  152. return tuliaos[3]
  153. if 'E' in json_string:
  154. return tuliaos[4]
  155. if 'F' in json_string:
  156. return tuliaos[5]
  157. if 'G' in json_string:
  158. return tuliaos[6]
  159. def aifilter3(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 = aiclient.chat.completions.create(
  169. model="glm-4.5-flash",
  170. #model="Qwen/Qwen3-14B",
  171. messages=[
  172. {"role": "system", "content": "You are a helpful assistant."},
  173. {"role": "user", "content": " 特殊处理要求:如果选项中有含有“零星钢构件制作”字样的选项,并且同时选项中有含有“铁件制作”字样的选项,则二者只能选一,且优先选择出现靠前的选项"},
  174. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  175. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  176. ],
  177. extra_body={"thinking": {"type": "disabled"}},
  178. #extra_body={"enable_thinking": False},
  179. )
  180. json_string = completion.choices[0].message.content
  181. print(json_string)
  182. completion = aiclient.chat.completions.create(
  183. model="glm-4.5-flash",
  184. messages=[
  185. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  186. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B,C]的数组作为结果,请将该最终结果输出"},
  187. ],
  188. extra_body={"thinking": {"type": "disabled"}},
  189. #extra_body={"enable_thinking": False},
  190. )
  191. json_string = completion.choices[0].message.content
  192. print(json_string)
  193. answer=[]
  194. if 'A' in json_string:
  195. answer.append(A[0])
  196. if 'B' in json_string:
  197. answer.append(A[1])
  198. if 'C' in json_string:
  199. answer.append(A[2])
  200. if 'D' in json_string:
  201. answer.append(A[3])
  202. if 'E' in json_string:
  203. answer.append(A[4])
  204. if 'F' in json_string:
  205. answer.append(A[5])
  206. if 'G' in json_string:
  207. answer.append(A[6])
  208. if 'H' in json_string:
  209. answer.append(A[7])
  210. if 'I' in json_string:
  211. answer.append(A[8])
  212. if 'J' in json_string:
  213. answer.append(A[9])
  214. return answer
  215. def aifilter1(A, #options
  216. B, #data
  217. aiclient,
  218. qwclient,
  219. dw):
  220. options=[]
  221. letters = "ABCDEFGHIJKLMN"
  222. for i in range(len(A)):
  223. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  224. completion = aiclient.chat.completions.create(
  225. model="glm-4.5-flash",
  226. #model="Qwen/Qwen3-14B",
  227. messages=[
  228. {"role": "system", "content": "You are a helpful assistant."},
  229. {"role": "user", "content": " 特殊处理要求:如果选项中有晒衣架制作安装的选项,但是工作内容中不涉及晒衣架,则去除选项中的晒衣架制作安装的选项"},
  230. {"role": "user", "content": " 特殊处理要求:如果选项中有龙骨钢骨架制作安装的选项,但是工作内容中不涉及龙骨钢骨架,则去除选项中的龙骨钢骨架的选项"},
  231. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  232. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  233. ],
  234. extra_body={"thinking": {"type": "disabled"}},
  235. #extra_body={"enable_thinking": False},
  236. )
  237. json_string = completion.choices[0].message.content
  238. print(json_string)
  239. completion = aiclient.chat.completions.create(
  240. model="glm-4.5-flash",
  241. messages=[
  242. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  243. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B,C]的数组作为结果,请将该最终结果输出"},
  244. ],
  245. extra_body={"thinking": {"type": "disabled"}},
  246. #extra_body={"enable_thinking": False},
  247. )
  248. json_string = completion.choices[0].message.content
  249. print(json_string)
  250. answer=[]
  251. if 'A' in json_string:
  252. answer.append(A[0])
  253. if 'B' in json_string:
  254. answer.append(A[1])
  255. if 'C' in json_string:
  256. answer.append(A[2])
  257. if 'D' in json_string:
  258. answer.append(A[3])
  259. if 'E' in json_string:
  260. answer.append(A[4])
  261. if 'F' in json_string:
  262. answer.append(A[5])
  263. if 'G' in json_string:
  264. answer.append(A[6])
  265. if 'H' in json_string:
  266. answer.append(A[7])
  267. if 'I' in json_string:
  268. answer.append(A[8])
  269. if 'J' in json_string:
  270. answer.append(A[9])
  271. return answer
  272. def aifilter2(A, #options
  273. B, #data
  274. aiclient,
  275. qwclient,
  276. dw):
  277. options=[]
  278. letters = "ABCDEFGHIJKLMN"
  279. for i in range(len(A)):
  280. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  281. completion = aiclient.chat.completions.create(
  282. model="glm-4.5-flash",
  283. #model="Qwen/Qwen3-14B",
  284. messages=[
  285. {"role": "system", "content": "You are a helpful assistant."},
  286. {"role": "user", "content": " 特殊处理要求:如果选项中有含有“零星钢构件制作”字样的选项,并且选项中没有其他具体的钢构件选项,则不做任何处理"},
  287. {"role": "user", "content": " 特殊处理要求:如果选项中有含有“零星钢构件制作”字样的选项,并且选项中有其他具体的钢构件选项(例如CZ轻钢檩条),则去除选项中的含有“零星钢构件制作”字样的选项"},
  288. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  289. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  290. ],
  291. extra_body={"thinking": {"type": "disabled"}},
  292. #extra_body={"enable_thinking": False},
  293. )
  294. json_string = completion.choices[0].message.content
  295. print(json_string)
  296. if len(json_string) < 4:
  297. answer=[]
  298. if 'A' in json_string:
  299. answer.append(A[0])
  300. if 'B' in json_string:
  301. answer.append(A[1])
  302. if 'C' in json_string:
  303. answer.append(A[2])
  304. if 'D' in json_string:
  305. answer.append(A[3])
  306. if 'E' in json_string:
  307. answer.append(A[4])
  308. if 'F' in json_string:
  309. answer.append(A[5])
  310. if 'G' in json_string:
  311. answer.append(A[6])
  312. if 'H' in json_string:
  313. answer.append(A[7])
  314. if 'I' in json_string:
  315. answer.append(A[8])
  316. if 'J' in json_string:
  317. answer.append(A[9])
  318. return answer
  319. completion = aiclient.chat.completions.create(
  320. model="glm-4.5-flash",
  321. messages=[
  322. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  323. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B,C]的数组作为结果,请将该最终结果输出"},
  324. ],
  325. extra_body={"thinking": {"type": "disabled"}},
  326. #extra_body={"enable_thinking": False},
  327. )
  328. json_string = completion.choices[0].message.content
  329. print(json_string)
  330. answer=[]
  331. if 'A' in json_string:
  332. answer.append(A[0])
  333. if 'B' in json_string:
  334. answer.append(A[1])
  335. if 'C' in json_string:
  336. answer.append(A[2])
  337. if 'D' in json_string:
  338. answer.append(A[3])
  339. if 'E' in json_string:
  340. answer.append(A[4])
  341. if 'F' in json_string:
  342. answer.append(A[5])
  343. if 'G' in json_string:
  344. answer.append(A[6])
  345. if 'H' in json_string:
  346. answer.append(A[7])
  347. if 'I' in json_string:
  348. answer.append(A[8])
  349. if 'J' in json_string:
  350. answer.append(A[9])
  351. return answer
  352. def postprocess0106_(selected, data, aiclient, qwclient, label_name, name_dw):
  353. if len(selected) == 1:
  354. return selected
  355. return aifilter3(aifilter2(aifilter1(selected, data, aiclient, qwclient, name_dw), data, aiclient, qwclient, name_dw), data, aiclient, qwclient, name_dw)
  356. def postprocess0106(selected, data, aiclient, qwclient, label_name, name_dw):
  357. selected = postprocess0106_(selected, data, aiclient, qwclient, label_name, name_dw)
  358. hit = fanghuo(selected, data, aiclient, qwclient, name_dw)
  359. if hit:
  360. tuliao = fanghuotuliao(selected, data, aiclient, qwclient, name_dw)
  361. if not tuliao:
  362. selected.append(tuliaofilter(selected, data, aiclient, qwclient, name_dw))
  363. return selected
  364. else:
  365. return selected