huansuan0106.py 2.8 KB

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