huansuan0106.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import re
  2. with open('gangjiegouhuansuan','r') as f:
  3. content = f.read()
  4. import json
  5. obj = json.loads(content)
  6. options=[]
  7. for i in range(len(obj['mc'])):
  8. options.append('给定选项A'+str(i)+', 内容为'+obj['mc'][i])
  9. options = ','.join(options)
  10. def callzaihuansuan0106_0(bianma, label, A,B,C, aiclient, qwclient):##C->tz
  11. completion = aiclient.chat.completions.create(
  12. model="glm-4.5-flash",
  13. messages=[
  14. {"role": "system", "content": "You are a helpful assistant."},
  15. {"role": "user", "content": "问题描述: 给定一段工作内容描述,内容为" + C + "," + options + ",请选出最匹配工作内容的选项并输出。例如如果你觉得A11选项最匹配,请输出A11"},
  16. ],
  17. extra_body={"thinking": {"type": "disabled"}},
  18. )
  19. json_string = completion.choices[0].message.content
  20. print(json_string)
  21. if len(json_string) < 4:
  22. return json_string
  23. completion = aiclient.chat.completions.create(
  24. model="glm-4.5-flash",
  25. messages=[
  26. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  27. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于A10的表达式作为结果,请将该最终结果输出"},
  28. ],
  29. extra_body={"thinking": {"type": "disabled"}},
  30. )
  31. json_string = completion.choices[0].message.content
  32. print(json_string)
  33. lines = json_string.split('\n')
  34. lines = [x for x in lines if ':' in x]
  35. line = lines[0].split(':')[1]
  36. line = line.replace('\'', '')
  37. line = line.replace('\"', '')
  38. matched_letters = re.findall(r'[a-zA-Z0-9]', line)
  39. return ''.join(matched_letters)
  40. def callzaihuansuan0106_1(bianma, label, A,B,C, aiclient, qwclient):##C->tz
  41. t = callzaihuansuan0106_0(bianma, label, A,B,C, aiclient, qwclient)
  42. t=t.replace('A', '')
  43. t = int(t)
  44. t = obj['alpha'][t]
  45. return "{" + "\n" + "answer: A=" + str(t) + "*B\n}"
  46. def callzaihuansuan0106_2(bianma, label, A,B,C, aiclient, qwclient):##C->tz
  47. t = callzaihuansuan0106_0(bianma, label, A,B,C, aiclient, qwclient)
  48. t=t.replace('A', '')
  49. t = int(t)
  50. t = obj['alpha'][t]/10
  51. return "{" + "\n" + "answer: A=" + str(t) + "*B\n}"
  52. def callzaihuansuan0106_3(bianma, label, A,B,C, aiclient, qwclient):##C->tz
  53. t = callzaihuansuan0106_0(bianma, label, A,B,C, aiclient, qwclient)
  54. t=t.replace('A', '')
  55. t = int(t)
  56. t = obj['alpha'][t]/100
  57. return "{" + "\n" + "answer: A=" + str(t) + "*B\n}"