postprocess0105.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import json
  2. from config import simplemodel
  3. from template import xuanxiang
  4. with open('nantong_rule', 'r') as f:
  5. content = f.read()
  6. import json
  7. obj=json.loads(content)
  8. from fallback import fallback
  9. qiangdu={"role": "user", "content": " 特殊处理要求:不需考虑工作内容中的混凝土强度等级与选项中的混凝土强度等级的差异"}
  10. xiang={"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"}
  11. shanchu={"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合(匹配),不得擅自根据符合与否去除选项,只需要根据特殊处理要求做出处理"}
  12. ceng={"role": "user", "content": " 重要提示:混凝土找平层与混凝土面层是不同的概念,不得混淆。混凝土整体面层不属于混凝土找平层"}
  13. def aifilter4(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 = aiclient.chat.completions.create(
  24. model="glm-4.5-air",
  25. #model="Qwen/Qwen3-14B",
  26. messages=[
  27. {"role": "system", "content": "You are a helpful assistant."},
  28. {"role": "user", "content": " 特殊处理要求:如果选项中有混凝土垫层选项,但是工作内容中明确描述垫层做法是碎石垫层,则去除选项中的混凝土垫层选项"},
  29. {"role": "user", "content": " 特殊处理要求:如果选项中有混凝土垫层选项,但是工作内容中不涉及垫层,则去除选项中的混凝土垫层选项"},
  30. {"role": "user", "content": " 特殊处理要求:如果选项中有细石混凝土(细石砼)找平层选项(细石混凝土整体面层不属于找平层),但是工作内容没有明确表述细石混凝土找平层,则去除选项中的细石混凝土找平层选项"},
  31. {"role": "user", "content": " 特殊处理要求:抱框柱是柱的一种,与门框不相同。如果选项中有门框选项,但是工作内容中没有明确提出门框,则去除选项中的门框选项"},
  32. qiangdu,xiang,shanchu,ceng,
  33. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,写出推理过程,并返回结果,删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  34. ],
  35. extra_body={"thinking": {"type": "disabled"}},
  36. #extra_body={"enable_thinking": False},
  37. )
  38. json_string = completion.choices[0].message.content
  39. print(json_string)
  40. completion = sfclient.chat.completions.create(
  41. model=simplemodel(),
  42. messages=xuanxiang(json_string),
  43. extra_body={"thinking": {"type": "disabled"}},
  44. #extra_body={"enable_thinking": False},
  45. )
  46. json_string = completion.choices[0].message.content
  47. print(json_string)
  48. answer=[]
  49. if 'A' in json_string:
  50. answer.append(A[0])
  51. if 'B' in json_string:
  52. answer.append(A[1])
  53. if 'C' in json_string:
  54. answer.append(A[2])
  55. if 'D' in json_string:
  56. answer.append(A[3])
  57. if 'E' in json_string:
  58. answer.append(A[4])
  59. if 'F' in json_string:
  60. answer.append(A[5])
  61. if 'G' in json_string:
  62. answer.append(A[6])
  63. if 'H' in json_string:
  64. answer.append(A[7])
  65. if 'I' in json_string:
  66. answer.append(A[8])
  67. if 'J' in json_string:
  68. answer.append(A[9])
  69. return answer
  70. def aifilter2(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-air",
  82. #model="Qwen/Qwen3-14B",
  83. messages=[
  84. {"role": "system", "content": "You are a helpful assistant."},
  85. {"role": "user", "content": " 特殊处理要求:如果选项中有檩条选项,但是工作内容中没有涉及檩条,则去除选项中的檩条选项"},
  86. {"role": "user", "content": " 特殊处理要求:如果工作内容中没有明确提及素水泥浆(提到水泥浆不等于提到素水泥浆),则去除选项中的素水泥浆选项"},
  87. qiangdu,xiang,shanchu,ceng,
  88. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,写出推理过程,并返回结果,删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  89. ],
  90. extra_body={"thinking": {"type": "disabled"}},
  91. #extra_body={"enable_thinking": False},
  92. )
  93. json_string = completion.choices[0].message.content
  94. print(json_string)
  95. completion = sfclient.chat.completions.create(
  96. model=simplemodel(),
  97. messages=xuanxiang(json_string),
  98. extra_body={"thinking": {"type": "disabled"}},
  99. #extra_body={"enable_thinking": False},
  100. )
  101. json_string = completion.choices[0].message.content
  102. print(json_string)
  103. answer=[]
  104. if 'A' in json_string:
  105. answer.append(A[0])
  106. if 'B' in json_string:
  107. answer.append(A[1])
  108. if 'C' in json_string:
  109. answer.append(A[2])
  110. if 'D' in json_string:
  111. answer.append(A[3])
  112. if 'E' in json_string:
  113. answer.append(A[4])
  114. if 'F' in json_string:
  115. answer.append(A[5])
  116. if 'G' in json_string:
  117. answer.append(A[6])
  118. if 'H' in json_string:
  119. answer.append(A[7])
  120. if 'I' in json_string:
  121. answer.append(A[8])
  122. if 'J' in json_string:
  123. answer.append(A[9])
  124. return answer
  125. def aifilter3(A, #options
  126. B, #data
  127. aiclient,
  128. qwclient,
  129. sfclient,
  130. dw):
  131. options=[]
  132. letters = "ABCDEFGHIJKLMN"
  133. for i in range(len(A)):
  134. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  135. completion = aiclient.chat.completions.create(
  136. model="glm-4.5-air",
  137. #model="Qwen/Qwen3-14B",
  138. messages=[
  139. {"role": "system", "content": "You are a helpful assistant."},
  140. {"role": "user", "content": " 特殊处理要求:如果选项中有模板工程选项,但是工作内容中没有明确提出包含模板工程,则去除选项中的模板工程选项"},
  141. {"role": "user", "content": " 特殊处理要求:如果选项中有锯缝选项,但是工作内容中没有明确提出需要锯缝(道路伸缩缝),则去除选项中的锯缝选项"},
  142. qiangdu,xiang,shanchu,ceng,
  143. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,写出推理过程,并返回结果,删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  144. ],
  145. extra_body={"thinking": {"type": "disabled"}},
  146. #extra_body={"enable_thinking": False},
  147. )
  148. json_string = completion.choices[0].message.content
  149. print(json_string)
  150. completion = sfclient.chat.completions.create(
  151. model=simplemodel(),
  152. messages=xuanxiang(json_string),
  153. extra_body={"thinking": {"type": "disabled"}},
  154. #extra_body={"enable_thinking": False},
  155. )
  156. json_string = completion.choices[0].message.content
  157. print(json_string)
  158. answer=[]
  159. if 'A' in json_string:
  160. answer.append(A[0])
  161. if 'B' in json_string:
  162. answer.append(A[1])
  163. if 'C' in json_string:
  164. answer.append(A[2])
  165. if 'D' in json_string:
  166. answer.append(A[3])
  167. if 'E' in json_string:
  168. answer.append(A[4])
  169. if 'F' in json_string:
  170. answer.append(A[5])
  171. if 'G' in json_string:
  172. answer.append(A[6])
  173. if 'H' in json_string:
  174. answer.append(A[7])
  175. if 'I' in json_string:
  176. answer.append(A[8])
  177. if 'J' in json_string:
  178. answer.append(A[9])
  179. return answer
  180. def aifilter1_2(A, #options
  181. B, #data
  182. aiclient,
  183. qwclient,
  184. sfclient,
  185. dw):
  186. options=[]
  187. letters = "ABCDEFGHIJKLMN"
  188. for i in range(len(A)):
  189. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  190. completion = aiclient.chat.completions.create(
  191. model="glm-4.5-air",
  192. #model="Qwen/Qwen3-14B",
  193. messages=[
  194. {"role": "system", "content": "You are a helpful assistant."},
  195. {"role": "user", "content": " 特殊处理要求:钢盖板,钢篦子一般指不锈钢材质。如果选项中同时出现不锈钢盖板选项和铸铁盖板选项,则二者只能选一种(并删除另外一个),且优先选择与工作内容描述更接近的选项"},
  196. {"role": "user", "content": " 特殊处理要求:如果选项中同时出现混凝土散水选项和混凝土(砼)整体面层选项(加浆抹光选项虽然有整体面层字样,但是不属于整体面层选项),则二者只能选一个(并删除另一个),且优先选择出现更早的选项"},
  197. qiangdu,xiang,shanchu,ceng,
  198. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,写出推理过程,并返回结果,删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  199. ],
  200. extra_body={"thinking": {"type": "disabled"}},
  201. #extra_body={"enable_thinking": False},
  202. )
  203. json_string = completion.choices[0].message.content
  204. print(json_string)
  205. completion = sfclient.chat.completions.create(
  206. model=simplemodel(),
  207. messages=xuanxiang(json_string),
  208. extra_body={"thinking": {"type": "disabled"}},
  209. #extra_body={"enable_thinking": False},
  210. )
  211. json_string = completion.choices[0].message.content
  212. print(json_string)
  213. answer=[]
  214. if 'A' in json_string:
  215. answer.append(A[0])
  216. if 'B' in json_string:
  217. answer.append(A[1])
  218. if 'C' in json_string:
  219. answer.append(A[2])
  220. if 'D' in json_string:
  221. answer.append(A[3])
  222. if 'E' in json_string:
  223. answer.append(A[4])
  224. if 'F' in json_string:
  225. answer.append(A[5])
  226. if 'G' in json_string:
  227. answer.append(A[6])
  228. if 'H' in json_string:
  229. answer.append(A[7])
  230. if 'I' in json_string:
  231. answer.append(A[8])
  232. if 'J' in json_string:
  233. answer.append(A[9])
  234. return answer
  235. def aifilter1_1(A, #options
  236. B, #data
  237. aiclient,
  238. qwclient,
  239. sfclient,
  240. dw):
  241. options=[]
  242. letters = "ABCDEFGHIJKLMN"
  243. for i in range(len(A)):
  244. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  245. completion = aiclient.chat.completions.create(
  246. model="glm-4.5-air",
  247. #model="Qwen/Qwen3-14B",
  248. messages=[
  249. {"role": "system", "content": "You are a helpful assistant."},
  250. {"role": "user", "content": " 特殊处理要求:如果选项中同时出现现浇板式雨棚(雨蓬)选项和现浇水平板(平板)选项,则二者只能选一个(并删除另一个),且优先选择出现更早的选项"},
  251. {"role": "user", "content": " 特殊处理要求:如果选项中同时出现多个钢丝网选项,则只能选一个(并删除另一个),且优先选择出现更早的选项"},
  252. qiangdu,xiang,shanchu,ceng,
  253. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,写出推理过程,并返回结果,删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  254. ],
  255. extra_body={"thinking": {"type": "disabled"}},
  256. #extra_body={"enable_thinking": False},
  257. )
  258. json_string = completion.choices[0].message.content
  259. print(json_string)
  260. completion = sfclient.chat.completions.create(
  261. model=simplemodel(),
  262. messages=xuanxiang(json_string),
  263. extra_body={"thinking": {"type": "disabled"}},
  264. #extra_body={"enable_thinking": False},
  265. )
  266. json_string = completion.choices[0].message.content
  267. print(json_string)
  268. answer=[]
  269. if 'A' in json_string:
  270. answer.append(A[0])
  271. if 'B' in json_string:
  272. answer.append(A[1])
  273. if 'C' in json_string:
  274. answer.append(A[2])
  275. if 'D' in json_string:
  276. answer.append(A[3])
  277. if 'E' in json_string:
  278. answer.append(A[4])
  279. if 'F' in json_string:
  280. answer.append(A[5])
  281. if 'G' in json_string:
  282. answer.append(A[6])
  283. if 'H' in json_string:
  284. answer.append(A[7])
  285. if 'I' in json_string:
  286. answer.append(A[8])
  287. if 'J' in json_string:
  288. answer.append(A[9])
  289. return answer
  290. def postprocess0105(selected, data, aiclient, qwclient, sfclient, label_name, name_dw):
  291. name=[label_name[x] for x in selected]
  292. dw=[name_dw[x] for x in name]
  293. if len(selected) == 1:
  294. t1 = selected
  295. else:
  296. t1 = aifilter1_1(selected, data, aiclient, qwclient, sfclient, dw)
  297. t1 = aifilter1_2(t1, data, aiclient, qwclient, sfclient, dw)
  298. t1 = aifilter3(t1, data, aiclient, qwclient, sfclient, dw)
  299. t1 = aifilter2(t1, data, aiclient, qwclient, sfclient, dw)
  300. t1 = aifilter4(t1, data, aiclient, qwclient, sfclient, dw)
  301. #t2 = fallback(t1, data, aiclient, qwclient)
  302. result = []
  303. if '套' in data['dw']:
  304. for entry in t1:
  305. if entry in obj['7.8']:##钢盖板
  306. result.append('第十二章 厂区道路及排水工程 12.5 排水系统中钢筋混凝土井、池、其它 铸铁盖板安装')
  307. elif '成品不锈钢盖板安装' in entry:
  308. result.append('第十二章 厂区道路及排水工程 12.5 排水系统中钢筋混凝土井、池、其它 铸铁盖板安装')
  309. else:
  310. result.append(entry)
  311. else:
  312. for entry in t1:
  313. if entry in obj['7.8']:##钢盖板
  314. result.append(obj['nantong7.8'][0])
  315. else:
  316. result.append(entry)
  317. return result