postprocess0108.py 7.6 KB

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