extra.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import time
  2. from config import simplemodel
  3. from menchuangfallback import menchuangfallback
  4. example1='''
  5. 1、包水管 做法详见图纸设计及相关图集规范
  6. 2、5#镀锌角钢基架
  7. 3、水管外包吸音材料
  8. 4、水泥纤维板
  9. '''
  10. answer_1='''
  11. {'面层': '水泥纤维板'}
  12. '''
  13. example2='''
  14. 1、一层大厅消火栓处,做法详见图纸设计及相关图集规范
  15. 2、石膏板、阻燃基层板、40*20*3镀锌方通龙骨、金属转轴等
  16. '''
  17. answer_2='''
  18. {'面层': '石膏板'}
  19. '''
  20. example3='''
  21. 1、不锈钢饰面 做法详见图纸设计及相关图集规范
  22. 2、1.5mm厚不锈钢面层
  23. 3、阻燃板基层,木龙骨找平阻燃处理
  24. '''
  25. answer_3='''
  26. {'面层': '1.5mm厚不锈钢面层'}
  27. '''
  28. def extra(
  29. data, #data
  30. aiclient,
  31. qwclient,
  32. sfclient,
  33. menchuang_collection,
  34. model,
  35. qita_collection,
  36. ):
  37. if '高强螺栓' in data['mc']:
  38. return '高强螺栓'
  39. if data['bianma'].startswith("0108"):
  40. sentence=["特征描述:" + data['mc'] + "\n" + data['tz']]
  41. embeddings = model.encode(sentence)
  42. result = menchuang_collection.query(query_embeddings=embeddings, n_results=10)
  43. print(result['documents'][0])
  44. l = len([x for x in result['distances'][0] if x < 0.5])
  45. if l < 2:
  46. l = 2
  47. completion = aiclient.chat.completions.create(
  48. model="glm-4.5-flash",
  49. messages=[
  50. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  51. {"role": "user", "content": "特征描述往往比较具体,工作内容是对特征描述的主要关键的总结提炼。以下是一些特征描述以及对应的提炼的工作内容的例子。" + '\n\n'.join(result['documents'][0][:l]) + "给定一段特征描述,内容为" + data['mc'] +data['tz'] + "。请参照示例,给出提炼的工作内容. 注意,不需要输出特征描述,仅输出工作内容"},
  52. ],
  53. extra_body={"thinking": {"type": "disabled"}},
  54. )
  55. json_string = completion.choices[0].message.content
  56. print(json_string)
  57. answers = json_string.split("\n")
  58. answers = [x for x in answers if ':' in x ]
  59. answer2 = answers[0].split(":")[1].replace(" ", "")
  60. return answer2
  61. if data['bianma'].startswith("0115"):
  62. sentence=["特征描述:" + data['mc'] + "\n" + data['tz']]
  63. embeddings = model.encode(sentence)
  64. result = qita_collection.query(query_embeddings=embeddings, n_results=10)
  65. print(result['documents'][0])
  66. l = len([x for x in result['distances'][0] if x < 0.5])
  67. if l < 2:
  68. l = 2
  69. completion = aiclient.chat.completions.create(
  70. model="glm-4.5-flash",
  71. messages=[
  72. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  73. {"role": "user", "content": "特征描述往往比较具体,工作内容是对特征描述的主要关键的总结提炼。以下是一些特征描述以及对应的提炼的工作内容的例子。" + '\n\n'.join(result['documents'][0][:l]) + "给定一段特征描述,内容为" + data['mc'] +data['tz'] + "。请参照示例,给出提炼的工作内容(提炼的工作内容中不得出现类似详见图纸、图集的表述). 注意,不需要输出特征描述,仅输出工作内容"},
  74. ],
  75. extra_body={"thinking": {"type": "disabled"}},
  76. )
  77. json_string = completion.choices[0].message.content
  78. print(json_string)
  79. answers = json_string.split("\n")
  80. answers = [x for x in answers if ':' in x ]
  81. answer2 = answers[0].split(":")[1].replace(" ", "")
  82. return answer2
  83. if data['bianma'].startswith("011207") or data['bianma'].startswith('011208'):
  84. completion = aiclient.chat.completions.create(
  85. model="glm-4.5-air",
  86. messages=[
  87. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  88. {"role": "user", "content": "墙柱面装饰板工程往往由多道工序组成,包括底层龙骨,附着于龙骨上的基层板、吸音棉、阻燃板等,以及作为饰面的面层板。现在要求你从给定的工作内容描述中抽取出面层的描述。举个例子,给定工作内容:"+example1+"\n你应该返回:"+answer_1+"\n再举个例子,给定工作内容:"+example2+"\n你应该返回:"+answer_2+"\n再举个例子,给定工作内容:"+example3+"\n你应该返回:"+answer_3+"\n现在给定工作内容:"+data['mc']+" "+data['tz']+"\n请给出你的答案"},
  89. ],
  90. extra_body={"thinking": {"type": "disabled"}},
  91. )
  92. json_string = completion.choices[0].message.content
  93. print(json_string)
  94. answers = json_string.split("\n")
  95. answers = [x for x in answers if ':' in x ]
  96. answer2 = answers[0].split(":")[1].replace(" ", "")
  97. return answer2
  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": " 背景知识:已知预应力高强混凝土管桩(PHC)代号定义为PHC-AAA(BB)CC-DDD-E1,E2,E3,E4,其中AAA代表管桩外径,BB代表管桩壁厚,CC表示型号,DDD表示混凝土强度等级,E1/E2/E3/E4表示分段桩长。例如,PHC-500(125)-AB-C80-9,7 表示外径500mm,壁厚125mm,型号AB,混凝土强度C80, 分段桩长分别为9米和7米,总桩长16米,施工时需要将两个分段接桩"},
  103. {"role": "user", "content": "问题描述: 给定一段工作内容描述,内容为" + data['mc'] +data['tz'] + "。请判断内容中是否包含桩的代号,如果没有,请输出“无”,如果有,请输出代号"},
  104. ],
  105. extra_body={"thinking": {"type": "disabled"}},
  106. )
  107. json_string = completion.choices[0].message.content
  108. completion = aiclient.chat.completions.create(
  109. model="glm-4.5-flash",
  110. messages=[
  111. {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
  112. {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个代号作为答案,请将该最终答案输出"},
  113. ],
  114. extra_body={"thinking": {"type": "disabled"}},
  115. )
  116. json_string = completion.choices[0].message.content
  117. answers = json_string.split("\n")
  118. answers = [x for x in answers if ':' in x ]
  119. answers = [x for x in answers if not 'true' in x]
  120. answers = [x for x in answers if not '是' in x]
  121. print(answers)
  122. if len(answers) == 0:
  123. return "无"
  124. answer2 = answers[0].split(":")[1].replace(" ", "")
  125. return answer2
  126. def need_extra(
  127. data, #data
  128. aiclient,
  129. qwclient,
  130. sfclient,
  131. result, name_label):
  132. if data['bianma'].startswith('011207') or data['bianma'].startswith('011208'):
  133. result = [x[0].replace('换', '') for x in result]
  134. result = [name_label[x] for x in result]
  135. if len([x for x in result if '铝板' in x or '铝单板' in x]) > 0:
  136. return False
  137. left = [x.replace('在木龙骨', '') for x in result ]
  138. left = [x.replace('在龙骨', '') for x in left ]
  139. left = [x for x in left if '龙骨' not in x]
  140. left = [x for x in left if '细木工板基层' not in x]
  141. left = [x for x in left if '吸音' not in x]
  142. if len(left) == 0:
  143. return True
  144. return False
  145. if data['bianma'].startswith("0108") and len(result) == 0:
  146. return True
  147. if data['bianma'].startswith("0115") and len(result) == 0:
  148. return True
  149. if '高强螺栓' in data['mc']:
  150. return True
  151. time.sleep(1)
  152. completion = qwclient.chat.completions.create(
  153. model="Qwen/Qwen3-32B",
  154. #model="THUDM/GLM-4-9B-0414",
  155. messages=[
  156. {"role": "system", "content": "You are a helpful assistant."},
  157. {"role": "user", "content": "问题描述: 给定一段工作内容描述,内容为" + data['mc'] +data['tz'] + "。请判断内容是否属于打桩、压桩。请回答是或者否"},
  158. ],
  159. #extra_body={"thinking": {"type": "disabled"}},
  160. extra_body={"enable_thinking": False},
  161. )
  162. json_string = completion.choices[0].message.content
  163. print(json_string)
  164. if "是" in json_string:
  165. return True
  166. else:
  167. return False