postprocess0115.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import time
  2. from fallback import fallback
  3. from config import simplemodel
  4. from template import xuanxiang
  5. import json
  6. with open('zhaoping_rule', 'r') as f:
  7. content = f.read()
  8. import json
  9. obj=json.loads(content)
  10. with open('name_label', 'r') as f:
  11. content = f.read()
  12. import json
  13. name_label=json.loads(content)
  14. baohuceng = ['10-74', '10-75', '10-77', '10-78', '10-80', '10-81', '10-83', '10-84', '10-86', '10-87', '10-90']
  15. from fallback import fallback
  16. def aifilter1(A, #options
  17. B, #data
  18. aiclient,
  19. qwclient,
  20. sfclient,
  21. dw):
  22. options=[]
  23. letters = "ABCDEFGHIJKLMN"
  24. for i in range(len(A)):
  25. options.append("给定选项" + letters[i]+",内容为"+A[i] )
  26. completion = aiclient.chat.completions.create(
  27. model="glm-z1-flash",
  28. #model="THUDM/GLM-Z1-9B-0414",
  29. #model="ernie-speed-128k",
  30. messages=[
  31. {"role": "system", "content": "You are a helpful assistant."},
  32. {"role": "user", "content": " 特殊处理要求一:如果工作内容没有提及幕墙,则去掉所有幕墙选项"},
  33. {"role": "user", "content": " 重要提示:选项指的是给定的A、B、C之类的选项,不是指的工作内容中的可能的1、2、3这样罗列的特征"},
  34. {"role": "user", "content": " 重要提示:除特殊处理要求提及的内容外,不需考虑选项内容与工作内容是否符合,只需要根据特殊处理要求做出处理"},
  35. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请根据处理要求做出处理,并返回结果, 删除选项必须对应到明确的特殊处理要求,不要擅自删除选项。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  36. ],
  37. extra_body={"thinking": {"type": "disabled"}},
  38. #extra_body={"enable_thinking": True},
  39. #stream=True
  40. )
  41. #done_thinking = False
  42. #json_string=""
  43. #thinking_json_string=""
  44. #for chunk in completion:
  45. # thinking_chunk = chunk.choices[0].delta.reasoning_content
  46. # answer_chunk = chunk.choices[0].delta.content
  47. # if thinking_chunk != '':
  48. # thinking_json_string = thinking_json_string + thinking_chunk
  49. # elif answer_chunk != '':
  50. # if not done_thinking:
  51. # done_thinking = True
  52. # json_string = json_string + answer_chunk
  53. json_string = completion.choices[0].message.content
  54. #print(completion.choices[0].message.reasoning_content)
  55. print(json_string)
  56. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  57. answer=[]
  58. if 'A' in json_string and len(A) > 0:
  59. answer.append(A[0])
  60. if 'B' in json_string and len(A) > 1:
  61. answer.append(A[1])
  62. if 'C' in json_string and len(A) > 2:
  63. answer.append(A[2])
  64. if 'D' in json_string and len(A) > 3:
  65. answer.append(A[3])
  66. if 'E' in json_string and len(A) > 4:
  67. answer.append(A[4])
  68. if 'F' in json_string and len(A) > 5:
  69. answer.append(A[5])
  70. if 'G' in json_string and len(A) > 6:
  71. answer.append(A[6])
  72. if 'H' in json_string and len(A) > 7:
  73. answer.append(A[7])
  74. if 'I' in json_string and len(A) > 8:
  75. answer.append(A[8])
  76. if 'J' in json_string and len(A) > 9:
  77. answer.append(A[9])
  78. return answer
  79. completion = sfclient.chat.completions.create(
  80. #model="glm-4.5-flash",
  81. model=simplemodel(),
  82. messages=xuanxiang(json_string),
  83. extra_body={"thinking": {"type": "disabled"}},
  84. #extra_body={"enable_thinking": False},
  85. )
  86. json_string = completion.choices[0].message.content
  87. print(json_string)
  88. answer=[]
  89. if 'A' in json_string and len(A) > 0:
  90. answer.append(A[0])
  91. if 'B' in json_string and len(A) > 1:
  92. answer.append(A[1])
  93. if 'C' in json_string and len(A) > 2:
  94. answer.append(A[2])
  95. if 'D' in json_string and len(A) > 3:
  96. answer.append(A[3])
  97. if 'E' in json_string and len(A) > 4:
  98. answer.append(A[4])
  99. if 'F' in json_string and len(A) > 5:
  100. answer.append(A[5])
  101. if 'G' in json_string and len(A) > 6:
  102. answer.append(A[6])
  103. if 'H' in json_string and len(A) > 7:
  104. answer.append(A[7])
  105. if 'I' in json_string and len(A) > 8:
  106. answer.append(A[8])
  107. if 'J' in json_string and len(A) > 9:
  108. answer.append(A[9])
  109. return answer
  110. def postprocess0115(selected, data, aiclient, qwclient, sfclient, label_name, name_dw, candidates):
  111. prime = aifilter1(selected, data, aiclient, qwclient, sfclient, name_dw)
  112. return prime