postprocess0104.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import json
  2. def aifilter(A, #options
  3. B, #data
  4. aiclient):
  5. options=[]
  6. letters = "ABCDEFGHIJKLMN"
  7. for i in range(len(A)):
  8. options.append("给定选项" + letters[i]+",内容为"+A[i])
  9. completion = aiclient.chat.completions.create(
  10. model="glm-4.5-flash",
  11. messages=[
  12. {"role": "system", "content": "You are a helpful assistant."},
  13. {"role": "user", "content": " 处理要求:如果工作内容中没有明确提出砌贴砖,则去除选项中的砌贴砖选项"},
  14. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + "," + ",".join(options) + "。请根据处理要求做出处理,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  15. ],
  16. extra_body={"thinking": {"type": "disabled"}},
  17. )
  18. json_string = completion.choices[0].message.content
  19. print(json_string)
  20. completion = aiclient.chat.completions.create(
  21. model="glm-4.5-flash",
  22. messages=[
  23. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  24. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B,C]的数组作为结果,请将该最终结果输出"},
  25. ],
  26. extra_body={"thinking": {"type": "disabled"}},
  27. )
  28. json_string = completion.choices[0].message.content
  29. print(json_string)
  30. answer=[]
  31. if 'A' in json_string:
  32. answer.append(A[0])
  33. if 'B' in json_string:
  34. answer.append(A[1])
  35. if 'C' in json_string:
  36. answer.append(A[2])
  37. if 'D' in json_string:
  38. answer.append(A[3])
  39. if 'E' in json_string:
  40. answer.append(A[4])
  41. if 'F' in json_string:
  42. answer.append(A[5])
  43. if 'G' in json_string:
  44. answer.append(A[6])
  45. if 'H' in json_string:
  46. answer.append(A[7])
  47. return answer
  48. def postprocess0104(selected, data, aiclient):
  49. return aifilter(selected, data, aiclient)