feiyong.py 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import time
  2. from fallback import fallback
  3. from config import simplemodel
  4. from template import xuanxiang
  5. from fallback import fallback
  6. chaogao9=['5m以上到8m以内', '8-12m', '12-16m', '16-20m']
  7. chaogao10=['3.6m以上到8m以内', '8-12m', '12-16m', '16-20m']
  8. chaogao11=['6到20m以内', '20-30m', '30-40m', '40-50m', '50-60m', '60-70m', '70-80m','80m以上']
  9. def select_chaogao_11(
  10. B, #data
  11. aiclient,
  12. qwclient,
  13. sfclient
  14. ):
  15. options=[]
  16. letters = "ABCDEFGHIJKLMN"
  17. for i in range(len(chaogao11)):
  18. options.append("给定选项" + letters[i]+",内容为"+chaogao11[i] )
  19. completion = aiclient.chat.completions.create(
  20. model="glm-4.5-air",
  21. #model="THUDM/GLM-Z1-9B-0414",
  22. #model="ernie-speed-128k",
  23. messages=[
  24. {"role": "system", "content": "You are a helpful assistant."},
  25. {"role": "user", "content": "超高指的是操作物高度距离楼地面6m以上的工程."},
  26. {"role": "user", "content": "问题描述: 给定一段含有超高工作的内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请选择最合适的选项,并返回字母代号,例如,返回 A。如果内容中没有明确高度,请返回A"},
  27. ],
  28. extra_body={"thinking": {"type": "disabled"}},
  29. #extra_body={"enable_thinking": True},
  30. #stream=True
  31. )
  32. json_string = completion.choices[0].message.content
  33. print(json_string)
  34. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  35. answer=[]
  36. if 'A' in json_string and len(chaogao11) > 0:
  37. answer.append('A')
  38. if 'B' in json_string and len(chaogao11) > 1:
  39. answer.append('B')
  40. if 'C' in json_string and len(chaogao11) > 2:
  41. answer.append('C')
  42. if 'D' in json_string and len(chaogao11) > 3:
  43. answer.append('D')
  44. if 'E' in json_string and len(chaogao11) > 4:
  45. answer.append('E')
  46. if 'F' in json_string and len(chaogao11) > 5:
  47. answer.append('F')
  48. if 'G' in json_string and len(chaogao11) > 6:
  49. answer.append('G')
  50. if 'H' in json_string and len(chaogao11) > 7:
  51. answer.append('H')
  52. return answer
  53. completion = sfclient.chat.completions.create(
  54. #model="glm-4.5-flash",
  55. model=simplemodel(),
  56. messages=xuanxiang(json_string),
  57. extra_body={"thinking": {"type": "disabled"}},
  58. #extra_body={"enable_thinking": False},
  59. )
  60. json_string = completion.choices[0].message.content
  61. print(json_string)
  62. answer=[]
  63. if 'A' in json_string and len(chaogao11) > 0:
  64. answer.append('A')
  65. if 'B' in json_string and len(chaogao11) > 1:
  66. answer.append('B')
  67. if 'C' in json_string and len(chaogao11) > 2:
  68. answer.append('C')
  69. if 'D' in json_string and len(chaogao11) > 3:
  70. answer.append('D')
  71. if 'E' in json_string and len(chaogao11) > 4:
  72. answer.append('E')
  73. if 'F' in json_string and len(chaogao11) > 5:
  74. answer.append('F')
  75. if 'G' in json_string and len(chaogao11) > 6:
  76. answer.append('G')
  77. if 'H' in json_string and len(chaogao11) > 7:
  78. answer.append('H')
  79. return answer
  80. def select_chaogao_10(
  81. B, #data
  82. aiclient,
  83. qwclient,
  84. sfclient
  85. ):
  86. options=[]
  87. letters = "ABCDEFGHIJKLMN"
  88. for i in range(len(chaogao10)):
  89. options.append("给定选项" + letters[i]+",内容为"+chaogao10[i] )
  90. completion = aiclient.chat.completions.create(
  91. model="glm-4.5-air",
  92. #model="THUDM/GLM-Z1-9B-0414",
  93. #model="ernie-speed-128k",
  94. messages=[
  95. {"role": "system", "content": "You are a helpful assistant."},
  96. {"role": "user", "content": "超高指的是操作物高度距离楼地面3.6m以上的工程."},
  97. {"role": "user", "content": "问题描述: 给定一段含有超高工作的内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请选择最合适的选项,并返回字母代号,例如,返回 A。如果内容中没有明确高度,请返回A"},
  98. ],
  99. extra_body={"thinking": {"type": "disabled"}},
  100. #extra_body={"enable_thinking": True},
  101. #stream=True
  102. )
  103. json_string = completion.choices[0].message.content
  104. print(json_string)
  105. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  106. answer=[]
  107. if 'A' in json_string and len(chaogao10) > 0:
  108. answer.append('A')
  109. if 'B' in json_string and len(chaogao10) > 1:
  110. answer.append('B')
  111. if 'C' in json_string and len(chaogao10) > 2:
  112. answer.append('C')
  113. if 'D' in json_string and len(chaogao10) > 3:
  114. answer.append('D')
  115. return answer
  116. completion = sfclient.chat.completions.create(
  117. #model="glm-4.5-flash",
  118. model=simplemodel(),
  119. messages=xuanxiang(json_string),
  120. extra_body={"thinking": {"type": "disabled"}},
  121. #extra_body={"enable_thinking": False},
  122. )
  123. json_string = completion.choices[0].message.content
  124. print(json_string)
  125. answer=[]
  126. if 'A' in json_string and len(chaogao10) > 0:
  127. answer.append('A')
  128. if 'B' in json_string and len(chaogao10) > 1:
  129. answer.append('B')
  130. if 'C' in json_string and len(chaogao10) > 2:
  131. answer.append('C')
  132. if 'D' in json_string and len(chaogao10) > 3:
  133. answer.append('D')
  134. return answer
  135. def select_chaogao_9(
  136. B, #data
  137. aiclient,
  138. qwclient,
  139. sfclient
  140. ):
  141. options=[]
  142. letters = "ABCDEFGHIJKLMN"
  143. for i in range(len(chaogao9)):
  144. options.append("给定选项" + letters[i]+",内容为"+chaogao9[i] )
  145. completion = aiclient.chat.completions.create(
  146. model="glm-4.5-air",
  147. #model="THUDM/GLM-Z1-9B-0414",
  148. #model="ernie-speed-128k",
  149. messages=[
  150. {"role": "system", "content": "You are a helpful assistant."},
  151. {"role": "user", "content": "超高指的是操作物高度距离楼地面5m以上的工程."},
  152. {"role": "user", "content": "问题描述: 给定一段含有超高工作的内容: " + B['label'] + " " + B['mc'] + " " + B['tz'] + ",".join(options) + "。请选择最合适的选项,并返回字母代号,例如,返回 A。如果内容中没有明确高度,请返回A"},
  153. ],
  154. extra_body={"thinking": {"type": "disabled"}},
  155. #extra_body={"enable_thinking": True},
  156. #stream=True
  157. )
  158. json_string = completion.choices[0].message.content
  159. print(json_string)
  160. if len([x for x in json_string if x != ',' and x != '[' and x != ']' and x != ' ' and (x < 'A' or x > 'M')]) < 5:
  161. answer=[]
  162. if 'A' in json_string and len(chaogao9) > 0:
  163. answer.append('A')
  164. if 'B' in json_string and len(chaogao9) > 1:
  165. answer.append('B')
  166. if 'C' in json_string and len(chaogao9) > 2:
  167. answer.append('C')
  168. if 'D' in json_string and len(chaogao9) > 3:
  169. answer.append('D')
  170. return answer
  171. completion = sfclient.chat.completions.create(
  172. #model="glm-4.5-flash",
  173. model=simplemodel(),
  174. messages=xuanxiang(json_string),
  175. extra_body={"thinking": {"type": "disabled"}},
  176. #extra_body={"enable_thinking": False},
  177. )
  178. json_string = completion.choices[0].message.content
  179. print(json_string)
  180. answer=[]
  181. if 'A' in json_string and len(chaogao9) > 0:
  182. answer.append('A')
  183. if 'B' in json_string and len(chaogao9) > 1:
  184. answer.append('B')
  185. if 'C' in json_string and len(chaogao9) > 2:
  186. answer.append('C')
  187. if 'D' in json_string and len(chaogao9) > 3:
  188. answer.append('D')
  189. return answer
  190. def feiyong_chaogao(data, selected, aiclient, qwclient, sfclient):
  191. a = [x for x in selected if x.startswith('4-')]
  192. if len(a) > 0:
  193. return ['4-F2!第四册']
  194. a = [x for x in selected if x.startswith('9-')]
  195. if len(a) > 0:
  196. t = select_chaogao_9(data, aiclient, qwclient, sfclient)
  197. if 'A' in t:
  198. return ['9-F2!第九册5m以上到8m以内']
  199. elif 'B' in t:
  200. return ['9-F2!第九册8-12m']
  201. elif 'C' in t:
  202. return ['9-F2!第九册12-16m']
  203. elif 'D' in t:
  204. return ['9-F2!第九册16-20m']
  205. a = [x for x in selected if x.startswith('10-')]
  206. if len(a) > 0:
  207. t = select_chaogao_10(data, aiclient, qwclient, sfclient)
  208. if 'A' in t:
  209. return ['10-F2!第十册3.6-8m以内']
  210. elif 'B' in t:
  211. return ['10-F2!第十册8-12m']
  212. elif 'C' in t:
  213. return ['10-F2!第十册12-16m']
  214. elif 'D' in t:
  215. return ['10-F2!第十册16-20m']
  216. a = [x for x in selected if x.startswith('11-')]
  217. if len(a) > 0:
  218. t = select_chaogao_11(data, aiclient, qwclient, sfclient)
  219. if 'A' in t:
  220. return ['11-F2!第十一册6-20m']
  221. elif 'B' in t:
  222. return ['11-F2!第十一册20-30m']
  223. elif 'C' in t:
  224. return ['11-F2!第十一册30-40m']
  225. elif 'D' in t:
  226. return ['11-F2!第十一册40-50m']
  227. elif 'E' in t:
  228. return ['11-F2!第十一册50-60m']
  229. elif 'F' in t:
  230. return ['11-F2!第十一册60-70m']
  231. elif 'G' in t:
  232. return ['11-F2!第十一册70-80m']
  233. elif 'H' in t:
  234. return ['11-F2!第十一册80m以上']
  235. return []