postprocess0308.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. import time
  2. from fallback import fallback
  3. from config import simplemodel
  4. from template import xuanxiang
  5. from fallback import fallback
  6. zhijing=['公称直径(mm以内)15', '公称直径(mm以内)20', '公称直径(mm以内)25', '公称直径(mm以内)32' , '公称直径(mm以内)40', '公称直径(mm以内)50', '公称直径(mm以内)65', '公称直径(mm以内)80', '公称直径(mm以内)100', '公称直径(mm以内)125', '公称直径(mm以内)150', '公称直径(mm以内)200', '公称直径(mm以内)250', '公称直径(mm以内)300', '公称直径(mm以内)350', '公称直径(mm以内)400', '公称直径(mm以内)450', '公称直径(mm以内)500']
  7. kqcs=['公称直径(mm以内)50', '公称直径(mm以内)100', '公称直径(mm以内)200', '公称直径(mm以内)300', '公称直径(mm以内)400', '公称直径(mm以内)500', '公称直径(mm以内)600']
  8. def select_chuisao(
  9. B, #data
  10. aiclient,
  11. qwclient,
  12. sfclient,
  13. dw):
  14. options=[]
  15. letters = "ABCDEFGHIJKLMNOPQR"
  16. for i in range(len(kqcs)):
  17. options.append("给定选项" + letters[i]+",内容为"+kqcs[i] )
  18. completion = aiclient.chat.completions.create(
  19. model="glm-4.5-air",
  20. #model="THUDM/GLM-Z1-9B-0414",
  21. #model="ernie-speed-128k",
  22. messages=[
  23. {"role": "system", "content": "You are a helpful assistant."},
  24. {"role": "user", "content": "背景知识:管道规格D273*8表示管径273mm,壁厚8mm"},
  25. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请选择最合适的选项,并返回字母代号,例如,返回 A"},
  26. ],
  27. extra_body={"thinking": {"type": "disabled"}},
  28. #extra_body={"enable_thinking": True},
  29. #stream=True
  30. )
  31. json_string = completion.choices[0].message.content
  32. print(json_string)
  33. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'R')]) < 5:
  34. answer=[]
  35. if 'A' in json_string and len(kqcs) > 0:
  36. answer.append('A')
  37. if 'B' in json_string and len(kqcs) > 1:
  38. answer.append('B')
  39. if 'C' in json_string and len(kqcs) > 2:
  40. answer.append('C')
  41. if 'D' in json_string and len(kqcs) > 3:
  42. answer.append('D')
  43. if 'E' in json_string and len(kqcs) > 4:
  44. answer.append('E')
  45. if 'F' in json_string and len(kqcs) > 5:
  46. answer.append('F')
  47. if 'G' in json_string and len(kqcs) > 6:
  48. answer.append('G')
  49. return answer
  50. completion = sfclient.chat.completions.create(
  51. #model="glm-4.5-flash",
  52. model=simplemodel(),
  53. messages=xuanxiang(json_string),
  54. extra_body={"thinking": {"type": "disabled"}},
  55. #extra_body={"enable_thinking": False},
  56. )
  57. json_string = completion.choices[0].message.content
  58. print(json_string)
  59. answer=[]
  60. if 'A' in json_string and len(kqcs) > 0:
  61. answer.append('A')
  62. if 'B' in json_string and len(kqcs) > 1:
  63. answer.append('B')
  64. if 'C' in json_string and len(kqcs) > 2:
  65. answer.append('C')
  66. if 'D' in json_string and len(kqcs) > 3:
  67. answer.append('D')
  68. if 'E' in json_string and len(kqcs) > 4:
  69. answer.append('E')
  70. if 'F' in json_string and len(kqcs) > 5:
  71. answer.append('F')
  72. if 'G' in json_string and len(kqcs) > 6:
  73. answer.append('G')
  74. return answer
  75. def youqi(
  76. B, #data
  77. aiclient,
  78. qwclient,
  79. sfclient,
  80. dw):
  81. completion = aiclient.chat.completions.create(
  82. model="glm-4.5-air",
  83. #model="THUDM/GLM-Z1-9B-0414",
  84. #model="ernie-speed-128k",
  85. messages=[
  86. {"role": "system", "content": "You are a helpful assistant."},
  87. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + '\n请问,工作内容是否要求管道刷油漆?请回答是或者否'},
  88. ],
  89. extra_body={"thinking": {"type": "disabled"}},
  90. #extra_body={"enable_thinking": True},
  91. #stream=True
  92. )
  93. json_string = completion.choices[0].message.content
  94. print(json_string)
  95. if '否' in json_string:
  96. return False
  97. return True
  98. def kongqichuisao(
  99. B, #data
  100. aiclient,
  101. qwclient,
  102. sfclient,
  103. dw):
  104. if B['bianma'].startswith('030804'):
  105. return False
  106. options=[]
  107. letters = "ABCDEFG"
  108. for i in range(len(kqcs)):
  109. options.append("给定选项" + letters[i]+",内容为"+kqcs[i] )
  110. print('判断空气吹扫')
  111. completion = aiclient.chat.completions.create(
  112. model="glm-4.5-air",
  113. #model="THUDM/GLM-Z1-9B-0414",
  114. #model="ernie-speed-128k",
  115. messages=[
  116. {"role": "system", "content": "You are a helpful assistant."},
  117. {"role": "user", "content": "背景知识:管道规格D273*8表示管径273mm,壁厚8mm"},
  118. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + '\n请问,工作内容是否明确要求空气吹扫?请回答是或者否'},
  119. ],
  120. extra_body={"thinking": {"type": "disabled"}},
  121. #extra_body={"enable_thinking": True},
  122. #stream=True
  123. )
  124. json_string = completion.choices[0].message.content
  125. print(json_string)
  126. if '否' in json_string:
  127. return False
  128. return True
  129. def select_zhijing(
  130. B, #data
  131. aiclient,
  132. qwclient,
  133. sfclient,
  134. dw):
  135. options=[]
  136. letters = "ABCDEFGHIJKLMNOPQR"
  137. for i in range(len(zhijing)):
  138. options.append("给定选项" + letters[i]+",内容为"+zhijing[i] )
  139. completion = aiclient.chat.completions.create(
  140. model="glm-4.5-air",
  141. #model="THUDM/GLM-Z1-9B-0414",
  142. #model="ernie-speed-128k",
  143. messages=[
  144. {"role": "system", "content": "You are a helpful assistant."},
  145. {"role": "user", "content": "背景知识:管道规格D273*8表示管径273mm,壁厚8mm"},
  146. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请选择最合适的选项,并返回字母代号,例如,返回 A"},
  147. ],
  148. extra_body={"thinking": {"type": "disabled"}},
  149. #extra_body={"enable_thinking": True},
  150. #stream=True
  151. )
  152. json_string = completion.choices[0].message.content
  153. print(json_string)
  154. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'R')]) < 5:
  155. answer=[]
  156. if 'A' in json_string and len(zhijing) > 0:
  157. answer.append('A')
  158. if 'B' in json_string and len(zhijing) > 1:
  159. answer.append('B')
  160. if 'C' in json_string and len(zhijing) > 2:
  161. answer.append('C')
  162. if 'D' in json_string and len(zhijing) > 3:
  163. answer.append('D')
  164. if 'E' in json_string and len(zhijing) > 4:
  165. answer.append('E')
  166. if 'F' in json_string and len(zhijing) > 5:
  167. answer.append('F')
  168. if 'G' in json_string and len(zhijing) > 6:
  169. answer.append('G')
  170. if 'H' in json_string and len(zhijing) > 7:
  171. answer.append('H')
  172. if 'I' in json_string and len(zhijing) > 8:
  173. answer.append('I')
  174. if 'J' in json_string and len(zhijing) > 9:
  175. answer.append('J')
  176. if 'K' in json_string and len(zhijing) > 10:
  177. answer.append('K')
  178. if 'L' in json_string and len(zhijing) > 11:
  179. answer.append('L')
  180. if 'M' in json_string and len(zhijing) > 12:
  181. answer.append('M')
  182. if 'N' in json_string and len(zhijing) > 13:
  183. answer.append('N')
  184. if 'O' in json_string and len(zhijing) > 14:
  185. answer.append('O')
  186. if 'P' in json_string and len(zhijing) > 15:
  187. answer.append('P')
  188. if 'Q' in json_string and len(zhijing) > 16:
  189. answer.append('Q')
  190. if 'R' in json_string and len(zhijing) > 17:
  191. answer.append('R')
  192. return answer
  193. completion = sfclient.chat.completions.create(
  194. #model="glm-4.5-flash",
  195. model=simplemodel(),
  196. messages=xuanxiang(json_string),
  197. extra_body={"thinking": {"type": "disabled"}},
  198. #extra_body={"enable_thinking": False},
  199. )
  200. json_string = completion.choices[0].message.content
  201. print(json_string)
  202. answer=[]
  203. if 'A' in json_string and len(zhijing) > 0:
  204. answer.append('A')
  205. if 'B' in json_string and len(zhijing) > 1:
  206. answer.append('B')
  207. if 'C' in json_string and len(zhijing) > 2:
  208. answer.append('C')
  209. if 'D' in json_string and len(zhijing) > 3:
  210. answer.append('D')
  211. if 'E' in json_string and len(zhijing) > 4:
  212. answer.append('E')
  213. if 'F' in json_string and len(zhijing) > 5:
  214. answer.append('F')
  215. if 'G' in json_string and len(zhijing) > 6:
  216. answer.append('G')
  217. if 'H' in json_string and len(zhijing) > 7:
  218. answer.append('H')
  219. if 'I' in json_string and len(zhijing) > 8:
  220. answer.append('I')
  221. if 'J' in json_string and len(zhijing) > 9:
  222. answer.append('J')
  223. if 'K' in json_string and len(zhijing) > 10:
  224. answer.append('K')
  225. if 'L' in json_string and len(zhijing) > 11:
  226. answer.append('L')
  227. if 'M' in json_string and len(zhijing) > 12:
  228. answer.append('M')
  229. if 'N' in json_string and len(zhijing) > 13:
  230. answer.append('N')
  231. if 'O' in json_string and len(zhijing) > 14:
  232. answer.append('O')
  233. if 'P' in json_string and len(zhijing) > 15:
  234. answer.append('P')
  235. if 'Q' in json_string and len(zhijing) > 16:
  236. answer.append('Q')
  237. if 'R' in json_string and len(zhijing) > 17:
  238. answer.append('R')
  239. return answer
  240. def aifilter1(A, #options
  241. B, #data
  242. aiclient,
  243. qwclient,
  244. sfclient,
  245. dw):
  246. options=[]
  247. letters = "ABCDEFGHIJKLMN"
  248. for i in range(len(A)):
  249. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  250. completion = aiclient.chat.completions.create(
  251. model="glm-4.5-air",
  252. #model="THUDM/GLM-Z1-9B-0414",
  253. #model="ernie-speed-128k",
  254. messages=[
  255. {"role": "system", "content": "You are a helpful assistant."},
  256. {"role": "user", "content": " 特殊处理要求一:如果工作内容描述没有提及管道冲洗,则去掉所有管道冲洗的选项"},
  257. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  258. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  259. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果, 删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  260. ],
  261. extra_body={"thinking": {"type": "disabled"}},
  262. #extra_body={"enable_thinking": True},
  263. #stream=True
  264. )
  265. json_string = completion.choices[0].message.content
  266. print(json_string)
  267. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  268. answer=[]
  269. if 'A' in json_string and len(A) > 0:
  270. answer.append(A[0])
  271. if 'B' in json_string and len(A) > 1:
  272. answer.append(A[1])
  273. if 'C' in json_string and len(A) > 2:
  274. answer.append(A[2])
  275. if 'D' in json_string and len(A) > 3:
  276. answer.append(A[3])
  277. if 'E' in json_string and len(A) > 4:
  278. answer.append(A[4])
  279. if 'F' in json_string and len(A) > 5:
  280. answer.append(A[5])
  281. if 'G' in json_string and len(A) > 6:
  282. answer.append(A[6])
  283. if 'H' in json_string and len(A) > 7:
  284. answer.append(A[7])
  285. if 'I' in json_string and len(A) > 8:
  286. answer.append(A[8])
  287. if 'J' in json_string and len(A) > 9:
  288. answer.append(A[9])
  289. return answer
  290. completion = sfclient.chat.completions.create(
  291. #model="glm-4.5-flash",
  292. model=simplemodel(),
  293. messages=xuanxiang(json_string),
  294. extra_body={"thinking": {"type": "disabled"}},
  295. #extra_body={"enable_thinking": False},
  296. )
  297. json_string = completion.choices[0].message.content
  298. print(json_string)
  299. answer=[]
  300. if 'A' in json_string and len(A) > 0:
  301. answer.append(A[0])
  302. if 'B' in json_string and len(A) > 1:
  303. answer.append(A[1])
  304. if 'C' in json_string and len(A) > 2:
  305. answer.append(A[2])
  306. if 'D' in json_string and len(A) > 3:
  307. answer.append(A[3])
  308. if 'E' in json_string and len(A) > 4:
  309. answer.append(A[4])
  310. if 'F' in json_string and len(A) > 5:
  311. answer.append(A[5])
  312. if 'G' in json_string and len(A) > 6:
  313. answer.append(A[6])
  314. if 'H' in json_string and len(A) > 7:
  315. answer.append(A[7])
  316. if 'I' in json_string and len(A) > 8:
  317. answer.append(A[8])
  318. if 'J' in json_string and len(A) > 9:
  319. answer.append(A[9])
  320. return answer
  321. def postprocess0308(selected, data, aiclient, qwclient, sfclient, label_name, name_dw, candidates):
  322. prime = selected
  323. if len([x for x in selected if ' 低压碳钢管(电弧焊)' in x]) > 0:
  324. prime = [x for x in prime if ' 低压碳钢管(电弧焊)' not in x]
  325. option = select_zhijing(data, aiclient, qwclient, sfclient, name_dw)
  326. if 'A' in option:
  327. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 15')
  328. elif 'B' in option:
  329. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 20')
  330. elif 'C' in option:
  331. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 25')
  332. elif 'D' in option:
  333. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 32')
  334. elif 'E' in option:
  335. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 40')
  336. elif 'F' in option:
  337. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 50')
  338. elif 'G' in option:
  339. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 65')
  340. elif 'H' in option:
  341. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 80')
  342. elif 'I' in option:
  343. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 100')
  344. elif 'J' in option:
  345. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 125')
  346. elif 'K' in option:
  347. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 150')
  348. elif 'L' in option:
  349. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 200')
  350. elif 'M' in option:
  351. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 250')
  352. elif 'N' in option:
  353. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 300')
  354. elif 'O' in option:
  355. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 350')
  356. elif 'P' in option:
  357. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 400')
  358. elif 'Q' in option:
  359. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 450')
  360. elif 'R' in option:
  361. prime.append('第八册 工业管道工程 第一章 管道安装 1.1 低压管道 1.1.5 碳钢管(电弧焊) 低压碳钢管(电弧焊) 公称直径(mm以内) 500')
  362. if data['bianma'].startswith('030801'):
  363. prime = [x for x in prime if '管件' not in x]
  364. if kongqichuisao(data, aiclient, qwclient, sfclient, name_dw):
  365. prime = [x for x in prime if '空气吹扫' not in x]
  366. t = select_chuisao(data, aiclient, qwclient, sfclient, name_dw)
  367. if 'A' in t:
  368. prime.append('第八册 工业管道工程 第六章 管道压力试验、吹扫与清洗 6.2 管道系统吹扫 6.2.2 空气吹扫 管道系统空气吹扫 公称直径(mm以内) 50')
  369. elif 'B' in t:
  370. prime.append('第八册 工业管道工程 第六章 管道压力试验、吹扫与清洗 6.2 管道系统吹扫 6.2.2 空气吹扫 管道系统空气吹扫 公称直径(mm以内) 100')
  371. elif 'C' in t:
  372. prime.append('第八册 工业管道工程 第六章 管道压力试验、吹扫与清洗 6.2 管道系统吹扫 6.2.2 空气吹扫 管道系统空气吹扫 公称直径(mm以内) 200')
  373. elif 'D' in t:
  374. prime.append('第八册 工业管道工程 第六章 管道压力试验、吹扫与清洗 6.2 管道系统吹扫 6.2.2 空气吹扫 管道系统空气吹扫 公称直径(mm以内) 300')
  375. elif 'E' in t:
  376. prime.append('第八册 工业管道工程 第六章 管道压力试验、吹扫与清洗 6.2 管道系统吹扫 6.2.2 空气吹扫 管道系统空气吹扫 公称直径(mm以内) 400')
  377. elif 'F' in t:
  378. prime.append('第八册 工业管道工程 第六章 管道压力试验、吹扫与清洗 6.2 管道系统吹扫 6.2.2 空气吹扫 管道系统空气吹扫 公称直径(mm以内) 500')
  379. elif 'G' in t:
  380. prime.append('第八册 工业管道工程 第六章 管道压力试验、吹扫与清洗 6.2 管道系统吹扫 6.2.2 空气吹扫 管道系统空气吹扫 公称直径(mm以内) 600')
  381. else:
  382. print(prime)
  383. print('clear chuisao')
  384. prime = [x for x in prime if '空气吹扫' not in x]
  385. if youqi(data, aiclient, qwclient, sfclient, name_dw):
  386. prime = prime + ['第十一册 刷油、防腐蚀、绝热工程 第二章 刷油工程 2.1 管道刷油 管道刷油 防锈漆 第一遍', '第十一册 刷油、防腐蚀、绝热工程 第二章 刷油工程 2.1 管道刷油 管道刷油 防锈漆 第二遍', '第十一册 刷油、防腐蚀、绝热工程 第二章 刷油工程 2.1 管道刷油 管道刷油 调和漆 第一遍', '第十一册 刷油、防腐蚀、绝热工程 第二章 刷油工程 2.1 管道刷油 管道刷油 调和漆 第二遍']
  387. return list(set(prime))