postprocess0108.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. tuliaos=[
  2. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 薄型 0.5小时',
  3. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 薄型 1小时',
  4. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 薄型 1.5小时',
  5. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 薄型 2小时',
  6. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 厚型 2小时',
  7. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 厚型 2.5小时',
  8. '第十七章 油漆、涂料、裱糊工程 17.1 油漆、涂料 17.1.2 金属面油漆 17.1.2.3 防火涂料 金属面防火涂料 厚型 3小时',
  9. ]
  10. tuliao_options=[]
  11. tuliao_letters='ABCDEFG'
  12. for i in range(len(tuliaos)):
  13. tuliao_options.append('给定选项'+tuliao_letters[i]+', 内容为' + tuliaos[i])
  14. import json
  15. with open('nantong_rule', 'r') as f:
  16. content = f.read()
  17. import json
  18. obj=json.loads(content)
  19. from fallback import fallback
  20. def aifilter1(A, #options
  21. B, #data
  22. aiclient,
  23. qwclient,
  24. dw):
  25. options=[]
  26. letters = "ABCDEFGHIJKLMN"
  27. for i in range(len(A)):
  28. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  29. completion = aiclient.chat.completions.create(
  30. model="glm-z1-flash",
  31. #model="Qwen/Qwen3-14B",
  32. messages=[
  33. {"role": "system", "content": "You are a helpful assistant."},
  34. {"role": "user", "content": " 特殊处理要求:去掉所有含有“五金配件”字样的选项"},
  35. {"role": "user", "content": " 特殊处理要求:去掉所有含有“金属面油漆”字样的选项"},
  36. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  37. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  38. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  39. ],
  40. extra_body={"thinking": {"type": "enabled"}},
  41. #extra_body={"enable_thinking": False},
  42. )
  43. json_string = completion.choices[0].message.content
  44. print(json_string)
  45. completion = aiclient.chat.completions.create(
  46. model="glm-4.5-flash",
  47. messages=[
  48. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  49. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B,C]的数组作为结果,请将该最终结果输出"},
  50. ],
  51. extra_body={"thinking": {"type": "disabled"}},
  52. #extra_body={"enable_thinking": False},
  53. )
  54. json_string = completion.choices[0].message.content
  55. print(json_string)
  56. answer=[]
  57. if 'A' in json_string:
  58. answer.append(A[0])
  59. if 'B' in json_string:
  60. answer.append(A[1])
  61. if 'C' in json_string:
  62. answer.append(A[2])
  63. if 'D' in json_string:
  64. answer.append(A[3])
  65. if 'E' in json_string:
  66. answer.append(A[4])
  67. if 'F' in json_string:
  68. answer.append(A[5])
  69. if 'G' in json_string:
  70. answer.append(A[6])
  71. if 'H' in json_string:
  72. answer.append(A[7])
  73. if 'I' in json_string:
  74. answer.append(A[8])
  75. if 'J' in json_string:
  76. answer.append(A[9])
  77. return answer
  78. def aifilter2(A, #options
  79. B, #data
  80. aiclient,
  81. qwclient,
  82. dw):
  83. options=[]
  84. letters = "ABCDEFGHIJKLMN"
  85. for i in range(len(A)):
  86. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  87. completion = aiclient.chat.completions.create(
  88. model="glm-4.5-flash",
  89. #model="Qwen/Qwen3-14B",
  90. messages=[
  91. {"role": "system", "content": "You are a helpful assistant."},
  92. {"role": "user", "content": " 特殊处理要求:如果工作内容的描述没有明确提及无框,则去掉含有“无框”字样的选项"},
  93. {"role": "user", "content": " 特殊处理要求:防火门与放火卷帘门是完全不同的产品。如果工作内容的描述没有明确提及防火卷帘门,则去掉防火卷帘门的选项"},
  94. {"role": "user", "content": " 特殊处理要求:防火门与铝合金门是完全不同的产品。如果工作内容的描述是防火门,则去掉铝合金门的选项"},
  95. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  96. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  97. ],
  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. if len(json_string) < 4:
  104. answer=[]
  105. if 'A' in json_string:
  106. answer.append(A[0])
  107. if 'B' in json_string:
  108. answer.append(A[1])
  109. if 'C' in json_string:
  110. answer.append(A[2])
  111. if 'D' in json_string:
  112. answer.append(A[3])
  113. if 'E' in json_string:
  114. answer.append(A[4])
  115. if 'F' in json_string:
  116. answer.append(A[5])
  117. if 'G' in json_string:
  118. answer.append(A[6])
  119. if 'H' in json_string:
  120. answer.append(A[7])
  121. if 'I' in json_string:
  122. answer.append(A[8])
  123. if 'J' in json_string:
  124. answer.append(A[9])
  125. return answer
  126. completion = aiclient.chat.completions.create(
  127. model="glm-4.5-flash",
  128. messages=[
  129. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  130. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B,C]的数组作为结果,请将该最终结果输出"},
  131. ],
  132. extra_body={"thinking": {"type": "disabled"}},
  133. #extra_body={"enable_thinking": False},
  134. )
  135. json_string = completion.choices[0].message.content
  136. print(json_string)
  137. answer=[]
  138. if 'A' in json_string:
  139. answer.append(A[0])
  140. if 'B' in json_string:
  141. answer.append(A[1])
  142. if 'C' in json_string:
  143. answer.append(A[2])
  144. if 'D' in json_string:
  145. answer.append(A[3])
  146. if 'E' in json_string:
  147. answer.append(A[4])
  148. if 'F' in json_string:
  149. answer.append(A[5])
  150. if 'G' in json_string:
  151. answer.append(A[6])
  152. if 'H' in json_string:
  153. answer.append(A[7])
  154. if 'I' in json_string:
  155. answer.append(A[8])
  156. if 'J' in json_string:
  157. answer.append(A[9])
  158. return answer
  159. def postprocess0108(selected, data, aiclient, qwclient, label_name, name_dw):
  160. prime = aifilter1(selected, data, aiclient, qwclient, name_dw)
  161. if len(prime) == 0:
  162. return []
  163. prime = aifilter2(prime, data, aiclient, qwclient, name_dw)
  164. if len(prime) == 0:
  165. return []
  166. return selected