buchong.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. import json
  2. def only(tz, aiclient):
  3. completion = aiclient.chat.completions.create(
  4. model="glm-4.5-air",
  5. messages=[
  6. {"role": "system", "content": "You are a helpful assistant."},
  7. {"role": "user", "content": "给定一段文字,其中描述了一项安装工作的工作内容。这段文字可能会注明,该项工作不用考虑安装的设备本身的费用,只需考虑安装费。这段文字也可能不做任何注明。"+'''
  8. 例如,给定文字如下:
  9. 1、名称:高真空焊烟净化机组控制箱(箱随设备提供计安装费)
  10. 这段文字注明了仅计安装费
  11. 再例如,给定文字如下:
  12. 1、名称:母线槽始端箱(超高)
  13. 2、型号:15C
  14. 3、容量(A):1800A
  15. 这段文字没有注明
  16. ''' + '现在给定文字如下:'+tz+"\n请判断是否注明了仅计安装费,请直接回答是或者否"},
  17. ],
  18. extra_body={"thinking": {"type": "disabled"}},
  19. )
  20. mc = completion.choices[0].message.content
  21. if '是' in mc:
  22. return True
  23. return False
  24. def need_buchong(debm, tz, aiclient):
  25. if debm == '4-266' or debm == '4-267' or debm =='4-268' or debm=='4-269' or debm=='4-270':
  26. return not only(tz, aiclient)
  27. if debm == '4-265':
  28. return not only(tz, aiclient)
  29. if debm == '4-203' or debm =='4-204' or debm=='4-205' or debm=='4-206':
  30. return not only(tz, aiclient)
  31. if debm == '4-918' or debm =='4-919':
  32. return not only(tz, aiclient)
  33. if debm in ['1-'+str(x) for x in range(684,702)]:
  34. return not only(tz, aiclient)
  35. if debm in ['9-'+str(x) for x in range(153,163)]:
  36. return not only(tz, aiclient)
  37. if debm in ['9-'+str(x) for x in range(200,206)]:
  38. return not only(tz, aiclient)
  39. if debm in ['6-'+str(x) for x in range(23,36)]:
  40. return not only(tz, aiclient)
  41. if debm in ['6-'+str(x) for x in range(64,92)]:
  42. return not only(tz, aiclient)
  43. if debm in ['7-'+str(x) for x in range(298,324)]:
  44. return not only(tz, aiclient)
  45. if debm in ['7-'+str(x) for x in range(378,420)]:
  46. return not only(tz, aiclient)
  47. return False
  48. def buchong_cailiao(aiclient, debm, tz):
  49. if debm in ['7-'+str(x) for x in range(378,420)]:
  50. bh = '710000F'
  51. completion = aiclient.chat.completions.create(
  52. model="glm-4.5-air",
  53. messages=[
  54. {"role": "system", "content": "You are a helpful assistant."},
  55. {"role": "user", "content": "给定一段文字,请抽取出风口的关键信息并返回。"+'''
  56. 例如,给定文字如下:
  57. 1、名称:防雨百叶风口
  58. 2、规格:400*400
  59. 你应该返回 "防雨百叶风口400*400"
  60. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  61. ],
  62. extra_body={"thinking": {"type": "disabled"}},
  63. )
  64. mc = completion.choices[0].message.content
  65. print(mc)
  66. if debm in ['7-'+str(x) for x in range(298,324)]:
  67. bh = '710000F'
  68. completion = aiclient.chat.completions.create(
  69. model="glm-4.5-air",
  70. messages=[
  71. {"role": "system", "content": "You are a helpful assistant."},
  72. {"role": "user", "content": "给定一段文字,请抽取出阀门的关键信息并返回。"+'''
  73. 例如,给定文字如下:
  74. 1、名称:对开多叶调节阀
  75. 2、规格:320*320
  76. 你应该返回 "对开多叶调节阀320*320"
  77. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  78. ],
  79. extra_body={"thinking": {"type": "disabled"}},
  80. )
  81. mc = completion.choices[0].message.content
  82. print(mc)
  83. if debm in ['6-'+str(x) for x in range(64,92)]:
  84. bh = '610000F'
  85. completion = aiclient.chat.completions.create(
  86. model="glm-4.5-air",
  87. messages=[
  88. {"role": "system", "content": "You are a helpful assistant."},
  89. {"role": "user", "content": "给定一段文字,请抽取出流量表的关键信息并返回。"+'''
  90. 例如,给定文字如下:
  91. 1、名称:热式动力气体质量流量计
  92. 2、型号:50-5000Nm,141/h,PN1.6MPa
  93. 你应该返回 "热式动力气体质量流量计50-5000Nm,141/h,PN1.6MPa"
  94. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  95. ],
  96. extra_body={"thinking": {"type": "disabled"}},
  97. )
  98. mc = completion.choices[0].message.content
  99. print(mc)
  100. if debm in ['6-'+str(x) for x in range(23,36)]:
  101. bh = '610000F'
  102. completion = aiclient.chat.completions.create(
  103. model="glm-4.5-air",
  104. messages=[
  105. {"role": "system", "content": "You are a helpful assistant."},
  106. {"role": "user", "content": "给定一段文字,请抽取出压力表的关键信息并返回。"+'''
  107. 例如,给定文字如下:
  108. 1、名称:压力表
  109. 2、型号:含表阀及弯管
  110. 3、规格:Y-100型,0-1.6MPa
  111. 你应该返回 "压力表Y-100型 含表阀及弯管"
  112. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  113. ],
  114. extra_body={"thinking": {"type": "disabled"}},
  115. )
  116. mc = completion.choices[0].message.content
  117. print(mc)
  118. if debm in ['9-'+str(x) for x in range(200,206)]:
  119. bh = '910000F'
  120. completion = aiclient.chat.completions.create(
  121. model="glm-4.5-air",
  122. messages=[
  123. {"role": "system", "content": "You are a helpful assistant."},
  124. {"role": "user", "content": "给定一段文字,请抽取出显示器、报警器、控制器的关键信息并返回。"+'''
  125. 例如,给定文字如下:
  126. 名称: 燃气声光报警器
  127. 你应该返回 "燃气声光报警器"
  128. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  129. ],
  130. extra_body={"thinking": {"type": "disabled"}},
  131. )
  132. mc = completion.choices[0].message.content
  133. print(mc)
  134. if debm in ['9-'+str(x) for x in range(153,163)]:
  135. bh = '910000F'
  136. completion = aiclient.chat.completions.create(
  137. model="glm-4.5-air",
  138. messages=[
  139. {"role": "system", "content": "You are a helpful assistant."},
  140. {"role": "user", "content": "给定一段文字,请抽取出探测器的关键信息并返回。"+'''
  141. 例如,给定文字如下:
  142. 名称:可燃气体探测器
  143. 你应该返回 "可燃气体探测器"
  144. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  145. ],
  146. extra_body={"thinking": {"type": "disabled"}},
  147. )
  148. mc = completion.choices[0].message.content
  149. print(mc)
  150. if debm in ['1-'+str(x) for x in range(684,702)]:
  151. bh = '110000F'
  152. completion = aiclient.chat.completions.create(
  153. model="glm-4.5-air",
  154. messages=[
  155. {"role": "system", "content": "You are a helpful assistant."},
  156. {"role": "user", "content": "给定一段文字,请抽取出轴流通风机的关键信息并返回。"+'''
  157. 例如,给定文字如下:
  158. 名称:侧墙轴流风机
  159. 你应该返回 "侧墙轴流风机"
  160. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  161. ],
  162. extra_body={"thinking": {"type": "disabled"}},
  163. )
  164. mc = completion.choices[0].message.content
  165. print(mc)
  166. if debm.startswith('4-918') or debm.startswith('4-919'):
  167. bh = '410000F'
  168. completion = aiclient.chat.completions.create(
  169. model="glm-4.5-air",
  170. messages=[
  171. {"role": "system", "content": "You are a helpful assistant."},
  172. {"role": "user", "content": "给定一段文字,请抽取出避雷网的关键信息并返回。"+'''
  173. 例如,给定文字如下:
  174. 1、名称:防雷网
  175. 2、材质:镀锌扁钢
  176. 3、规格:25*4
  177. 你应该返回 "镀锌扁钢 25*4"
  178. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  179. ],
  180. extra_body={"thinking": {"type": "disabled"}},
  181. )
  182. mc = completion.choices[0].message.content
  183. print(mc)
  184. if debm.startswith('4-203') or debm.startswith('4-204') or debm.startswith('4-205') or debm.startswith('4-206'):
  185. bh = '410000F'
  186. completion = aiclient.chat.completions.create(
  187. model="glm-4.5-air",
  188. messages=[
  189. {"role": "system", "content": "You are a helpful assistant."},
  190. {"role": "user", "content": "给定一段文字,请抽取出始端箱(分线箱)的关键信息(电流容量)并返回。"+'''
  191. 例如,给定文字如下:
  192. 1、名称:母线槽始端箱(超高)
  193. 2. 型号2D
  194. 3. 容量(A):800A
  195. 你应该返回 "母线槽始端箱800A"
  196. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  197. ],
  198. extra_body={"thinking": {"type": "disabled"}},
  199. )
  200. mc = completion.choices[0].message.content
  201. print(mc)
  202. if debm.startswith('4-265'):
  203. bh = '410000F'
  204. completion = aiclient.chat.completions.create(
  205. model="glm-4.5-air",
  206. messages=[
  207. {"role": "system", "content": "You are a helpful assistant."},
  208. {"role": "user", "content": "给定一段文字,请抽取出控制箱的关键信息并返回。"+'''
  209. 例如,给定文字如下:
  210. 1、名称:照明按钮控制箱
  211. 你应该返回 "照明按钮控制箱"
  212. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  213. ],
  214. extra_body={"thinking": {"type": "disabled"}},
  215. )
  216. mc = completion.choices[0].message.content
  217. print(mc)
  218. if debm.startswith('4-266') or debm.startswith('4-267') or debm.startswith('4-268') or debm.startswith('4-269') or debm.startswith('4-230'):
  219. bh = '410000F'
  220. completion = aiclient.chat.completions.create(
  221. model="glm-4.5-air",
  222. messages=[
  223. {"role": "system", "content": "You are a helpful assistant."},
  224. {"role": "user", "content": "给定一段文字,请抽取出配电箱的关键信息并返回。"+'''
  225. 例如,给定文字如下:
  226. 1、名称:配电箱
  227. 2、型号:L5A
  228. 3、规格:600*1500*400
  229. 4、基础形式、材质、规格:10#槽钢
  230. 5、安装方式:落地安装
  231. 6、电气元器件,模块按设计配置齐全
  232. 7、详见设计图纸,满足设计及规范要求
  233. 你应该返回 "配电箱L5A"
  234. 再例如,给定文字如下:
  235. 1、名称:消火栓泵配电柜XFX
  236. 2、型号:600*1500*400
  237. 4、基础形式、材质、规格:10#槽钢
  238. 5、安装方式:落地安装
  239. 6、电气元器件,模块按设计配置齐全
  240. 7、详见设计图纸,满足设计及规范要求
  241. 你应该返回 "消火栓泵配电柜XFX"
  242. 再例如,给定文字如下:
  243. 1、名称:配电箱C-AT
  244. 2、型号:非标,详见系统图
  245. 4、基础形式、材质、规格:10#槽钢
  246. 5、安装方式:落地安装
  247. 6、电气元器件,模块按设计配置齐全
  248. 7、详见设计图纸,满足设计及规范要求
  249. 你应该返回 "配电箱C-AT"
  250. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  251. ],
  252. extra_body={"thinking": {"type": "disabled"}},
  253. )
  254. mc = completion.choices[0].message.content
  255. print(mc)
  256. return {'CLBH': bh, 'CLMC': mc, 'JLDW': '台', 'YSJG': 0, 'SL': 1, 'HJ': 0}
  257. def tihuan(aiclient, old_name, tz):
  258. completion = aiclient.chat.completions.create(
  259. model="glm-4.5-air",
  260. messages=[
  261. {"role": "system", "content": "You are a helpful assistant."},
  262. {"role": "user", "content": "给定一段文字,再给定一个材料,请抽取出该材料的关键信息并返回。"+'''
  263. 例如,给定文字如下:
  264. 1、名称:密集型铜母线(超高)
  265. 2、型号:XL-M-63A/5P
  266. 3、容量(A):63A
  267. 4、含配套支架
  268. 给定材料为 “母线槽 每相400A以下”,
  269. 你应该返回 “密集型铜母线XL-M-63A/5P”
  270. 再例如,给定文字如下:
  271. 1、名称:接地母线
  272. 2、材质:镀锌扁钢
  273. 3、规格:-40*4
  274. 给定材料为 “接地母线”,
  275. 你应该返回 “镀锌扁钢 40*4”
  276. 再例如,给定文字如下:
  277. 1、名称:消防电源通讯管理机
  278. 2、型号:配DPD信号
  279. 3、安装方式:落地安装
  280. 给定材料为 “槽钢”,
  281. 因为文字没有提及槽钢,所以你原封不动返回材料名,这里你应该返回“槽钢”
  282. ''' + '现在给定文字如下:'+tz+"\n给定材料为 "+old_name+"\n请返回结果"},
  283. ],
  284. extra_body={"thinking": {"type": "disabled"}},
  285. )
  286. mc = completion.choices[0].message.content
  287. print(mc)
  288. return mc
  289. def buchong(aiclient, json_string, debm, tz):
  290. obj = json.loads(json_string)
  291. print(debm)
  292. if need_buchong(debm, tz, aiclient):
  293. obj['clde'].append(buchong_cailiao(aiclient, debm, tz))
  294. for entry in obj['clde']:
  295. if entry['CLBH'].startswith('CL'):
  296. entry['CLMC']=tihuan(aiclient, entry['CLMC'], tz)
  297. return json.dumps(obj, ensure_ascii=False)