postprocess0117.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import json
  2. with open("cuoshi_corpus.txt", "r") as f:
  3. content = f.read()
  4. pairs = content.split("\n")
  5. pair_tuple = []
  6. i = 0
  7. while i < len(pairs):
  8. pair_tuple.append([pairs[i], pairs[i+1]])
  9. i = i + 2
  10. def aifilter(A, #options
  11. B, #data
  12. aiclient):
  13. options=[]
  14. letters = "ABCDEFGHIJKLMN"
  15. for i in range(len(A)):
  16. options.append("给定选项" + letters[i]+",内容为"+A[i])
  17. completion = aiclient.chat.completions.create(
  18. model="glm-4.5-flash",
  19. messages=[
  20. {"role": "system", "content": "You are a helpful assistant."},
  21. {"role": "user", "content": " 背景知识:如果工作内容是土石方工程、土方工程等,那么不要能选用塔式起重机"},
  22. {"role": "user", "content": "问题描述: 给定一段工作内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + "," + ",".join(options) + "。请做出筛选,并返回结果。例如,如果处理完后剩余A,B,C三个选项,请返回[A,B,C]"},
  23. ],
  24. extra_body={"thinking": {"type": "disabled"}},
  25. )
  26. json_string = completion.choices[0].message.content
  27. print(json_string)
  28. completion = aiclient.chat.completions.create(
  29. model="glm-4.5-flash",
  30. messages=[
  31. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  32. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于[A,B,C]的数组作为答案,请将该最终答案输出"},
  33. ],
  34. extra_body={"thinking": {"type": "disabled"}},
  35. )
  36. json_string = completion.choices[0].message.content
  37. print(json_string)
  38. answer=[]
  39. if 'A' in json_string:
  40. answer.append(A[0])
  41. if 'B' in json_string:
  42. answer.append(A[1])
  43. if 'C' in json_string:
  44. answer.append(A[2])
  45. if 'D' in json_string:
  46. answer.append(A[3])
  47. if 'E' in json_string:
  48. answer.append(A[4])
  49. if 'F' in json_string:
  50. answer.append(A[5])
  51. if 'G' in json_string:
  52. answer.append(A[6])
  53. if 'H' in json_string:
  54. answer.append(A[7])
  55. return answer
  56. def postprocess0117(selected, data, aiclient):
  57. correct=[]
  58. for entry in selected:
  59. correct.append(entry)
  60. for item in pair_tuple:
  61. if entry in item:
  62. correct = correct + item
  63. correct = list(set(correct))
  64. return aifilter(correct, data, aiclient)