postprocess0308.py 20 KB

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