postprocess0114.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. import time
  2. from fallback import fallback
  3. from config import simplemodel
  4. from template import xuanxiang
  5. import json
  6. with open('name_label', 'r') as f:
  7. content = f.read()
  8. name_label=json.loads(content)
  9. from fallback import fallback
  10. def aifilter1(A, #options
  11. B, #data
  12. aiclient,
  13. qwclient,
  14. sfclient,
  15. dw):
  16. options=[]
  17. letters = "ABCDEFGHIJKLMN"
  18. for i in range(len(A)):
  19. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  20. completion = aiclient.chat.completions.create(
  21. model="glm-4.5-air",
  22. #model="THUDM/GLM-Z1-9B-0414",
  23. #model="ernie-speed-128k",
  24. messages=[
  25. {"role": "system", "content": "You are a helpful assistant."},
  26. {"role": "user", "content": " 特殊处理要求一:如果工作内容提及的是内墙,则去掉所有精确含有“外墙涂料”字样的选项"},
  27. {"role": "user", "content": " 特殊处理要求二:如果工作内容没有明确提及抗裂腻子,则去掉所有精确含有“抗裂腻子”字样的选项"},
  28. {"role": "user", "content": " 特殊处理要求三:如果工作内容没有明确提及批腻子,则去掉所有精确含有“外墙批抗裂腻子”字样的选项"},
  29. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  30. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  31. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果, 删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  32. ],
  33. extra_body={"thinking": {"type": "disabled"}},
  34. #extra_body={"enable_thinking": True},
  35. #stream=True
  36. )
  37. #done_thinking = False
  38. #json_string=""
  39. #thinking_json_string=""
  40. #for chunk in completion:
  41. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  42. # answer_chunk = chunk.choices[0].delta.content
  43. # if thinking_chunk != '':
  44. # thinking_json_string = thinking_json_string + thinking_chunk
  45. # elif answer_chunk != '':
  46. # if not done_thinking:
  47. # done_thinking = True
  48. # json_string = json_string + answer_chunk
  49. json_string = completion.choices[0].message.content
  50. #print(completion.choices[0].message.reasoning_content)
  51. print(json_string)
  52. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  53. answer=[]
  54. if 'A' in json_string and len(A) > 0:
  55. answer.append(A[0])
  56. if 'B' in json_string and len(A) > 1:
  57. answer.append(A[1])
  58. if 'C' in json_string and len(A) > 2:
  59. answer.append(A[2])
  60. if 'D' in json_string and len(A) > 3:
  61. answer.append(A[3])
  62. if 'E' in json_string and len(A) > 4:
  63. answer.append(A[4])
  64. if 'F' in json_string and len(A) > 5:
  65. answer.append(A[5])
  66. if 'G' in json_string and len(A) > 6:
  67. answer.append(A[6])
  68. if 'H' in json_string and len(A) > 7:
  69. answer.append(A[7])
  70. if 'I' in json_string and len(A) > 8:
  71. answer.append(A[8])
  72. if 'J' in json_string and len(A) > 9:
  73. answer.append(A[9])
  74. return answer
  75. completion = sfclient.chat.completions.create(
  76. #model="glm-4.5-flash",
  77. model=simplemodel(),
  78. messages=xuanxiang(json_string),
  79. extra_body={"thinking": {"type": "disabled"}},
  80. #extra_body={"enable_thinking": False},
  81. )
  82. json_string = completion.choices[0].message.content
  83. print(json_string)
  84. answer=[]
  85. if 'A' in json_string and len(A) > 0:
  86. answer.append(A[0])
  87. if 'B' in json_string and len(A) > 1:
  88. answer.append(A[1])
  89. if 'C' in json_string and len(A) > 2:
  90. answer.append(A[2])
  91. if 'D' in json_string and len(A) > 3:
  92. answer.append(A[3])
  93. if 'E' in json_string and len(A) > 4:
  94. answer.append(A[4])
  95. if 'F' in json_string and len(A) > 5:
  96. answer.append(A[5])
  97. if 'G' in json_string and len(A) > 6:
  98. answer.append(A[6])
  99. if 'H' in json_string and len(A) > 7:
  100. answer.append(A[7])
  101. if 'I' in json_string and len(A) > 8:
  102. answer.append(A[8])
  103. if 'J' in json_string and len(A) > 9:
  104. answer.append(A[9])
  105. return answer
  106. def handle_nizi(selected, data,aiclient,qwclient,sfclient,label_name,name_dw,candidates):
  107. options=[]
  108. options_=[]
  109. options.append('不使用腻子')
  110. options.append('使用腻子')
  111. options.append('使用保温腻子')
  112. options.append('腻子2道(遍)')
  113. options.append('腻子3道(遍)')
  114. letters = "ABCDEFGHIJKLMN"
  115. for i in range(len(options)):
  116. options_.append("给定选项" + letters[i]+",内容为"+options[i] )
  117. completion = aiclient.chat.completions.create(
  118. model="glm-4.5-air",
  119. #model="THUDM/GLM-Z1-9B-0414",
  120. #model="ernie-speed-128k",
  121. messages=[
  122. {"role": "system", "content": "You are a helpful assistant."},
  123. {"role": "user", "content": "问题描述: 给定一段工作内容;"+ ",".join(options_) + "。请选出与工作内容最匹配的选项。例如,如果工作内容中不使用腻子,则输出A。再例如,如果工作内容中提到刷腻子2遍,则输出D.现在给定一段工作内容: "+ data['label'] + " " + data['mc'] + " " + data['tz'] + "\n请给出分析过程并请输出A、B这样的字母作为答案"},
  124. ],
  125. extra_body={"thinking": {"type": "disabled"}},
  126. #extra_body={"enable_thinking": True},
  127. #stream=True
  128. )
  129. #done_thinking = False
  130. #json_string=""
  131. #thinking_json_string=""
  132. #for chunk in completion:
  133. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  134. # answer_chunk = chunk.choices[0].delta.content
  135. # if thinking_chunk != '':
  136. # thinking_json_string = thinking_json_string + thinking_chunk
  137. # elif answer_chunk != '':
  138. # if not done_thinking:
  139. # done_thinking = True
  140. # json_string = json_string + answer_chunk
  141. json_string = completion.choices[0].message.content
  142. #print(completion.choices[0].message.reasoning_content)
  143. print(json_string)
  144. if len(json_string) < 5:
  145. answer='A'
  146. if 'B' in json_string:
  147. answer='B'
  148. if 'C' in json_string:
  149. answer='C'
  150. if 'D' in json_string:
  151. answer='D'
  152. if 'E' in json_string:
  153. answer='E'
  154. else:
  155. completion = sfclient.chat.completions.create(
  156. #model="glm-4.5-flash",
  157. model=simplemodel(),
  158. messages=[
  159. {"role": "system", "content": "You are a helpful assistant.请将结果以JSON格式输出"},
  160. {"role": "user", "content": "问题描述: 给定一段内容: " + json_string + "。文字中给出了一个类似于A、B的字母作为答案,请输出这个答案。不需要输出分析过程"},
  161. ],
  162. extra_body={"thinking": {"type": "disabled"}},
  163. #extra_body={"enable_thinking": False},
  164. )
  165. json_string = completion.choices[0].message.content
  166. print(json_string)
  167. answer='A'
  168. if 'B' in json_string:
  169. answer='B'
  170. if 'C' in json_string:
  171. answer='C'
  172. if 'D' in json_string:
  173. answer='D'
  174. if 'E' in json_string:
  175. answer='E'
  176. return answer
  177. def handle_neiqiang(selected, data,aiclient,qwclient,sfclient,label_name,name_dw,candidates):
  178. options=[]
  179. options_=[]
  180. options.append('调和漆')##
  181. options.append('乳胶漆(水性水泥漆)')##
  182. options.append('砂胶喷涂')##
  183. options.append('多彩涂料喷涂')##一整套
  184. options.append('浮雕喷涂料')##一整套
  185. options.append('喷刷白水泥浆、石灰浆、石灰大白浆')##一整套
  186. options.append('水性防霉涂料')##
  187. letters = "ABCDEFGHIJKLMN"
  188. for i in range(len(options)):
  189. options_.append("给定选项" + letters[i]+",内容为"+options[i] )
  190. completion = aiclient.chat.completions.create(
  191. model="glm-4.5-air",
  192. #model="THUDM/GLM-Z1-9B-0414",
  193. #model="ernie-speed-128k",
  194. messages=[
  195. {"role": "system", "content": "You are a helpful assistant."},
  196. {"role": "user", "content": "问题描述: 给定一段工作内容: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ",".join(options_) + "。请选出与工作内容最匹配的涂料选项。如果没有特别匹配的选项,则默认选择选项B。请给出你的选择,请输出A、B这样的字母作为答案"},
  197. ],
  198. extra_body={"thinking": {"type": "disabled"}},
  199. #extra_body={"enable_thinking": True},
  200. #stream=True
  201. )
  202. #done_thinking = False
  203. #json_string=""
  204. #thinking_json_string=""
  205. #for chunk in completion:
  206. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  207. # answer_chunk = chunk.choices[0].delta.content
  208. # if thinking_chunk != '':
  209. # thinking_json_string = thinking_json_string + thinking_chunk
  210. # elif answer_chunk != '':
  211. # if not done_thinking:
  212. # done_thinking = True
  213. # json_string = json_string + answer_chunk
  214. json_string = completion.choices[0].message.content
  215. #print(completion.choices[0].message.reasoning_content)
  216. print(json_string)
  217. if len(json_string) < 5:
  218. answer='A'
  219. if 'B' in json_string:
  220. answer='B'
  221. if 'C' in json_string:
  222. answer='C'
  223. if 'D' in json_string:
  224. answer='D'
  225. if 'E' in json_string:
  226. answer='E'
  227. if 'F' in json_string:
  228. answer='F'
  229. if 'G' in json_string:
  230. answer='G'
  231. else:
  232. completion = sfclient.chat.completions.create(
  233. #model="glm-4.5-flash",
  234. model=simplemodel(),
  235. messages=[
  236. {"role": "system", "content": "You are a helpful assistant.请将结果以JSON格式输出"},
  237. {"role": "user", "content": "问题描述: 给定一段内容: " + json_string + "。文字中给出了一个类似于A、B的字母作为答案,请输出这个答案。不需要输出分析过程"},
  238. ],
  239. extra_body={"thinking": {"type": "disabled"}},
  240. #extra_body={"enable_thinking": False},
  241. )
  242. json_string = completion.choices[0].message.content
  243. print(json_string)
  244. answer='A'
  245. if 'B' in json_string:
  246. answer='B'
  247. if 'C' in json_string:
  248. answer='C'
  249. if 'D' in json_string:
  250. answer='D'
  251. if 'E' in json_string:
  252. answer='E'
  253. if 'F' in json_string:
  254. answer='F'
  255. if 'G' in json_string:
  256. answer='G'
  257. if answer=='A':
  258. return [name_label['17-160']]
  259. if answer=='B':
  260. return [name_label['17-177']]
  261. if answer=='C':
  262. return [name_label['17-205']]
  263. if answer=='D':
  264. return [name_label['17-210']]
  265. if answer=='E':
  266. return [name_label['17-220']]
  267. if answer=='F':
  268. return [name_label['17-224']]
  269. if answer=='G':
  270. nizi = handle_nizi(selected, data,aiclient,qwclient,sfclient,label_name,name_dw,candidates)
  271. if nizi == 'A':
  272. return [name_label['17-CB5']]
  273. return [name_label['17-CB4']]##满刮腻子
  274. def handle_waiqiang(nizi, selected, data,aiclient,qwclient,sfclient,label_name,name_dw,candidates):
  275. options=[]
  276. options_=[]
  277. options.append('外墙丙烯酸弹性乳胶漆')##不包括腻子,二遍
  278. options.append('外墙苯丙乳胶漆')##不包括腻子,二遍
  279. options.append('外墙溶剂涂料')##一整套
  280. options.append('外墙弹性涂料')##包括两遍腻子,一底二面
  281. options.append('外墙批抗裂腻子(不刷涂料)')
  282. options.append('外墙彩砂喷涂')##包括腻子二遍,喷面层二遍
  283. options.append('喷涂外墙乳液型涂料')##一整套
  284. options.append('外墙真石漆')##一整套
  285. options.append('浮雕喷涂料外墙')##一整套
  286. letters = "ABCDEFGHIJKLMN"
  287. for i in range(len(options)):
  288. options_.append("给定选项" + letters[i]+",内容为"+options[i] )
  289. completion = aiclient.chat.completions.create(
  290. model="glm-4.5-air",
  291. #model="THUDM/GLM-Z1-9B-0414",
  292. #model="ernie-speed-128k",
  293. messages=[
  294. {"role": "system", "content": "You are a helpful assistant."},
  295. {"role": "user", "content": "问题描述: 给定一段工作内容: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ",".join(options_) + "。请选出与工作内容最匹配的外墙涂料选项。如果工作内容只提及外墙涂料,没有更细节的介绍,则选择选项D。请给出你的选择,请输出A、B这样的字母作为答案"},
  296. ],
  297. extra_body={"thinking": {"type": "disabled"}},
  298. #extra_body={"enable_thinking": True},
  299. #stream=True
  300. )
  301. #done_thinking = False
  302. #json_string=""
  303. #thinking_json_string=""
  304. #for chunk in completion:
  305. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  306. # answer_chunk = chunk.choices[0].delta.content
  307. # if thinking_chunk != '':
  308. # thinking_json_string = thinking_json_string + thinking_chunk
  309. # elif answer_chunk != '':
  310. # if not done_thinking:
  311. # done_thinking = True
  312. # json_string = json_string + answer_chunk
  313. json_string = completion.choices[0].message.content
  314. #print(completion.choices[0].message.reasoning_content)
  315. print(json_string)
  316. if len(json_string) < 5:
  317. answer='A'
  318. if 'B' in json_string:
  319. answer='B'
  320. if 'C' in json_string:
  321. answer='C'
  322. if 'D' in json_string:
  323. answer='D'
  324. if 'E' in json_string:
  325. answer='E'
  326. if 'F' in json_string:
  327. answer='F'
  328. if 'G' in json_string:
  329. answer='G'
  330. if 'H' in json_string:
  331. answer='H'
  332. if 'I' in json_string:
  333. answer='I'
  334. else:
  335. completion = sfclient.chat.completions.create(
  336. #model="glm-4.5-flash",
  337. model=simplemodel(),
  338. messages=[
  339. {"role": "system", "content": "You are a helpful assistant.请将结果以JSON格式输出"},
  340. {"role": "user", "content": "问题描述: 给定一段内容: " + json_string + "。文字中给出了一个类似于A、B的字母作为答案,请输出这个答案。不需要输出分析过程"},
  341. ],
  342. extra_body={"thinking": {"type": "disabled"}},
  343. #extra_body={"enable_thinking": False},
  344. )
  345. json_string = completion.choices[0].message.content
  346. print(json_string)
  347. answer='A'
  348. if 'B' in json_string:
  349. answer='B'
  350. if 'C' in json_string:
  351. answer='C'
  352. if 'D' in json_string:
  353. answer='D'
  354. if 'E' in json_string:
  355. answer='E'
  356. if 'F' in json_string:
  357. answer='F'
  358. if 'G' in json_string:
  359. answer='G'
  360. if 'H' in json_string:
  361. answer='H'
  362. if 'I' in json_string:
  363. answer='I'
  364. if answer=='A':
  365. return [name_label['NT17-补22']] + nizi
  366. if answer=='B':
  367. return [name_label['17-192']] + nizi
  368. if answer=='C':
  369. return [name_label['17-199']] + nizi
  370. if answer=='D':
  371. return [name_label['17-197']] + nizi
  372. if answer=='E':
  373. return [name_label['17-195']]
  374. if answer=='F':
  375. return [name_label['17-202']] + nizi
  376. if answer=='G':
  377. return [name_label['17-207']]+ nizi
  378. if answer=='H':
  379. return [name_label['17-218']] + nizi
  380. if answer=='I':
  381. return [name_label['17-222']] + nizi
  382. def handle_mohui(selected, data,aiclient,qwclient,sfclient,label_name,name_dw,candidates):
  383. if '外墙' in data['tz']:
  384. result = []
  385. nizi = handle_nizi(selected, data,aiclient,qwclient,sfclient,label_name,name_dw,candidates)
  386. if nizi == 'C':
  387. result = [name_label['14-CB1(1)']]
  388. if nizi == 'D':
  389. result = [name_label['17-164']]
  390. if nizi == 'E':
  391. result = [name_label['17-164']]
  392. return handle_waiqiang(result, selected,data,aiclient,qwclient,sfclient,label_name,name_dw,candidates)
  393. return handle_neiqiang(selected,data,aiclient,qwclient,sfclient,label_name,name_dw,candidates)
  394. def postprocess0114(selected, data, aiclient, qwclient, sfclient, label_name, name_dw, candidates):
  395. mu =0
  396. jinshu=0
  397. mohui=0
  398. for entry in selected:
  399. if '17.1.1' in entry:
  400. mu = mu + 1
  401. if '17.1.2' in entry:
  402. jinshu = jinshu + 1
  403. if '17.1.3' in entry:
  404. mohui = mohui + 1
  405. if mohui > mu and mohui > jinshu:
  406. return handle_mohui(selected,data,aiclient,qwclient,sfclient,label_name,name_dw,candidates)
  407. prime = aifilter1(selected, data, aiclient, qwclient, sfclient, name_dw)
  408. if len(prime) == 0:
  409. selected = fallback(candidates, data, aiclient, qwclient, sfclient, None, None)
  410. return selected
  411. return prime