postprocess0310.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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以内)50', '公称直径(mm以内)80', '公称直径(mm以内)100', '公称直径(mm以内)150' , '公称直径(mm以内)200', '公称直径(mm以内)250', '公称直径(mm以内)300']
  7. def select_zhijing(
  8. B, #data
  9. aiclient,
  10. qwclient,
  11. sfclient,
  12. dw):
  13. options=[]
  14. letters = "ABCDEFGHIJKLMN"
  15. for i in range(len(zhijing)):
  16. options.append("给定选项" + letters[i]+",内容为"+zhijing[i] )
  17. completion = aiclient.chat.completions.create(
  18. model="glm-4.5-air",
  19. #model="THUDM/GLM-Z1-9B-0414",
  20. #model="ernie-speed-128k",
  21. messages=[
  22. {"role": "system", "content": "You are a helpful assistant."},
  23. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请选择最合适的选项,并返回字母代号,例如,返回 A"},
  24. ],
  25. extra_body={"thinking": {"type": "disabled"}},
  26. #extra_body={"enable_thinking": True},
  27. #stream=True
  28. )
  29. json_string = completion.choices[0].message.content
  30. print(json_string)
  31. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  32. answer=[]
  33. if 'A' in json_string and len(zhijing) > 0:
  34. answer.append('A')
  35. if 'B' in json_string and len(zhijing) > 1:
  36. answer.append('B')
  37. if 'C' in json_string and len(zhijing) > 2:
  38. answer.append('C')
  39. if 'D' in json_string and len(zhijing) > 3:
  40. answer.append('D')
  41. if 'E' in json_string and len(zhijing) > 4:
  42. answer.append('E')
  43. if 'F' in json_string and len(zhijing) > 5:
  44. answer.append('F')
  45. if 'G' in json_string and len(zhijing) > 6:
  46. answer.append('G')
  47. return answer
  48. completion = sfclient.chat.completions.create(
  49. #model="glm-4.5-flash",
  50. model=simplemodel(),
  51. messages=xuanxiang(json_string),
  52. extra_body={"thinking": {"type": "disabled"}},
  53. #extra_body={"enable_thinking": False},
  54. )
  55. json_string = completion.choices[0].message.content
  56. print(json_string)
  57. answer=[]
  58. if 'A' in json_string and len(zhijing) > 0:
  59. answer.append('A')
  60. if 'B' in json_string and len(zhijing) > 1:
  61. answer.append('B')
  62. if 'C' in json_string and len(zhijing) > 2:
  63. answer.append('C')
  64. if 'D' in json_string and len(zhijing) > 3:
  65. answer.append('D')
  66. if 'E' in json_string and len(zhijing) > 4:
  67. answer.append('E')
  68. if 'F' in json_string and len(zhijing) > 5:
  69. answer.append('F')
  70. if 'G' in json_string and len(zhijing) > 6:
  71. answer.append('G')
  72. return answer
  73. def aifilter1(A, #options
  74. B, #data
  75. aiclient,
  76. qwclient,
  77. sfclient,
  78. dw):
  79. options=[]
  80. letters = "ABCDEFGHIJKLMN"
  81. for i in range(len(A)):
  82. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  83. completion = aiclient.chat.completions.create(
  84. model="glm-4.5-air",
  85. #model="THUDM/GLM-Z1-9B-0414",
  86. #model="ernie-speed-128k",
  87. messages=[
  88. {"role": "system", "content": "You are a helpful assistant."},
  89. {"role": "user", "content": " 特殊处理要求一:如果工作内容描述没有提及管道冲洗,则去掉所有管道冲洗的选项"},
  90. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  91. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  92. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果, 删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  93. ],
  94. extra_body={"thinking": {"type": "disabled"}},
  95. #extra_body={"enable_thinking": True},
  96. #stream=True
  97. )
  98. json_string = completion.choices[0].message.content
  99. print(json_string)
  100. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  101. answer=[]
  102. if 'A' in json_string and len(A) > 0:
  103. answer.append(A[0])
  104. if 'B' in json_string and len(A) > 1:
  105. answer.append(A[1])
  106. if 'C' in json_string and len(A) > 2:
  107. answer.append(A[2])
  108. if 'D' in json_string and len(A) > 3:
  109. answer.append(A[3])
  110. if 'E' in json_string and len(A) > 4:
  111. answer.append(A[4])
  112. if 'F' in json_string and len(A) > 5:
  113. answer.append(A[5])
  114. if 'G' in json_string and len(A) > 6:
  115. answer.append(A[6])
  116. if 'H' in json_string and len(A) > 7:
  117. answer.append(A[7])
  118. if 'I' in json_string and len(A) > 8:
  119. answer.append(A[8])
  120. if 'J' in json_string and len(A) > 9:
  121. answer.append(A[9])
  122. return answer
  123. completion = sfclient.chat.completions.create(
  124. #model="glm-4.5-flash",
  125. model=simplemodel(),
  126. messages=xuanxiang(json_string),
  127. extra_body={"thinking": {"type": "disabled"}},
  128. #extra_body={"enable_thinking": False},
  129. )
  130. json_string = completion.choices[0].message.content
  131. print(json_string)
  132. answer=[]
  133. if 'A' in json_string and len(A) > 0:
  134. answer.append(A[0])
  135. if 'B' in json_string and len(A) > 1:
  136. answer.append(A[1])
  137. if 'C' in json_string and len(A) > 2:
  138. answer.append(A[2])
  139. if 'D' in json_string and len(A) > 3:
  140. answer.append(A[3])
  141. if 'E' in json_string and len(A) > 4:
  142. answer.append(A[4])
  143. if 'F' in json_string and len(A) > 5:
  144. answer.append(A[5])
  145. if 'G' in json_string and len(A) > 6:
  146. answer.append(A[6])
  147. if 'H' in json_string and len(A) > 7:
  148. answer.append(A[7])
  149. if 'I' in json_string and len(A) > 8:
  150. answer.append(A[8])
  151. if 'J' in json_string and len(A) > 9:
  152. answer.append(A[9])
  153. return answer
  154. def postprocess0310(selected, data, aiclient, qwclient, sfclient, label_name, name_dw, candidates):
  155. prime = aifilter1(selected, data, aiclient, qwclient, sfclient, name_dw)
  156. return prime