|
|
@@ -1,6 +1,13 @@
|
|
|
import time
|
|
|
+from tihuan import tihuan
|
|
|
+from fuzhu_util import fuzhu_util
|
|
|
+from f_youqi import f_youqi
|
|
|
+import re
|
|
|
+from config import simplemodel
|
|
|
+from template import expression
|
|
|
from fallback import fallback
|
|
|
from dianceng import dianceng
|
|
|
+from mianceng import mianceng
|
|
|
from lingji import lingji
|
|
|
from jieheceng import jieheceng
|
|
|
from celery_app import celery_app
|
|
|
@@ -10,11 +17,14 @@ from huansuan import callzaihuansuan
|
|
|
import json
|
|
|
import dedata
|
|
|
import chromadb
|
|
|
+print("chroma")
|
|
|
client = chromadb.HttpClient(host='47.101.198.30',port=8000)
|
|
|
-collection = client.get_or_create_collection(name="tj_de_bge")
|
|
|
+collection = client.get_or_create_collection(name="tj_de_bge", metadata={'hnsw:search_ef':15})
|
|
|
cuoshi_collection = client.get_or_create_collection(name="tj_cuoshi_bge")
|
|
|
menchuang_collection = client.get_or_create_collection(name="tj_menchuang_bge")
|
|
|
+qita_collection = client.get_or_create_collection(name="tj_qita_bge")
|
|
|
from FlagEmbedding import FlagModel
|
|
|
+print("model")
|
|
|
model = FlagModel('/mnt/d/Develop/bge/test2_encoder_only_base_bge-large-zh-v1.5')
|
|
|
cuoshi_model = FlagModel('cuoshi_encoder_only_base_bge-large-zh-v1.5/cuoshi_encoder_only_base_bge-large-zh-v1.5')
|
|
|
from sentence_transformers import CrossEncoder
|
|
|
@@ -45,8 +55,11 @@ name_label = json.loads(content)
|
|
|
with open("name_dw", "r") as f:
|
|
|
content = f.read()
|
|
|
name_dw = json.loads(content)
|
|
|
+with open("fuzhu_candidate", "r") as f:
|
|
|
+ content = f.read()
|
|
|
+fuzhu_candidate = json.loads(content)
|
|
|
THRESHOLD=0.8####adjust it
|
|
|
-
|
|
|
+print("client")
|
|
|
import os
|
|
|
from openai import OpenAI
|
|
|
import requests
|
|
|
@@ -55,6 +68,7 @@ aiclient = OpenAI(
|
|
|
api_key=os.getenv("ZAI_API_KEY"),
|
|
|
#base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
|
base_url="https://open.bigmodel.cn/api/paas/v4/",
|
|
|
+ timeout=60
|
|
|
)
|
|
|
qwclient = OpenAI(
|
|
|
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
|
|
|
@@ -62,6 +76,7 @@ qwclient = OpenAI(
|
|
|
api_key=os.getenv("MS_API_KEY"),
|
|
|
#base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
|
base_url="https://api-inference.modelscope.cn/v1/",
|
|
|
+ timeout=60
|
|
|
)
|
|
|
hyclient = OpenAI(
|
|
|
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
|
|
|
@@ -69,25 +84,56 @@ hyclient = OpenAI(
|
|
|
api_key=os.getenv("HY_API_KEY"),
|
|
|
#base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
|
base_url="https://api.hunyuan.cloud.tencent.com/v1",
|
|
|
+ timeout=60
|
|
|
)
|
|
|
-bdclient = OpenAI(
|
|
|
+dsclient = OpenAI(
|
|
|
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
|
|
|
#api_key=os.getenv("DASHSCOPE_API_KEY"),
|
|
|
- api_key=os.getenv("BD_API_KEY"),
|
|
|
+ api_key=os.getenv("DS_API_KEY"),
|
|
|
#base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
|
- base_url="https://qianfan.baidubce.com/v2",
|
|
|
+ base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
|
+ timeout=60
|
|
|
)
|
|
|
+##silicon flow不能用,超级慢,垃圾
|
|
|
sfclient = OpenAI(
|
|
|
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
|
|
|
#api_key=os.getenv("DASHSCOPE_API_KEY"),
|
|
|
api_key=os.getenv("SF_API_KEY"),
|
|
|
#base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
|
base_url="https://api.siliconflow.cn/v1",
|
|
|
+ timeout=60
|
|
|
)
|
|
|
+ssclient = OpenAI(
|
|
|
+ api_key=os.getenv("SS_API_KEY"), # 此处传token,不带Bearer
|
|
|
+ base_url="https://chat.intern-ai.org.cn/api/v1/",
|
|
|
+ timeout=60
|
|
|
+)
|
|
|
+simpleclient = ssclient
|
|
|
|
|
|
|
|
|
-
|
|
|
-def callzaikuailiao(data):
|
|
|
+def has_chinese(text):
|
|
|
+ pattern = re.compile(r'[\u4e00-\u9fff]+')
|
|
|
+ result = pattern.search(text)
|
|
|
+ return True if result else False
|
|
|
+def analyze(json_string):
|
|
|
+ obj = json.loads(json_string)
|
|
|
+ bz = None
|
|
|
+ if 'bz_selected' in obj:
|
|
|
+ bz = obj['bz_selected']
|
|
|
+ bh = bz['BZBH']
|
|
|
+ bh_list = []
|
|
|
+ for entry in bh:
|
|
|
+ bh_list.append([entry, bh[entry], bz['SM'][entry]])
|
|
|
+ print(bh_list)
|
|
|
+ return bh_list,obj['bz_selected2']
|
|
|
+def select_fuzhu(input, label, aiclient, qwclient, sfclient):
|
|
|
+ if label_name[input[0]] in fuzhu_candidate:
|
|
|
+ print(input[0])
|
|
|
+ print(input[1][0])
|
|
|
+ print(input[1][1])
|
|
|
+ return fuzhu_util(input[0], [x[2] for x in input[1][0]], label, aiclient, qwclient, sfclient),input[1][1],input[1][0]
|
|
|
+ return [],{},[]
|
|
|
+def callzailonggu_0113(data):
|
|
|
time.sleep(1)
|
|
|
completion = aiclient.chat.completions.create(
|
|
|
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
@@ -96,7 +142,7 @@ def callzaikuailiao(data):
|
|
|
#model="qwen3-4b",
|
|
|
messages=[
|
|
|
{"role": "system", "content": "You are a helpful assistant."},
|
|
|
- {"role": "user", "content": " 楼地面有多种做法,包括整体面层,块料面层,木地板等。块料面层常见的有石材块料面板,缸砖,马赛克,假麻石块,地砖,橡胶塑料板等。 现在给定一工作内容如下: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ", 计量单位为" + data['dw'] + ", 请问该工作内容中包括了块料面层施工吗?"},
|
|
|
+ {"role": "user", "content": " 天棚工程有多种做法,包括单纯抹灰,单纯天棚面层,也可以制作龙骨并在龙骨上安装面层等。龙骨包括方木龙骨,轻钢龙骨,铝合金龙骨等。 现在给定一工作内容如下: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ", 计量单位为" + data['dw'] + ", 请问该工作内容中包括了龙骨吗?"},
|
|
|
],
|
|
|
# Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
# 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
@@ -106,13 +152,16 @@ def callzaikuailiao(data):
|
|
|
json_string = completion.choices[0].message.content
|
|
|
print(json_string)
|
|
|
time.sleep(1)
|
|
|
- completion = sfclient.chat.completions.create(
|
|
|
+ completion = simpleclient.chat.completions.create(
|
|
|
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
- model="THUDM/GLM-4-9B-0414",
|
|
|
- #model="glm-4.5-flash",
|
|
|
+ model=simplemodel(),
|
|
|
messages=[
|
|
|
{"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
|
|
|
- {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了关于是否包括块料面层施工的判断,请将该判断输出。请输出是或者否"},
|
|
|
+ {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了关于是否包括龙骨的判断,请将该判断输出。 例如:"+'''
|
|
|
+ {
|
|
|
+ '判断':'不包括'
|
|
|
+ }
|
|
|
+ '''},
|
|
|
],
|
|
|
# Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
# 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
@@ -122,14 +171,16 @@ def callzaikuailiao(data):
|
|
|
json_string = completion.choices[0].message.content
|
|
|
print(json_string)
|
|
|
return json_string
|
|
|
-def callzaiclarify(data):
|
|
|
+def callzaikuailiao_0112(data):
|
|
|
+ time.sleep(1)
|
|
|
completion = aiclient.chat.completions.create(
|
|
|
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
- model="glm-4.5-flash",
|
|
|
+ model="glm-4.5-air",
|
|
|
+ #model="ZhipuAI/GLM-4.5",
|
|
|
#model="qwen3-4b",
|
|
|
messages=[
|
|
|
{"role": "system", "content": "You are a helpful assistant."},
|
|
|
- {"role": "user", "content": " 管桩的清单工作内容描述可以分成两类,一类是打桩、压桩,属于桩基工程的一种,其工作内容计量的单位一般是米(m)或根。另一类是填芯,一般是向桩芯内浇混凝土,属于土建工程的一种,其配套的计量单位一般是立方米(m3),即浇混凝土的体积量。现在给定一工作内容如下: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ", 计量单位为" + data['dw'] + ", 请问该工作内容属于填芯吗?"},
|
|
|
+ {"role": "user", "content": " 墙柱面有多种做法,包括单纯抹灰,镶贴块料面层,使用墙板等。块料面层常见的有石材块料面板,瓷砖,面砖,假麻石块等。 现在给定一工作内容如下: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ", 计量单位为" + data['dw'] + ", 请问该工作内容中包括了块料面层施工吗?"},
|
|
|
],
|
|
|
# Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
# 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
@@ -138,13 +189,17 @@ def callzaiclarify(data):
|
|
|
)
|
|
|
json_string = completion.choices[0].message.content
|
|
|
print(json_string)
|
|
|
- completion = sfclient.chat.completions.create(
|
|
|
+ time.sleep(1)
|
|
|
+ completion = simpleclient.chat.completions.create(
|
|
|
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
- model="THUDM/GLM-4-9B-0414",
|
|
|
- #model="glm-4.5-flash",
|
|
|
+ model=simplemodel(),
|
|
|
messages=[
|
|
|
{"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
|
|
|
- {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了关于是不是填芯的判断,请将该判断输出。请输出是或者否"},
|
|
|
+ {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了关于是否包括块料面层施工的判断,请将该判断输出。 例如:"+'''
|
|
|
+ {
|
|
|
+ '判断':'不包括'
|
|
|
+ }
|
|
|
+ '''},
|
|
|
],
|
|
|
# Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
# 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
@@ -154,16 +209,16 @@ def callzaiclarify(data):
|
|
|
json_string = completion.choices[0].message.content
|
|
|
print(json_string)
|
|
|
return json_string
|
|
|
-def callzaidw(A,B):
|
|
|
+def callzaikuailiao(data):
|
|
|
time.sleep(1)
|
|
|
- completion = qwclient.chat.completions.create(
|
|
|
+ completion = aiclient.chat.completions.create(
|
|
|
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
- #model="glm-4.5-flash",
|
|
|
- model="ZhipuAI/GLM-4.5",
|
|
|
+ model="glm-4.5-flash",
|
|
|
+ #model="ZhipuAI/GLM-4.5",
|
|
|
#model="qwen3-4b",
|
|
|
messages=[
|
|
|
{"role": "system", "content": "You are a helpful assistant."},
|
|
|
- {"role": "user", "content": " 计量单位可以用名称或者符号表示,常用的符号包括表示米的符号m,表示千米的符号km,表示吨的符号t,表示千克的符号kg,表示平方米的符号m2,表示立方米的符号m3。也有计量单位很宽泛,比如“项”、“次”. 给定一个工作量计量单位,内容为" + A + ",记作A,再给定一个工作量计量单位,内容为" + B + ",记作B。若两个单位相等,请返回A=B。例如,“项”跟“次”是等价的,应返回A=B。若两个单位不相等,但是存在比例换算关系,请返回比例换算关系,例如A单位是m,B单位是10m, 则返回A=0.1*B。再例如,A单位是10m2,B单位是m2,则返回A=10*B。再例如,A单位是m3, B单位是1000m3,则返回A=0.001*B。若两个单位不相等,且不存在比例换算关系,请返回A<>B,例如A单位是m,B单位是m2,一个表示长度,一个表示面积,不存在比例关系,则返回A<>B。 "},
|
|
|
+ {"role": "user", "content": " 楼地面有多种做法,包括整体面层,块料面层,木地板等。块料面层常见的有石材块料面板,缸砖,马赛克,假麻石块,地砖,橡胶塑料板等。 现在给定一工作内容如下: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ", 计量单位为" + data['dw'] + ", 请问该工作内容中包括了块料面层施工吗?"},
|
|
|
],
|
|
|
# Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
# 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
@@ -173,13 +228,16 @@ def callzaidw(A,B):
|
|
|
json_string = completion.choices[0].message.content
|
|
|
print(json_string)
|
|
|
time.sleep(1)
|
|
|
- completion = qwclient.chat.completions.create(
|
|
|
+ completion = simpleclient.chat.completions.create(
|
|
|
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
- model="ZhipuAI/GLM-4.5",
|
|
|
- #model="glm-4.5-flash",
|
|
|
+ model=simplemodel(),
|
|
|
messages=[
|
|
|
{"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
|
|
|
- {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于A=B的表达式作为答案,请将该最终答案输出"},
|
|
|
+ {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了关于是否包括块料面层施工的判断,请将该判断输出。 例如:"+'''
|
|
|
+ {
|
|
|
+ '判断':'不包括'
|
|
|
+ }
|
|
|
+ '''},
|
|
|
],
|
|
|
# Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
# 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
@@ -189,16 +247,14 @@ def callzaidw(A,B):
|
|
|
json_string = completion.choices[0].message.content
|
|
|
print(json_string)
|
|
|
return json_string
|
|
|
-
|
|
|
-
|
|
|
-def callzai(A,B,C):
|
|
|
+def youqi_(tz):
|
|
|
completion = aiclient.chat.completions.create(
|
|
|
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
- model="glm-4.5-flash",
|
|
|
+ model="glm-4.5-air",
|
|
|
#model="qwen3-4b",
|
|
|
messages=[
|
|
|
- {"role": "system", "content": "You are a helpful assistant."},
|
|
|
- {"role": "user", "content": " 给定一条主定额,内容为" + A + ",记作A,再给定一条配套定额,内容为" + B + ",记作B。可以通过简单的组合,来表达对应的工作内容的数量,比如A+B可以表达,主定额的工作量加上配套定额的工作量;再比如,A+B*2可以表达, 主定额的工作量加上两倍的配套定额的工作量;再比如,A+B*(-2)可以表达, 主定额减去两倍的配套定额的工作量;再比如,A可以表示,不使用配套定额,仅表示主定额的工作量。现在给你一条工程量清单,内容为" + C + ",该条清单包含了主定额描述的工作内容,但是数量并不一定一致。请你组合A与B,表示出清单描述的对应工作数量。请输出类似A+B、A+B*2、A-B*2的格式,不要输出A+2*B、A-2*B的格式。如果清单里相应工作量的描述不明确,请输出A作为答案 "},
|
|
|
+ {"role": "system", "content": "You are a helpful assistant.请将结果以json格式输出"},
|
|
|
+ {"role": "user", "content": " 金属结构的油漆一般是多层涂刷,常规的是包括底漆跟面漆。也可能是底漆,中间漆再加面漆。金属结构有时需要涂刷防火涂料。但是防火涂料跟油漆不是一回事。现在给定一工作内容如下: " + tz + ", 请将该工作内容中的油漆相关内容原封不动地抽取出来。请勿抽取防火涂料相关内容。如果工作内容中完全没有提到油漆,则返回”无“"},
|
|
|
],
|
|
|
# Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
# 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
@@ -207,15 +263,117 @@ def callzai(A,B,C):
|
|
|
)
|
|
|
json_string = completion.choices[0].message.content
|
|
|
print(json_string)
|
|
|
- if len(json_string) < 4:
|
|
|
- return json_string
|
|
|
+ return json_string
|
|
|
+def callzaiclarify(data):
|
|
|
completion = aiclient.chat.completions.create(
|
|
|
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
+ model="glm-4.5-air",
|
|
|
#model="qwen3-4b",
|
|
|
- model="glm-4.5-flash",
|
|
|
+ messages=[
|
|
|
+ {"role": "system", "content": "You are a helpful assistant."},
|
|
|
+ {"role": "user", "content": " 管桩的清单工作内容描述可以分成两类,一类是打桩、压桩,属于桩基工程的一种,其工作内容计量的单位一般是米(m)或根。另一类是填芯,一般是向桩芯内浇混凝土,属于土建工程的一种,其配套的计量单位一般是立方米(m3),即浇混凝土的体积量。现在给定一工作内容如下: " + data['label'] + " " + data['mc'] + " " + data['tz'] + ", 计量单位为" + data['dw'] + ", 请问该工作内容属于填芯吗?"},
|
|
|
+ ],
|
|
|
+ # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
+ # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
+ #extra_body={"enable_thinking": False},
|
|
|
+ extra_body={"thinking": {"type": "disabled"}},
|
|
|
+ )
|
|
|
+ json_string = completion.choices[0].message.content
|
|
|
+ print(json_string)
|
|
|
+ completion = simpleclient.chat.completions.create(
|
|
|
+ # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
+ model=simplemodel(),
|
|
|
+ messages=[
|
|
|
+ {"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
|
|
|
+ {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了关于是不是填芯的判断,请将该判断输出。请输出是或者否"},
|
|
|
+ ],
|
|
|
+ # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
+ # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
+ #extra_body={"enable_thinking": False},
|
|
|
+ extra_body={"thinking": {"type": "disabled"}},
|
|
|
+ )
|
|
|
+ json_string = completion.choices[0].message.content
|
|
|
+ print(json_string)
|
|
|
+ return json_string
|
|
|
+def callzaidw(A,B):
|
|
|
+ time.sleep(1)
|
|
|
+ completion = dsclient.chat.completions.create(
|
|
|
+ # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
+ model='glm-4.5-air',
|
|
|
+ #model="modelscope.cn/unsloth/GLM-Z1-32B-0414-GGUF",
|
|
|
+ stream=True,
|
|
|
+ messages=[
|
|
|
+ {"role": "system", "content": "You are a helpful assistant."},
|
|
|
+ {"role": "user", "content": " 计量单位可以用名称或者符号表示,常用的符号包括表示米的符号m,表示千米的符号km,表示吨的符号t,表示千克的符号kg,表示平方米的符号m2,表示立方米的符号m3。也有计量单位很宽泛,比如“项”、“次”. 给定一个工作量计量单位,内容为" + A + ",记作A,再给定一个工作量计量单位,内容为" + B + ",记作B。若两个单位相等,请返回A=B。例如,“项”跟“次”是等价的,应返回A=B。若两个单位不相等,但是存在比例换算关系,请返回比例换算关系,例如A单位是m,B单位是10m, 则返回A=0.1*B。再例如,A单位是10m2,B单位是m2,则返回A=10*B。再例如,A单位是m3, B单位是1000m3,则返回A=0.001*B。若两个单位不相等,且不存在比例换算关系,请返回A<>B,例如A单位是m,B单位是m2,一个表示长度,一个表示面积,不存在比例关系,则返回A<>B。 "},
|
|
|
+ ],
|
|
|
+ # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
+ # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
+ extra_body={"enable_thinking": False},
|
|
|
+ #extra_body={"thinking": {"type": "disabled"}},
|
|
|
+ )
|
|
|
+ is_answering = False # 是否进入回复阶段
|
|
|
+ print("\n" + "=" * 20 + "思考过程" + "=" * 20)
|
|
|
+ json_string = ""
|
|
|
+ for chunk in completion:
|
|
|
+ delta = chunk.choices[0].delta
|
|
|
+ if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
|
|
|
+ if not is_answering:
|
|
|
+ print(delta.reasoning_content, end="", flush=True)
|
|
|
+ if hasattr(delta, "content") and delta.content:
|
|
|
+ if not is_answering:
|
|
|
+ print("\n" + "=" * 20 + "完整回复" + "=" * 20)
|
|
|
+ is_answering = True
|
|
|
+ json_string = json_string + delta.content#, end="", flush=True)
|
|
|
+ #json_string = completion.choices[0].message.content
|
|
|
+ print(json_string)
|
|
|
+ time.sleep(1)
|
|
|
+ completion = simpleclient.chat.completions.create(
|
|
|
+ # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
+ #model="THUDM/GLM-4-9B-0414",
|
|
|
+ model=simplemodel(),
|
|
|
+ #model="glm-4.5-flash",
|
|
|
+ messages=expression(json_string),
|
|
|
+ # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
+ # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
+ #extra_body={"enable_thinking": False},
|
|
|
+ extra_body={"thinking": {"type": "disabled"}},
|
|
|
+ )
|
|
|
+ json_string = completion.choices[0].message.content
|
|
|
+ print(json_string)
|
|
|
+ return json_string
|
|
|
+
|
|
|
+
|
|
|
+def callzai(A,B,C):
|
|
|
+ completion = qwclient.chat.completions.create(
|
|
|
+ # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
+ #model="glm-4.5-flash",
|
|
|
+ model="Qwen/Qwen3-32B",
|
|
|
+ messages=[
|
|
|
+ {"role": "system", "content": "You are a helpful assistant."},
|
|
|
+ {"role": "user", "content": " 给定一条主定额,内容为" + A + ",记作A,再给定一条配套定额,内容为" + B + ",记作B。可以通过简单的组合,来表达对应的工作内容的数量,比如A+B可以表达,主定额的工作量加上配套定额的工作量;再比如,A+B*2可以表达, 主定额的工作量加上两倍的配套定额的工作量;再比如,A+B*(-2)可以表达, 主定额减去两倍的配套定额的工作量;再比如,A可以表示,不使用配套定额,仅表示主定额的工作量。现在给你一条工程量清单,内容为" + C + ",该条清单包含了主定额描述的工作内容,但是数量并不一定一致。请你找到清单中对应的描述(不需要考虑混凝土强度等级是否完全一致,需要区分面层和找平找坡层),辨识出工作数量(砂浆保护层厚度跟砂浆找平层厚度不可合并),并组合A与B,表示出清单描述的对应工作数量。请给出分析过程,并请最终输出类似A+B、A+B*2、A-B*2的格式,不要输出A+2*B、A-2*B的格式。如果清单里相应工作量的描述不明确,请输出A作为答案 "},
|
|
|
+ ],
|
|
|
+ # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
+ # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
+ extra_body={"enable_thinking": False},
|
|
|
+ #extra_body={"thinking": {"type": "disabled"}},
|
|
|
+ )
|
|
|
+ json_string = completion.choices[0].message.content
|
|
|
+ print(json_string)
|
|
|
+ if len(json_string) < 4:
|
|
|
+ return "result:" + json_string
|
|
|
+ completion = simpleclient.chat.completions.create(
|
|
|
+ # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
+ model=simplemodel(),
|
|
|
+ #model="THUDM/GLM-4-9B-0414",
|
|
|
messages=[
|
|
|
{"role": "system", "content": "You are a helpful assistant.请将最终答案以JSON格式输出"},
|
|
|
- {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于A+B的表达式作为答案,请将该最终答案输出"},
|
|
|
+ {"role": "user", "content": " 给你一段文字如下, " + json_string + ",其中给出了一个类似于A+B的表达式作为答案,请将该最终答案输出.如果文字中指出可能有两种答案,则只需要输出其中一种。例如" +'''
|
|
|
+ [
|
|
|
+ 'result' : 'A+B*-2'
|
|
|
+ }
|
|
|
+ 注意,只需要输出最终答案,不需要中间过程或者其他细节,只需要输出一种答案
|
|
|
+ '''
|
|
|
+ },
|
|
|
],
|
|
|
# Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False)
|
|
|
# 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错
|
|
|
@@ -230,15 +388,20 @@ def transform(answer, input, entry):
|
|
|
answers = [x for x in answers if ':' in x and "A" in x]
|
|
|
if len(answers) == 0:
|
|
|
return input
|
|
|
+ answers[0] = answers[0].split(',')[0]
|
|
|
answer2 = answers[0].split(":")[1].replace(" ", "")
|
|
|
- answer2 = answer2.replace("A", input)
|
|
|
- answer2 = answer2.replace("B", "["+entry+"]")
|
|
|
+ if 'B' in answer2:
|
|
|
+ answer2 = answer2.replace("B", 'BBB')
|
|
|
+ answer2 = answer2.replace("A", input)
|
|
|
+ answer2 = answer2.replace("BBB", "["+entry+"]")
|
|
|
+ else:
|
|
|
+ answer2 = answer2.replace("A", input)
|
|
|
answer2 = answer2.replace("\'", "")
|
|
|
answer2 = answer2.replace("\"", "")
|
|
|
return answer2
|
|
|
|
|
|
def zuhe(input, content):
|
|
|
- if input in incremental:
|
|
|
+ if input in incremental and input != '17-176' and input != '17-177' and input != '17-179' and input != '17-180' and input != '17-181':
|
|
|
option = incremental[input]
|
|
|
for entry in option:
|
|
|
answer = callzai(name_label[input], name_label[entry], content)
|
|
|
@@ -256,10 +419,12 @@ def huansuan_highlevel(bianma, label, input,dw, tz):
|
|
|
dw1 = input
|
|
|
dw1 = dw1.lower()
|
|
|
dw1 = dw1.replace("水平投影面积", "")
|
|
|
+ dw1 = dw1.replace("每1m2建筑面积", "m2")
|
|
|
dw2 = name_dw[dw]
|
|
|
dw2 = dw2.lower()
|
|
|
dw2 = dw2.replace("水平投影面积", "")
|
|
|
- answer = callzaihuansuan(bianma, label, dw1,dw2,tz, aiclient, qwclient)
|
|
|
+ dw2 = dw2.replace("每1m2建筑面积", "m2")
|
|
|
+ answer = callzaihuansuan(bianma, label, dw1,dw2,tz, aiclient, qwclient, simpleclient)
|
|
|
answers = answer.split("\n")
|
|
|
answers = [x for x in answers if ':' in x and "A" in x]
|
|
|
answers = [x for x in answers if '=' in x or '<>' in x]
|
|
|
@@ -294,16 +459,35 @@ def huansuan(input, dw):
|
|
|
dw1 = input
|
|
|
dw1 = dw1.lower()
|
|
|
dw1 = dw1.replace("水平投影面积", "")
|
|
|
+ dw1 = dw1.replace("每1m2建筑面积", "m2")
|
|
|
dw2 = name_dw[dw]
|
|
|
dw2 = dw2.lower()
|
|
|
dw2 = dw2.replace("水平投影面积", "")
|
|
|
+ dw2 = dw2.replace("每1m2建筑面积", "m2")
|
|
|
if dw1 == dw2:
|
|
|
return 1
|
|
|
+ if dw1 == 'm2' and dw2 == '10m2':
|
|
|
+ return 0.1
|
|
|
+ if dw1 == 'm2' and dw2 == '100m2':
|
|
|
+ return 0.01
|
|
|
+ if dw1 == 'm2' and dw2 == '1000m2':
|
|
|
+ return 0.001
|
|
|
+ if dw1 == 'm' and dw2 == '10m':
|
|
|
+ return 0.1
|
|
|
+ if dw1 == 'm' and dw2 == '100m':
|
|
|
+ return 0.01
|
|
|
+ if dw1 == 'm3' and dw2 == '10m3':
|
|
|
+ return 0.1
|
|
|
+ if dw1 == 'm3' and dw2 == '100m3':
|
|
|
+ return 0.01
|
|
|
+ if dw1 == 'm3' and dw2 == '1000m3':
|
|
|
+ return 0.001
|
|
|
else:
|
|
|
answer = callzaidw(dw1,dw2)
|
|
|
answers = answer.split("\n")
|
|
|
answers = [x for x in answers if ':' in x and "A" in x]
|
|
|
answers = [x for x in answers if '=' in x or '<>' in x]
|
|
|
+ answers = [x for x in answers if not has_chinese(x)]
|
|
|
print(answers)
|
|
|
if len(answers) == 0:
|
|
|
return 0
|
|
|
@@ -325,34 +509,78 @@ def huansuan(input, dw):
|
|
|
|
|
|
def clarify(data):
|
|
|
data['tz'] = data['tz'].replace("水泥基防水涂料", "水泥基渗透结晶防水涂料")
|
|
|
- data['tz'] = data['tz'].replace("无机保温砂浆", "无机轻集料保温砂浆")
|
|
|
+ data['tz'] = data['tz'].replace("回光灯带", "回光灯槽")
|
|
|
+ data['mc'] = data['mc'].replace("回光灯带", "回光灯槽")
|
|
|
+ data['tz'] = data['tz'].replace("自流平", "自流平地面")
|
|
|
data['tz'] = data['tz'].replace("JS防水涂料", "聚合物水泥防水涂料")
|
|
|
+ data['tz'] = data['tz'].replace("聚合物水泥砂浆", "防水砂浆")
|
|
|
+ data['tz'] = data['tz'].replace("丝杆", "丝杆吊筋")
|
|
|
if data['bianma'].startswith("010301"):##打桩
|
|
|
print("clarify")
|
|
|
result = callzaiclarify(data)
|
|
|
if "是" in result:
|
|
|
data['mc'] = data['mc'] + '填芯'
|
|
|
return data, False
|
|
|
+ elif data['bianma'].startswith("010606012"): ##钢支架
|
|
|
+ if '镀锌方管' in data['tz'] or '镀锌圆管' in data['tz'] or '镀锌钢管' in data['tz'] or '镀锌角钢' in data['tz']:
|
|
|
+ data['tz'] = data['tz'].replace('支架', '骨架')
|
|
|
+ data['tz'] = data['tz'].replace('基架', '骨架')
|
|
|
+ data['mc'] = '钢骨架'
|
|
|
+ return data, False
|
|
|
elif data['bianma'].startswith("010507001"): ##散水、坡道
|
|
|
data['tz'] = lingji(data['tz'], aiclient, qwclient)
|
|
|
data['tz'] = dianceng(data['tz'], aiclient, qwclient)
|
|
|
+ data['tz'] = mianceng(data['tz'], aiclient, qwclient)
|
|
|
+ data['tz'] = jieheceng(data['tz'], aiclient, qwclient)
|
|
|
return data, False
|
|
|
elif data['bianma'].startswith("0109"): ##防水
|
|
|
data['tz'] = lingji(data['tz'], aiclient, qwclient)
|
|
|
data['tz'] = dianceng(data['tz'], aiclient, qwclient)
|
|
|
+ data['tz'] = jieheceng(data['tz'], aiclient, qwclient)
|
|
|
return data, False
|
|
|
elif data['bianma'].startswith("0111"):
|
|
|
+ data['tz'] = data['tz'].replace("卷材面层", "面层")
|
|
|
+ if data['bianma'].startswith("011107"):##台阶
|
|
|
+ data['mc'] = '台阶面'
|
|
|
+
|
|
|
data['tz'] = jieheceng(data['tz'], aiclient, qwclient)
|
|
|
result = callzaikuailiao(data)
|
|
|
- if '是' in result:
|
|
|
- return data, True
|
|
|
+ if '不' in result:
|
|
|
+ return data, False
|
|
|
+ return data, True
|
|
|
+ elif data['bianma'].startswith("0112"):
|
|
|
+ if '镀锌方管' in data['tz'] or '镀锌圆管' in data['tz'] or '镀锌钢管' in data['tz'] or '镀锌角钢' in data['tz']:
|
|
|
+ data['tz'] = data['tz'].replace('支架', '骨架')
|
|
|
+ data['tz'] = data['tz'].replace('基架', '骨架')
|
|
|
+ data['tz'] = data['tz'].replace("铝单板", "铝单板幕墙")
|
|
|
+ data['tz'] = data['tz'].replace("阻燃板", "细木工板")
|
|
|
+ data['tz'] = data['tz'].replace("阻燃基层板", "细木工板")
|
|
|
+ data['tz'] = data['tz'].replace("水泥纤维板", "水泥压力板")
|
|
|
+ if '防潮层' in data['tz'] or '防水砂浆' in data['tz']:
|
|
|
+ data['mc']='墙柱面防水(防潮)'
|
|
|
+ result = callzaikuailiao_0112(data)
|
|
|
+ if '不' in result:
|
|
|
+ return data, False
|
|
|
+ return data, True
|
|
|
+ elif data['bianma'].startswith("0113"):
|
|
|
+ result = callzailonggu_0113(data)
|
|
|
+ if '不' in result:
|
|
|
+ return data, False
|
|
|
+ if not '上人' in data['tz']:
|
|
|
+ data['tz']=data['tz'].replace('龙骨','不上人型龙骨')
|
|
|
+ data['tz']=data['tz'].replace('铝格栅','铝格栅吊顶')
|
|
|
+ data['tz']=data['tz'].replace('纸面石膏板','纸面石膏板面层')
|
|
|
+ return data, True
|
|
|
+ elif data['bianma'].startswith("0117"):
|
|
|
+ data['mc']=data['mc'].replace('线条','檐沟')
|
|
|
+ data['tz']=data['tz'].replace('线条','檐沟')
|
|
|
return data, False
|
|
|
|
|
|
else:
|
|
|
return data, False
|
|
|
|
|
|
-
|
|
|
-@celery_app.task
|
|
|
+from redis.exceptions import TimeoutError
|
|
|
+@celery_app.task(autoretry_for=(TimeoutError,))
|
|
|
def process_data(data:dict)-> dict:
|
|
|
placeholder, kuailiao = clarify(data)
|
|
|
label = data['mc'] + ' ' + data['tz']
|
|
|
@@ -367,7 +595,11 @@ def process_data(data:dict)-> dict:
|
|
|
result = cuoshi_collection.query(query_embeddings=embeddings,n_results=25)
|
|
|
else:
|
|
|
result = collection.query(query_embeddings=embeddings,n_results=25)
|
|
|
-
|
|
|
+ yqspecial=[]
|
|
|
+ if data['bianma'].startswith('0106'):
|
|
|
+ youqi = youqi_(data['tz'])
|
|
|
+ if '无' not in youqi:
|
|
|
+ yqspecial= f_youqi(data, youqi,collection,model,ce,name_label)
|
|
|
d = result['documents'][0]
|
|
|
print(d)
|
|
|
if data['bianma'].startswith("0117"):
|
|
|
@@ -472,24 +704,44 @@ def process_data(data:dict)-> dict:
|
|
|
# cutoff = score - 0.1
|
|
|
# if cutoff < 0.3:
|
|
|
# cutoff = 0.3
|
|
|
- if data['bianma'].startswith('0106'):##金属结构
|
|
|
+ if data['bianma'].startswith('0106') and '钢丝网' not in data['mc']:##金属结构
|
|
|
score = -1
|
|
|
for rank in ranks:
|
|
|
if label_name[d[rank['corpus_id']]].startswith('7-') and label_name[d[rank['corpus_id']]] != '7-62' and label_name[d[rank['corpus_id']]] !='7-63':
|
|
|
score = rank['score']
|
|
|
break
|
|
|
if score > -1 and score < cutoff:
|
|
|
- cutoff = score - 0.05
|
|
|
+ cutoff = score - 0.01
|
|
|
if cutoff < 0.3:
|
|
|
cutoff = 0.3
|
|
|
if data['bianma'].startswith('0111'):##楼地面
|
|
|
score = -1
|
|
|
for rank in ranks:
|
|
|
- if '13.4' in d[rank['corpus_id']] and '块料面层' in d[rank['corpus_id']]:
|
|
|
+ if ('13.4' in d[rank['corpus_id']] or '14.3' in d[rank['corpus_id']]) and '块料面层' in d[rank['corpus_id']]:
|
|
|
score = rank['score']
|
|
|
break
|
|
|
- if score > -1 and score < cutoff:
|
|
|
- cutoff = score - 0.05
|
|
|
+ if score > -1 and score < cutoff and kuailiao:
|
|
|
+ cutoff = score - 0.01
|
|
|
+ if cutoff < 0.3:
|
|
|
+ cutoff = 0.3
|
|
|
+ if data['bianma'].startswith('0112'):##墙柱面
|
|
|
+ score = -1
|
|
|
+ for rank in ranks:
|
|
|
+ if ('14.3' in d[rank['corpus_id']]) and '块料面层' in d[rank['corpus_id']]:
|
|
|
+ score = rank['score']
|
|
|
+ break
|
|
|
+ if score > -1 and score < cutoff and kuailiao:
|
|
|
+ cutoff = score - 0.01
|
|
|
+ if cutoff < 0.3:
|
|
|
+ cutoff = 0.3
|
|
|
+ if data['bianma'].startswith('0113'):##天棚
|
|
|
+ score = -1
|
|
|
+ for rank in ranks:
|
|
|
+ if '15.1.1' in d[rank['corpus_id']] or '15.1.2' in d[rank['corpus_id']] or '15.1.3' in d[rank['corpus_id']] or '15.1.4' in d[rank['corpus_id']] or '15.1.5' in d[rank['corpus_id']]:
|
|
|
+ score = rank['score']
|
|
|
+ break
|
|
|
+ if score > -1 and score < cutoff and kuailiao:
|
|
|
+ cutoff = score - 0.01
|
|
|
if cutoff < 0.3:
|
|
|
cutoff = 0.3
|
|
|
print("cutoff=" + str(cutoff))
|
|
|
@@ -542,25 +794,38 @@ def process_data(data:dict)-> dict:
|
|
|
notselected = notselected + basic[entry]
|
|
|
notselected = [x for x in notselected if x not in selected]
|
|
|
selected = list(set(selected))
|
|
|
- if len(selected) == 0:
|
|
|
- candidates=[]
|
|
|
- for rank in ranks:
|
|
|
- candidates.append(d[rank['corpus_id']])
|
|
|
- selected = fallback(candidates, data, aiclient, qwclient, menchuang_collection, model)
|
|
|
- selected = postprocess(selected, data, aiclient, qwclient,sfclient, label_name, name_dw)
|
|
|
+ candidates=[]
|
|
|
+ for rank in ranks:
|
|
|
+ candidates.append(d[rank['corpus_id']])
|
|
|
+ if len(selected) == 0 and not data['bianma'].startswith('0115'):
|
|
|
+ selected = fallback(candidates, data, aiclient, qwclient, simpleclient, menchuang_collection, model)
|
|
|
+ selected = postprocess(selected, data, aiclient, qwclient,simpleclient, label_name, name_dw, candidates,yqspecial)
|
|
|
print("final selected")
|
|
|
print(selected)
|
|
|
result = [(label_name[x], huansuan_highlevel(data['bianma'], x, data['dw'], label_name[x], data['mc']+data['tz'])) for x in selected]
|
|
|
print("after haunsuan")
|
|
|
print(result)
|
|
|
- result = [(zuhe(x[0], label), x[1]) for x in result]
|
|
|
+ result = [(zuhe(x[0], label).replace(',',''), x[1]) for x in result]
|
|
|
print("after zuhe")
|
|
|
print(result)
|
|
|
result = [(x[0], x[1], dedata.read_singledexilie2(10, x[0])) for x in result]
|
|
|
- need = need_extra(data, aiclient, qwclient, result)
|
|
|
+ result = [(x[0], x[1], x[2], tihuan(x[0], x[2], label, aiclient, qwclient, simpleclient)) for x in result]
|
|
|
+ fuzhu = [analyze(x[2]) for x in result]
|
|
|
+ fuzhu = zip(selected, fuzhu)
|
|
|
+ fuzhu = [x for x in fuzhu]
|
|
|
+ fuzhu_selected = [select_fuzhu(x, label, aiclient, qwclient, simpleclient) for x in fuzhu]
|
|
|
+ need = need_extra(data, aiclient, qwclient, simpleclient, result)
|
|
|
+ replace={}
|
|
|
if need:
|
|
|
- extra_info = extra(data, aiclient, qwclient, menchuang_collection, model)
|
|
|
+ extra_info = extra(data, aiclient, qwclient, simpleclient, menchuang_collection, model, qita_collection)
|
|
|
+ replace['04290241']=extra_info##桩
|
|
|
+ replace['04290303']=extra_info
|
|
|
else:
|
|
|
extra_info = "无"
|
|
|
- response = requests.post("http://localhost:3000/api/transform", json={'bianma': data['bianma'], 'mc': data['mc'], 'tz': data['tz'], 'dw': data['dw'], 'sl': data['sl'], 'n': data['n'], "extra": extra_info, 'result': result})
|
|
|
- return {"result": response.json()}
|
|
|
+ if '高强螺栓' in extra_info:
|
|
|
+ response = requests.post("http://localhost:3000/api/transform", json={'bianma': data['bianma'], 'mc': data['mc'], 'tz': data['tz'], 'dw': data['dw'], 'sl': data['sl'], 'n': data['n'], "extra": extra_info, 'result': [], 'fuzhu': fuzhu_selected, 'replace': replace})
|
|
|
+ return {"result": response.json()}
|
|
|
+ else:
|
|
|
+ response = requests.post("http://localhost:3000/api/transform", json={'bianma': data['bianma'], 'mc': data['mc'], 'tz': data['tz'], 'dw': data['dw'], 'sl': data['sl'], 'n': data['n'], "extra": extra_info, 'result': result, 'fuzhu': fuzhu_selected, 'replace': replace})
|
|
|
+ return {"result": response.json()}
|
|
|
+
|