postprocess011105.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. import time
  2. from config import simplemodel
  3. from template import xuanxiang
  4. import json
  5. with open('zhaoping_rule', 'r') as f:
  6. content = f.read()
  7. import json
  8. obj=json.loads(content)
  9. with open('name_label', 'r') as f:
  10. content = f.read()
  11. import json
  12. name_label=json.loads(content)
  13. tijiaoxian = ['13-95', '13-27', '13-127', '13-128', '13-129', '13-130', '13-131', '13-34', '13-72', '13-76', '13-100']
  14. example1='''
  15. 1、用于地下楼梯间、走道地面 做法详见图纸设计及相关图集规范
  16. 2、100厚C25细石混凝土随打随抹,内配Φ4@200钢筋网片,抹平压光
  17. '''
  18. example2='''
  19. 1、用于消防泵房地面 做法详见图纸设计及相关图集规范
  20. 2、50厚C25细石混凝土随打随抹,内配Φ4@200钢筋网片,抹平压光
  21. 3、最薄处30厚C20细石混凝土向排水沟、集水坑找1%坡,随打随抹平,立管根部用DS M15砂浆(1:3水泥砂浆)抹小八字角
  22. '''
  23. from fallback import fallback
  24. def aifilter5(A, #options
  25. B, #data
  26. aiclient,
  27. qwclient,
  28. sfclient,
  29. dw):
  30. options=[]
  31. letters = "ABCDEFGHIJKLMN"
  32. for i in range(len(tijiaoxian)):
  33. options.append("给定选项" + letters[i]+",内容为"+name_label[tijiaoxian[i]] )
  34. completion = aiclient.chat.completions.create(
  35. #model="THUDM/GLM-4-9B-0414",
  36. model="glm-4.5-air",
  37. #model="Qwen/Qwen3-8B",
  38. #model="ernie-speed-128k",
  39. messages=[
  40. {"role": "system", "content": "You are a helpful assistant."},
  41. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + "。该工作内容的描述中包含踢脚线施工。"+';'.join(options)+'。请选出与工作内容最匹配的一个选项并返回代号。例如,你觉得选项A最匹配,则你应该返回A'},
  42. ],
  43. extra_body={"thinking": {"type": "disabled"}},
  44. #extra_body={"enable_thinking": True},
  45. #stream=True
  46. )
  47. json_string = completion.choices[0].message.content
  48. print(json_string)
  49. answer=[]
  50. if len(json_string) < 4:
  51. if 'A' in json_string:
  52. answer.append(name_label[tijiaoxian[0]])
  53. if 'B' in json_string:
  54. answer.append(name_label[tijiaoxian[1]])
  55. if 'C' in json_string:
  56. answer.append(name_label[tijiaoxian[2]])
  57. if 'D' in json_string:
  58. answer.append(name_label[tijiaoxian[3]])
  59. if 'E' in json_string:
  60. answer.append(name_label[tijiaoxian[4]])
  61. if 'F' in json_string:
  62. answer.append(name_label[tijiaoxian[5]])
  63. if 'G' in json_string:
  64. answer.append(name_label[tijiaoxian[6]])
  65. if 'H' in json_string:
  66. answer.append(name_label[tijiaoxian[7]])
  67. if 'I' in json_string:
  68. answer.append(name_label[tijiaoxian[8]])
  69. if 'J' in json_string:
  70. answer.append(name_label[tijiaoxian[9]])
  71. if 'K' in json_string:
  72. answer.append(name_label[tijiaoxian[10]])
  73. return answer
  74. completion = sfclient.chat.completions.create(
  75. model=simplemodel(),
  76. messages=[
  77. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  78. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于A或者B的英文字母作为答案,请将该字母答案输出"},
  79. ],
  80. extra_body={"thinking": {"type": "disabled"}},
  81. #extra_body={"enable_thinking": False},
  82. )
  83. json_string = completion.choices[0].message.content
  84. print(json_string)
  85. if 'A' in json_string:
  86. answer.append(name_label[tijiaoxian[0]])
  87. if 'B' in json_string:
  88. answer.append(name_label[tijiaoxian[1]])
  89. if 'C' in json_string:
  90. answer.append(name_label[tijiaoxian[2]])
  91. if 'D' in json_string:
  92. answer.append(name_label[tijiaoxian[3]])
  93. if 'E' in json_string:
  94. answer.append(name_label[tijiaoxian[4]])
  95. if 'F' in json_string:
  96. answer.append(name_label[tijiaoxian[5]])
  97. if 'G' in json_string:
  98. answer.append(name_label[tijiaoxian[6]])
  99. if 'H' in json_string:
  100. answer.append(name_label[tijiaoxian[7]])
  101. if 'I' in json_string:
  102. answer.append(name_label[tijiaoxian[8]])
  103. if 'J' in json_string:
  104. answer.append(name_label[tijiaoxian[9]])
  105. if 'K' in json_string:
  106. answer.append(name_label[tijiaoxian[10]])
  107. return answer
  108. def aifilter3(A, #options
  109. B, #data
  110. aiclient,
  111. qwclient,
  112. sfclient,
  113. dw):
  114. options=[]
  115. letters = "ABCDEFGHIJKLMN"
  116. for i in range(len(A)):
  117. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  118. completion = aiclient.chat.completions.create(
  119. #model="THUDM/GLM-4-9B-0414",
  120. model="glm-4.5-air",
  121. #model="Qwen/Qwen3-8B",
  122. #model="ernie-speed-128k",
  123. messages=[
  124. {"role": "system", "content": "You are a helpful assistant."},
  125. {"role": "user", "content": "问题描述: 细石混凝土内配钢筋网片是一种常见的施工工艺。给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + "。请问该工作内容的描述中有同时包含混凝土以及钢筋网片吗?请回答有或者没有"},
  126. ],
  127. extra_body={"thinking": {"type": "disabled"}},
  128. #extra_body={"enable_thinking": True},
  129. #stream=True
  130. )
  131. json_string = completion.choices[0].message.content
  132. print(json_string)
  133. if len(json_string) < 4:
  134. if '没有' in json_string:
  135. return False
  136. return True
  137. completion = sfclient.chat.completions.create(
  138. model=simplemodel(),
  139. messages=[
  140. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  141. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个有或者没有的判断,请将该中文判断输出"},
  142. ],
  143. extra_body={"thinking": {"type": "disabled"}},
  144. #extra_body={"enable_thinking": False},
  145. )
  146. json_string = completion.choices[0].message.content
  147. print(json_string)
  148. if '没有' in json_string:
  149. return False
  150. return True
  151. def aifilter4(A, #options
  152. B, #data
  153. aiclient,
  154. qwclient,
  155. sfclient,
  156. dw):
  157. options=[]
  158. letters = "ABCDEFGHIJKLMN"
  159. for i in range(len(A)):
  160. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  161. completion = aiclient.chat.completions.create(
  162. model="glm-4.5-air",
  163. #model="THUDM/GLM-Z1-9B-0414",
  164. #model="ernie-speed-128k",
  165. messages=[
  166. {"role": "system", "content": "You are a helpful assistant."},
  167. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土找平层是不同的施工步骤,不得混淆"},
  168. {"role": "user", "content": " 背景知识:细石混凝土楼地面不是块料面层,而是混凝土整体面层"},
  169. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土垫层是不同的施工步骤,不得混淆"},
  170. {"role": "user", "content": " 背景知识:混凝土(砼)找平层跟混凝土垫层是不同的施工步骤,不得混淆"},
  171. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆面层是不同的施工步骤,不得混淆"},
  172. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆保护层是不同的施工步骤,不得混淆"},
  173. {"role": "user", "content": " 特殊处理要求:如果工作内容描述中明确提到块料面层,比如地砖、石材块料等,则去掉精确包含“细石砼整体面层”字样的选项"},
  174. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  175. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  176. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果, 删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  177. ],
  178. extra_body={"thinking": {"type": "disabled"}},
  179. #extra_body={"enable_thinking": True},
  180. #stream=True
  181. )
  182. ##done_thinking = False
  183. ##json_string=""
  184. ##thinking_json_string=""
  185. ##for chunk in completion:
  186. ## thinking_chunk = chunk.choices[0].delta.reasoning_content
  187. ## answer_chunk = chunk.choices[0].delta.content
  188. ## if thinking_chunk != '':
  189. ## thinking_json_string = thinking_json_string + thinking_chunk
  190. ## elif answer_chunk != '':
  191. ## if not done_thinking:
  192. ## done_thinking = True
  193. ## json_string = json_string + answer_chunk
  194. json_string = completion.choices[0].message.content
  195. #print(completion.choices[0].message.reasoning_content)
  196. print(json_string)
  197. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  198. answer=[]
  199. if 'A' in json_string and len(A) > 0:
  200. answer.append(A[0])
  201. if 'B' in json_string and len(A) > 1:
  202. answer.append(A[1])
  203. if 'C' in json_string and len(A) > 2:
  204. answer.append(A[2])
  205. if 'D' in json_string and len(A) > 3:
  206. answer.append(A[3])
  207. if 'E' in json_string and len(A) > 4:
  208. answer.append(A[4])
  209. if 'F' in json_string and len(A) > 5:
  210. answer.append(A[5])
  211. if 'G' in json_string and len(A) > 6:
  212. answer.append(A[6])
  213. if 'H' in json_string and len(A) > 7:
  214. answer.append(A[7])
  215. if 'I' in json_string and len(A) > 8:
  216. answer.append(A[8])
  217. if 'J' in json_string and len(A) > 9:
  218. answer.append(A[9])
  219. return answer
  220. completion = sfclient.chat.completions.create(
  221. model=simplemodel(),
  222. #model="glm-4.5-flash",
  223. messages=xuanxiang(json_string),
  224. extra_body={"thinking": {"type": "disabled"}},
  225. #extra_body={"enable_thinking": False},
  226. )
  227. json_string = completion.choices[0].message.content
  228. print(json_string)
  229. answer=[]
  230. if 'A' in json_string and len(A) > 0:
  231. answer.append(A[0])
  232. if 'B' in json_string and len(A) > 1:
  233. answer.append(A[1])
  234. if 'C' in json_string and len(A) > 2:
  235. answer.append(A[2])
  236. if 'D' in json_string and len(A) > 3:
  237. answer.append(A[3])
  238. if 'E' in json_string and len(A) > 4:
  239. answer.append(A[4])
  240. if 'F' in json_string and len(A) > 5:
  241. answer.append(A[5])
  242. if 'G' in json_string and len(A) > 6:
  243. answer.append(A[6])
  244. if 'H' in json_string and len(A) > 7:
  245. answer.append(A[7])
  246. if 'I' in json_string and len(A) > 8:
  247. answer.append(A[8])
  248. if 'J' in json_string and len(A) > 9:
  249. answer.append(A[9])
  250. return answer
  251. def aifilter1_2(A, #options
  252. B, #data
  253. aiclient,
  254. qwclient,
  255. sfclient,
  256. dw):
  257. options=[]
  258. letters = "ABCDEFGHIJKLMN"
  259. for i in range(len(A)):
  260. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  261. completion = aiclient.chat.completions.create(
  262. model="glm-4.5-air",
  263. #model="THUDM/GLM-Z1-9B-0414",
  264. #model="ernie-speed-128k",
  265. messages=[
  266. {"role": "system", "content": "You are a helpful assistant."},
  267. {"role": "user", "content": " 背景知识:混凝土楼地面是面层,跟混凝土垫层是不同的施工步骤,不得混淆"},
  268. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土找平层是不同的施工步骤,不得混淆"},
  269. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土垫层是不同的施工步骤,不得混淆"},
  270. {"role": "user", "content": " 背景知识:混凝土(砼)找平层跟混凝土垫层是不同的施工步骤,不得混淆"},
  271. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆面层是不同的施工步骤,不得混淆"},
  272. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆保护层是不同的施工步骤,不得混淆"},
  273. {"role": "user", "content": " 特殊处理要求一:如果工作内容描述中**没有**明确提到素水泥浆,则**去掉**所有含有“素水泥浆”字样的选项"},
  274. {"role": "user", "content": " 特殊处理要求二:如果工作内容描述中**没有**明确提到“加浆抹光”,则**去掉**所有含有“加浆抹光”字样的选项"},
  275. {"role": "user", "content": " 特殊处理要求三:如果工作内容描述中**没有**明确提到混凝土垫层,则**去掉**所有混凝土垫层的选项"},
  276. {"role": "user", "content": " 特殊处理要求四:如果选项中同时存在“冷轧带肋钢筋”选项和“抗裂基层 热镀锌钢丝网”选项,则去掉热镀锌钢丝网的选项"},
  277. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  278. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  279. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果,删除选项必须对应到明确的特殊处理要求,不要擅自删除选项.例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  280. ],
  281. extra_body={"thinking": {"type": "disabled"}},
  282. #extra_body={"enable_thinking": True},
  283. #stream=True
  284. )
  285. #done_thinking = False
  286. #json_string=""
  287. #thinking_json_string=""
  288. #for chunk in completion:
  289. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  290. # answer_chunk = chunk.choices[0].delta.content
  291. # if thinking_chunk != '':
  292. # thinking_json_string = thinking_json_string + thinking_chunk
  293. # elif answer_chunk != '':
  294. # if not done_thinking:
  295. # done_thinking = True
  296. # json_string = json_string + answer_chunk
  297. json_string = completion.choices[0].message.content
  298. #print(completion.choices[0].message.reasoning_content)
  299. print(json_string)
  300. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  301. answer=[]
  302. if 'A' in json_string and len(A) > 0:
  303. answer.append(A[0])
  304. if 'B' in json_string and len(A) > 1:
  305. answer.append(A[1])
  306. if 'C' in json_string and len(A) > 2:
  307. answer.append(A[2])
  308. if 'D' in json_string and len(A) > 3:
  309. answer.append(A[3])
  310. if 'E' in json_string and len(A) > 4:
  311. answer.append(A[4])
  312. if 'F' in json_string and len(A) > 5:
  313. answer.append(A[5])
  314. if 'G' in json_string and len(A) > 6:
  315. answer.append(A[6])
  316. if 'H' in json_string and len(A) > 7:
  317. answer.append(A[7])
  318. if 'I' in json_string and len(A) > 8:
  319. answer.append(A[8])
  320. if 'J' in json_string and len(A) > 9:
  321. answer.append(A[9])
  322. return answer
  323. completion = sfclient.chat.completions.create(
  324. model=simplemodel(),
  325. messages=xuanxiang(json_string),
  326. extra_body={"thinking": {"type": "disabled"}},
  327. #extra_body={"enable_thinking": False},
  328. )
  329. json_string = completion.choices[0].message.content
  330. print(json_string)
  331. answer=[]
  332. if 'A' in json_string and len(A) > 0:
  333. answer.append(A[0])
  334. if 'B' in json_string and len(A) > 1:
  335. answer.append(A[1])
  336. if 'C' in json_string and len(A) > 2:
  337. answer.append(A[2])
  338. if 'D' in json_string and len(A) > 3:
  339. answer.append(A[3])
  340. if 'E' in json_string and len(A) > 4:
  341. answer.append(A[4])
  342. if 'F' in json_string and len(A) > 5:
  343. answer.append(A[5])
  344. if 'G' in json_string and len(A) > 6:
  345. answer.append(A[6])
  346. if 'H' in json_string and len(A) > 7:
  347. answer.append(A[7])
  348. if 'I' in json_string and len(A) > 8:
  349. answer.append(A[8])
  350. if 'J' in json_string and len(A) > 9:
  351. answer.append(A[9])
  352. return answer
  353. def aifilter1_3(A, #options
  354. B, #data
  355. aiclient,
  356. qwclient,
  357. sfclient,
  358. dw):
  359. options=[]
  360. letters = "ABCDEFGHIJKLMN"
  361. for i in range(len(A)):
  362. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  363. completion = aiclient.chat.completions.create(
  364. model="glm-4.5-air",
  365. #model="THUDM/GLM-Z1-9B-0414",
  366. #model="ernie-speed-128k",
  367. messages=[
  368. {"role": "system", "content": "You are a helpful assistant."},
  369. {"role": "user", "content": " 背景知识:混凝土楼地面是面层,跟混凝土垫层是不同的施工步骤,不得混淆"},
  370. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土找平层是不同的施工步骤,不得混淆"},
  371. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土垫层是不同的施工步骤,不得混淆"},
  372. {"role": "user", "content": " 背景知识:混凝土(砼)找平层跟混凝土垫层是不同的施工步骤,不得混淆"},
  373. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆面层是不同的施工步骤,不得混淆"},
  374. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆保护层是不同的施工步骤,不得混淆"},
  375. {"role": "user", "content": " 特殊处理要求:如果工作内容描述中没有明确提到石材面刷防护剂,则去掉所有含有“石材面刷防护剂”字样的选项"},
  376. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  377. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  378. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果,删除选项必须对应到明确的特殊处理要求,不要擅自删除选项.例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  379. ],
  380. extra_body={"thinking": {"type": "disabled"}},
  381. #extra_body={"enable_thinking": True},
  382. #stream=True
  383. )
  384. #done_thinking = False
  385. #json_string=""
  386. #thinking_json_string=""
  387. #for chunk in completion:
  388. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  389. # answer_chunk = chunk.choices[0].delta.content
  390. # if thinking_chunk != '':
  391. # thinking_json_string = thinking_json_string + thinking_chunk
  392. # elif answer_chunk != '':
  393. # if not done_thinking:
  394. # done_thinking = True
  395. # json_string = json_string + answer_chunk
  396. json_string = completion.choices[0].message.content
  397. #print(completion.choices[0].message.reasoning_content)
  398. print(json_string)
  399. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  400. answer=[]
  401. if 'A' in json_string and len(A) > 0:
  402. answer.append(A[0])
  403. if 'B' in json_string and len(A) > 1:
  404. answer.append(A[1])
  405. if 'C' in json_string and len(A) > 2:
  406. answer.append(A[2])
  407. if 'D' in json_string and len(A) > 3:
  408. answer.append(A[3])
  409. if 'E' in json_string and len(A) > 4:
  410. answer.append(A[4])
  411. if 'F' in json_string and len(A) > 5:
  412. answer.append(A[5])
  413. if 'G' in json_string and len(A) > 6:
  414. answer.append(A[6])
  415. if 'H' in json_string and len(A) > 7:
  416. answer.append(A[7])
  417. if 'I' in json_string and len(A) > 8:
  418. answer.append(A[8])
  419. if 'J' in json_string and len(A) > 9:
  420. answer.append(A[9])
  421. return answer
  422. completion = sfclient.chat.completions.create(
  423. model=simplemodel(),
  424. messages=xuanxiang(json_string),
  425. extra_body={"thinking": {"type": "disabled"}},
  426. #extra_body={"enable_thinking": False},
  427. )
  428. json_string = completion.choices[0].message.content
  429. print(json_string)
  430. answer=[]
  431. if 'A' in json_string and len(A) > 0:
  432. answer.append(A[0])
  433. if 'B' in json_string and len(A) > 1:
  434. answer.append(A[1])
  435. if 'C' in json_string and len(A) > 2:
  436. answer.append(A[2])
  437. if 'D' in json_string and len(A) > 3:
  438. answer.append(A[3])
  439. if 'E' in json_string and len(A) > 4:
  440. answer.append(A[4])
  441. if 'F' in json_string and len(A) > 5:
  442. answer.append(A[5])
  443. if 'G' in json_string and len(A) > 6:
  444. answer.append(A[6])
  445. if 'H' in json_string and len(A) > 7:
  446. answer.append(A[7])
  447. if 'I' in json_string and len(A) > 8:
  448. answer.append(A[8])
  449. if 'J' in json_string and len(A) > 9:
  450. answer.append(A[9])
  451. return answer
  452. def aifilter1(A, #options
  453. B, #data
  454. aiclient,
  455. qwclient,
  456. sfclient,
  457. dw):
  458. options=[]
  459. letters = "ABCDEFGHIJKLMN"
  460. for i in range(len(A)):
  461. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  462. completion = aiclient.chat.completions.create(
  463. model="glm-4.5-air",
  464. #model="THUDM/GLM-Z1-9B-0414",
  465. #model="ernie-speed-128k",
  466. messages=[
  467. {"role": "system", "content": "You are a helpful assistant."},
  468. {"role": "user", "content": " 背景知识:混凝土楼地面是面层,跟混凝土垫层是不同的施工步骤,不得混淆"},
  469. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土找平层是不同的施工步骤,不得混淆"},
  470. {"role": "user", "content": " 背景知识:混凝土(砼)整体面层跟混凝土垫层是不同的施工步骤,不得混淆"},
  471. {"role": "user", "content": " 背景知识:混凝土(砼)找平层跟混凝土垫层是不同的施工步骤,不得混淆"},
  472. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆面层是不同的施工步骤,不得混淆"},
  473. {"role": "user", "content": " 背景知识:水泥砂浆找平层跟水泥砂浆保护层是不同的施工步骤,不得混淆"},
  474. {"role": "user", "content": " 特殊处理要求:去掉所有模板工程的选项"},
  475. {"role": "user", "content": " 特殊处理要求:如果工作内容描述中没有明确涉及水泥砂浆面层,且没有提及水泥砂浆保护层,则去掉所有20mm水泥砂浆楼地面面层的选项.注意,是去除面层,不包括找平层"},
  476. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  477. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  478. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果, 删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  479. ],
  480. extra_body={"thinking": {"type": "disabled"}},
  481. #extra_body={"enable_thinking": True},
  482. #stream=True
  483. )
  484. #done_thinking = False
  485. #json_string=""
  486. #thinking_json_string=""
  487. #for chunk in completion:
  488. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  489. # answer_chunk = chunk.choices[0].delta.content
  490. # if thinking_chunk != '':
  491. # thinking_json_string = thinking_json_string + thinking_chunk
  492. # elif answer_chunk != '':
  493. # if not done_thinking:
  494. # done_thinking = True
  495. # json_string = json_string + answer_chunk
  496. json_string = completion.choices[0].message.content
  497. #print(completion.choices[0].message.reasoning_content)
  498. print(json_string)
  499. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  500. answer=[]
  501. if 'A' in json_string and len(A) > 0:
  502. answer.append(A[0])
  503. if 'B' in json_string and len(A) > 1:
  504. answer.append(A[1])
  505. if 'C' in json_string and len(A) > 2:
  506. answer.append(A[2])
  507. if 'D' in json_string and len(A) > 3:
  508. answer.append(A[3])
  509. if 'E' in json_string and len(A) > 4:
  510. answer.append(A[4])
  511. if 'F' in json_string and len(A) > 5:
  512. answer.append(A[5])
  513. if 'G' in json_string and len(A) > 6:
  514. answer.append(A[6])
  515. if 'H' in json_string and len(A) > 7:
  516. answer.append(A[7])
  517. if 'I' in json_string and len(A) > 8:
  518. answer.append(A[8])
  519. if 'J' in json_string and len(A) > 9:
  520. answer.append(A[9])
  521. return answer
  522. completion = sfclient.chat.completions.create(
  523. #model="glm-4.5-flash",
  524. model=simplemodel(),
  525. messages=xuanxiang(json_string),
  526. extra_body={"thinking": {"type": "disabled"}},
  527. #extra_body={"enable_thinking": False},
  528. )
  529. json_string = completion.choices[0].message.content
  530. print(json_string)
  531. answer=[]
  532. if 'A' in json_string and len(A) > 0:
  533. answer.append(A[0])
  534. if 'B' in json_string and len(A) > 1:
  535. answer.append(A[1])
  536. if 'C' in json_string and len(A) > 2:
  537. answer.append(A[2])
  538. if 'D' in json_string and len(A) > 3:
  539. answer.append(A[3])
  540. if 'E' in json_string and len(A) > 4:
  541. answer.append(A[4])
  542. if 'F' in json_string and len(A) > 5:
  543. answer.append(A[5])
  544. if 'G' in json_string and len(A) > 6:
  545. answer.append(A[6])
  546. if 'H' in json_string and len(A) > 7:
  547. answer.append(A[7])
  548. if 'I' in json_string and len(A) > 8:
  549. answer.append(A[8])
  550. if 'J' in json_string and len(A) > 9:
  551. answer.append(A[9])
  552. return answer
  553. def aifilter2(A, #options
  554. B, #data
  555. aiclient,
  556. qwclient,
  557. dw):
  558. hit_wumian = False
  559. for entry in A:
  560. if entry in obj['wumian']:
  561. hit_wumian=True
  562. hit_loumian = False
  563. loumian_entry = ''
  564. for entry in A:
  565. if entry in obj['loumian']:
  566. hit_loumian=True
  567. loumian_entry = entry
  568. if hit_wumian and hit_loumian:
  569. return [x for x in A if x != loumian_entry]
  570. return A
  571. def postprocess011105(selected, data, aiclient, qwclient, sfclient, label_name, name_dw):
  572. prime = aifilter1(selected, data, aiclient, qwclient, sfclient, name_dw)
  573. time.sleep(1)
  574. prime = aifilter1_2(prime, data, aiclient, qwclient, sfclient, name_dw)
  575. time.sleep(1)
  576. prime = aifilter1_3(prime, data, aiclient, qwclient, sfclient, name_dw)
  577. time.sleep(1)
  578. prime = [x for x in prime if not '踢脚线' in x]
  579. xian = aifilter5(selected, data, aiclient, qwclient, sfclient, name_dw)
  580. prime = prime + xian
  581. if '界面剂' in data['tz']:##保温
  582. if len([ x for x in prime if '第十四章 墙柱面工程 14.1 一般抹灰 14.1.3 保温砂浆及抗裂基层 刷界面剂' in x]) == 0:
  583. prime.append('第十四章 墙柱面工程 14.1 一般抹灰 14.1.3 保温砂浆及抗裂基层 刷界面剂 混凝土面') ##需要换
  584. return prime