buchong.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. return False
  44. def buchong_cailiao(aiclient, debm, tz):
  45. if debm in ['6-'+str(x) for x in range(64,92)]:
  46. bh = '610000F'
  47. completion = aiclient.chat.completions.create(
  48. model="glm-4.5-air",
  49. messages=[
  50. {"role": "system", "content": "You are a helpful assistant."},
  51. {"role": "user", "content": "给定一段文字,请抽取出流量表的关键信息并返回。"+'''
  52. 例如,给定文字如下:
  53. 1、名称:热式动力气体质量流量计
  54. 2、型号:50-5000Nm,141/h,PN1.6MPa
  55. 你应该返回 "热式动力气体质量流量计50-5000Nm,141/h,PN1.6MPa"
  56. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  57. ],
  58. extra_body={"thinking": {"type": "disabled"}},
  59. )
  60. mc = completion.choices[0].message.content
  61. print(mc)
  62. if debm in ['6-'+str(x) for x in range(23,36)]:
  63. bh = '610000F'
  64. completion = aiclient.chat.completions.create(
  65. model="glm-4.5-air",
  66. messages=[
  67. {"role": "system", "content": "You are a helpful assistant."},
  68. {"role": "user", "content": "给定一段文字,请抽取出压力表的关键信息并返回。"+'''
  69. 例如,给定文字如下:
  70. 1、名称:压力表
  71. 2、型号:含表阀及弯管
  72. 3、规格:Y-100型,0-1.6MPa
  73. 你应该返回 "压力表Y-100型 含表阀及弯管"
  74. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  75. ],
  76. extra_body={"thinking": {"type": "disabled"}},
  77. )
  78. mc = completion.choices[0].message.content
  79. print(mc)
  80. if debm in ['9-'+str(x) for x in range(200,206)]:
  81. bh = '910000F'
  82. completion = aiclient.chat.completions.create(
  83. model="glm-4.5-air",
  84. messages=[
  85. {"role": "system", "content": "You are a helpful assistant."},
  86. {"role": "user", "content": "给定一段文字,请抽取出显示器、报警器、控制器的关键信息并返回。"+'''
  87. 例如,给定文字如下:
  88. 名称: 燃气声光报警器
  89. 你应该返回 "燃气声光报警器"
  90. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  91. ],
  92. extra_body={"thinking": {"type": "disabled"}},
  93. )
  94. mc = completion.choices[0].message.content
  95. print(mc)
  96. if debm in ['9-'+str(x) for x in range(153,163)]:
  97. bh = '910000F'
  98. completion = aiclient.chat.completions.create(
  99. model="glm-4.5-air",
  100. messages=[
  101. {"role": "system", "content": "You are a helpful assistant."},
  102. {"role": "user", "content": "给定一段文字,请抽取出探测器的关键信息并返回。"+'''
  103. 例如,给定文字如下:
  104. 名称:可燃气体探测器
  105. 你应该返回 "可燃气体探测器"
  106. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  107. ],
  108. extra_body={"thinking": {"type": "disabled"}},
  109. )
  110. mc = completion.choices[0].message.content
  111. print(mc)
  112. if debm in ['1-'+str(x) for x in range(684,702)]:
  113. bh = '110000F'
  114. completion = aiclient.chat.completions.create(
  115. model="glm-4.5-air",
  116. messages=[
  117. {"role": "system", "content": "You are a helpful assistant."},
  118. {"role": "user", "content": "给定一段文字,请抽取出轴流通风机的关键信息并返回。"+'''
  119. 例如,给定文字如下:
  120. 名称:侧墙轴流风机
  121. 你应该返回 "侧墙轴流风机"
  122. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  123. ],
  124. extra_body={"thinking": {"type": "disabled"}},
  125. )
  126. mc = completion.choices[0].message.content
  127. print(mc)
  128. if debm.startswith('4-918') or debm.startswith('4-919'):
  129. bh = '410000F'
  130. completion = aiclient.chat.completions.create(
  131. model="glm-4.5-air",
  132. messages=[
  133. {"role": "system", "content": "You are a helpful assistant."},
  134. {"role": "user", "content": "给定一段文字,请抽取出避雷网的关键信息并返回。"+'''
  135. 例如,给定文字如下:
  136. 1、名称:防雷网
  137. 2、材质:镀锌扁钢
  138. 3、规格:25*4
  139. 你应该返回 "镀锌扁钢 25*4"
  140. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  141. ],
  142. extra_body={"thinking": {"type": "disabled"}},
  143. )
  144. mc = completion.choices[0].message.content
  145. print(mc)
  146. if debm.startswith('4-203') or debm.startswith('4-204') or debm.startswith('4-205') or debm.startswith('4-206'):
  147. bh = '410000F'
  148. completion = aiclient.chat.completions.create(
  149. model="glm-4.5-air",
  150. messages=[
  151. {"role": "system", "content": "You are a helpful assistant."},
  152. {"role": "user", "content": "给定一段文字,请抽取出始端箱(分线箱)的关键信息(电流容量)并返回。"+'''
  153. 例如,给定文字如下:
  154. 1、名称:母线槽始端箱(超高)
  155. 2. 型号2D
  156. 3. 容量(A):800A
  157. 你应该返回 "母线槽始端箱800A"
  158. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  159. ],
  160. extra_body={"thinking": {"type": "disabled"}},
  161. )
  162. mc = completion.choices[0].message.content
  163. print(mc)
  164. if debm.startswith('4-265'):
  165. bh = '410000F'
  166. completion = aiclient.chat.completions.create(
  167. model="glm-4.5-air",
  168. messages=[
  169. {"role": "system", "content": "You are a helpful assistant."},
  170. {"role": "user", "content": "给定一段文字,请抽取出控制箱的关键信息并返回。"+'''
  171. 例如,给定文字如下:
  172. 1、名称:照明按钮控制箱
  173. 你应该返回 "照明按钮控制箱"
  174. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  175. ],
  176. extra_body={"thinking": {"type": "disabled"}},
  177. )
  178. mc = completion.choices[0].message.content
  179. print(mc)
  180. 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'):
  181. bh = '410000F'
  182. completion = aiclient.chat.completions.create(
  183. model="glm-4.5-air",
  184. messages=[
  185. {"role": "system", "content": "You are a helpful assistant."},
  186. {"role": "user", "content": "给定一段文字,请抽取出配电箱的关键信息并返回。"+'''
  187. 例如,给定文字如下:
  188. 1、名称:配电箱
  189. 2、型号:L5A
  190. 3、规格:600*1500*400
  191. 4、基础形式、材质、规格:10#槽钢
  192. 5、安装方式:落地安装
  193. 6、电气元器件,模块按设计配置齐全
  194. 7、详见设计图纸,满足设计及规范要求
  195. 你应该返回 "配电箱L5A"
  196. 再例如,给定文字如下:
  197. 1、名称:消火栓泵配电柜XFX
  198. 2、型号:600*1500*400
  199. 4、基础形式、材质、规格:10#槽钢
  200. 5、安装方式:落地安装
  201. 6、电气元器件,模块按设计配置齐全
  202. 7、详见设计图纸,满足设计及规范要求
  203. 你应该返回 "消火栓泵配电柜XFX"
  204. 再例如,给定文字如下:
  205. 1、名称:配电箱C-AT
  206. 2、型号:非标,详见系统图
  207. 4、基础形式、材质、规格:10#槽钢
  208. 5、安装方式:落地安装
  209. 6、电气元器件,模块按设计配置齐全
  210. 7、详见设计图纸,满足设计及规范要求
  211. 你应该返回 "配电箱C-AT"
  212. ''' + '现在给定文字如下:'+tz+"\n请返回结果"},
  213. ],
  214. extra_body={"thinking": {"type": "disabled"}},
  215. )
  216. mc = completion.choices[0].message.content
  217. print(mc)
  218. return {'CLBH': bh, 'CLMC': mc, 'JLDW': '台', 'YSJG': 0, 'SL': 1, 'HJ': 0}
  219. def tihuan(aiclient, old_name, tz):
  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、型号:XL-M-63A/5P
  228. 3、容量(A):63A
  229. 4、含配套支架
  230. 给定材料为 “母线槽 每相400A以下”,
  231. 你应该返回 “密集型铜母线XL-M-63A/5P”
  232. 再例如,给定文字如下:
  233. 1、名称:接地母线
  234. 2、材质:镀锌扁钢
  235. 3、规格:-40*4
  236. 给定材料为 “接地母线”,
  237. 你应该返回 “镀锌扁钢 40*4”
  238. 再例如,给定文字如下:
  239. 1、名称:消防电源通讯管理机
  240. 2、型号:配DPD信号
  241. 3、安装方式:落地安装
  242. 给定材料为 “槽钢”,
  243. 因为文字没有提及槽钢,所以你原封不动返回材料名,这里你应该返回“槽钢”
  244. ''' + '现在给定文字如下:'+tz+"\n给定材料为 "+old_name+"\n请返回结果"},
  245. ],
  246. extra_body={"thinking": {"type": "disabled"}},
  247. )
  248. mc = completion.choices[0].message.content
  249. print(mc)
  250. return mc
  251. def buchong(aiclient, json_string, debm, tz):
  252. obj = json.loads(json_string)
  253. print(debm)
  254. if need_buchong(debm, tz, aiclient):
  255. obj['clde'].append(buchong_cailiao(aiclient, debm, tz))
  256. for entry in obj['clde']:
  257. if entry['CLBH'].startswith('CL'):
  258. entry['CLMC']=tihuan(aiclient, entry['CLMC'], tz)
  259. return json.dumps(obj, ensure_ascii=False)