上传文件至 /
4.3更新
This commit is contained in:
+99
-10
@@ -35,6 +35,13 @@ deep_v3 = ChatOpenAI(
|
||||
)
|
||||
|
||||
|
||||
# from langchain.llms import Xinference
|
||||
# from langchain.prompts import PromptTemplate
|
||||
# from langchain.chains import LLMChain, SequentialChain
|
||||
|
||||
# llm = Xinference(server_url="http://172.20.0.145:9995", model_uid="deepseek-r1-distill-qwen2.5-32b")
|
||||
|
||||
|
||||
def suffix_answers():
|
||||
PromptTemplate1 = """
|
||||
根据用户输入和相关知识回答问题
|
||||
@@ -54,6 +61,7 @@ def suffix_answers():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | qwen_llm | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -65,28 +73,57 @@ def suffix_answers():
|
||||
# 费用计算(专属意图,复杂计算推理)
|
||||
# 下载与安装(询问软件的下载和安装):【配网D3软件】程序包发我;【配网D3软件】怎么安装
|
||||
|
||||
# def Vertical_classification():
|
||||
# PromptTemplate1 = """
|
||||
# 根据用户输入进行垂直领域分类
|
||||
|
||||
# 目前的垂直分类:【'闲聊', '软件咨询'】
|
||||
|
||||
# # 软件咨询包括以下:
|
||||
# 1. 查询功能(询问软件功能或用途,包括后缀名问题)
|
||||
# 2. 操作指导(询问具体使用方法)
|
||||
# 3. 故障排查(解决软件错误问题)
|
||||
# 4. 下载安装(关于软件的下载和安装问题)
|
||||
|
||||
# # 用户输入
|
||||
# {query}
|
||||
|
||||
# # 注意:
|
||||
# 1. 你只能回答是'闲聊' 或者 '软件咨询',绝对不能有其他回复
|
||||
# """
|
||||
|
||||
# Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
# Chain = Prompt | qwen_llm | StrOutputParser()
|
||||
|
||||
# return Chain
|
||||
|
||||
def Vertical_classification():
|
||||
PromptTemplate1 = """
|
||||
根据用户输入进行垂直领域分类
|
||||
请根据用户的输入内容,将其归类为以下两个垂直领域之一:
|
||||
|
||||
目前的垂直分类:【'闲聊', '软件咨询'】
|
||||
【垂直领域分类】:
|
||||
1. 闲聊 —— 指与软件无关的日常对话、问候、感慨、情绪表达等。
|
||||
2. 软件咨询 —— 指涉及软件使用、下载、功能、问题排查等方面的提问或请求。
|
||||
|
||||
# 软件咨询包括以下:
|
||||
1. 查询功能(询问软件功能或用途,包括后缀名问题)
|
||||
2. 操作指导(询问具体使用方法)
|
||||
3. 故障排查(解决软件错误问题)
|
||||
4. 下载安装(关于软件的下载和安装问题)
|
||||
【软件咨询包括以下四类】:
|
||||
1. 查询功能:例如询问软件的功能、用途,或某种文件后缀对应的软件。
|
||||
2. 操作指导:例如询问如何使用某个功能、软件的使用方法。
|
||||
3. 故障排查:例如反馈软件报错、卡顿、打不开等问题,并寻求解决方案。
|
||||
4. 下载安装:例如请求下载地址、安装流程、环境配置等信息。
|
||||
|
||||
# 用户输入
|
||||
【用户输入】:
|
||||
{query}
|
||||
|
||||
# 注意:
|
||||
1. 你只能回答是'闲聊' 或者 '软件咨询',绝对不能有其他回复
|
||||
【要求】:
|
||||
- 请你只返回一个结果:"闲聊" 或 "软件咨询"。
|
||||
- 不允许输出任何解释、标点符号或额外内容。
|
||||
"""
|
||||
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | qwen_llm | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -108,6 +145,7 @@ def small_talk():
|
||||
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
Chain = Prompt | qwen_llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
@@ -144,6 +182,7 @@ def intention_judge():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | qwen_llm | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -172,6 +211,7 @@ def domain_judge():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -196,6 +236,36 @@ def domain_judge_v2():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
def domain_judge_v3():
|
||||
# 费用计算另处理
|
||||
PromptTemplate1 = """
|
||||
你是一个领域问题分类助手。请根据用户的问题,将其归类到以下软件领域中:
|
||||
|
||||
1. 西藏造价软件Z1
|
||||
2. 新型储能计价通C1
|
||||
3. 技改检修计价通T1
|
||||
4. 博微配网工程计价通D3软件
|
||||
5. 其他 (用户输入没有提到具体软件名称或者不属于上述软件名,就回答‘其他’)
|
||||
|
||||
用户输入:"{query}"
|
||||
|
||||
请明确指出该问题属于哪个领域问题分类。
|
||||
|
||||
输出格式:str类型
|
||||
|
||||
注意:
|
||||
1. 你的回复答案一定是[西藏造价软件Z1、新型储能计价通C1、技改检修计价通T1、博微配网工程计价通D3软件、未知]之一,不要有其他回答,不要解释说明
|
||||
2. 如果用户输入没有说明具体哪个软件,则回答‘其他’
|
||||
"""
|
||||
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -218,6 +288,7 @@ def judge_5W2H():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | qwen_llm | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -254,6 +325,7 @@ def extract_keywords():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | qwen_llm | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -320,5 +392,22 @@ def answer_questions():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
def mutil12():
|
||||
PromptTemplate1 = """
|
||||
你根据输入语句:{query}来分析是缺软件名字还是缺具体问题
|
||||
# 输出
|
||||
缺软件名字返回1
|
||||
缺具体问题返回2
|
||||
你只能返回1或者2,不要有其他解释
|
||||
"""
|
||||
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | qwen_llm | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
@@ -33,6 +33,12 @@ deep_v3 = ChatOpenAI(
|
||||
temperature=0.1
|
||||
)
|
||||
|
||||
|
||||
# =========================================
|
||||
|
||||
# =========================================
|
||||
|
||||
|
||||
# 软件名重写
|
||||
def software_name_rewrite():
|
||||
PromptTemplate = """
|
||||
@@ -47,6 +53,7 @@ def software_name_rewrite():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate)
|
||||
|
||||
Chain = Prompt | qwen_llm | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -96,6 +103,7 @@ def retrieval_rewrite():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate)
|
||||
|
||||
Chain = Prompt | qwen_llm | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -114,6 +122,7 @@ def to_normal_rewrite():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -134,6 +143,7 @@ def query_function_rewrite():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -154,6 +164,7 @@ def operation_guidance_rewrite():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -176,6 +187,7 @@ def troubleshooting_rewrite():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
@@ -197,8 +209,93 @@ def access_rewrite():
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
|
||||
# 全名扩写
|
||||
def full_name_extension():
|
||||
PromptTemplate = """
|
||||
你是一个智能问答重写助手,将用户问题和已知的软件名称重写为结构化、规范表达,符合以下范式:
|
||||
1. 【软件名】【其他】
|
||||
|
||||
# 例子
|
||||
输入:D3软件二次运输怎么计取
|
||||
输出:【博微配网工程计价通D3软件】【二次运输怎么计取】
|
||||
|
||||
输入:怎么添加特征段
|
||||
输出:【】【怎么添加特征段】
|
||||
|
||||
输入:西藏造价软件Z1
|
||||
输出:【西藏造价软件Z1】【】
|
||||
|
||||
请根据以下用户问题进行规范表达,不要有任何解释说明:
|
||||
|
||||
软件名称:{soft_name}
|
||||
用户问题:{query}
|
||||
|
||||
结构化问题:
|
||||
""".strip()
|
||||
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
|
||||
def mutil_text_rewrite():
|
||||
PromptTemplate = """
|
||||
你是一个智能问答重写助手,根据聊天记录进行结构化、规范表达的重写,符合以下范式:
|
||||
1. 【软件名】【其他】
|
||||
|
||||
# 例子
|
||||
输入:
|
||||
user: 西藏造价软件Z1
|
||||
assistant: 好的,具体软件是【西藏造价软件Z1】, 请补充具体的需求
|
||||
user: 进行费用统计
|
||||
输出:【西藏Z1软件】【进行费用统计】
|
||||
|
||||
请根据以下用户问题进行规范表达,不要有任何解释说明:
|
||||
|
||||
聊天记录:{history}
|
||||
|
||||
结构化问题:
|
||||
""".strip()
|
||||
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
|
||||
def software_judge():
|
||||
# 费用计算另处理
|
||||
PromptTemplate1 = """
|
||||
你根据用户输入的线索来选择返回输出:
|
||||
|
||||
1. 西藏造价软件Z1
|
||||
2. 新型储能计价通C1
|
||||
3. 技改检修计价通T1
|
||||
4. 博微配网工程计价通D3软件
|
||||
|
||||
用户输入:"{query}"
|
||||
|
||||
输出格式:str类型
|
||||
|
||||
注意:
|
||||
1. 你的回复答案一定是[西藏造价软件Z1、新型储能计价通C1、技改检修计价通T1、博微配网工程计价通D3软件]之一,不要有其他回答,不要解释说明
|
||||
"""
|
||||
|
||||
Prompt = ChatPromptTemplate.from_template(PromptTemplate1)
|
||||
|
||||
Chain = Prompt | deep_v3 | StrOutputParser()
|
||||
# Chain = Prompt | llm | StrOutputParser()
|
||||
|
||||
return Chain
|
||||
|
||||
|
||||
|
||||
+3
-1
@@ -118,6 +118,7 @@ async def analyze_input(data: QueryRequest):
|
||||
query_kg = suffix_to_software
|
||||
|
||||
result = chain_suffix_answers.invoke({"query": input_str, "kg": query_kg})
|
||||
# return {"response": f"booway助手:{result}"}
|
||||
return {"response": f"booway助手:{result}",
|
||||
"nlu_info": nlu_info}
|
||||
|
||||
@@ -156,7 +157,8 @@ async def analyze_input(data: QueryRequest):
|
||||
|
||||
nlu_info.retrieve_keywords = get_keywords_v3(nlu_info.rewrite)
|
||||
|
||||
return nlu_info
|
||||
return {"response": "success",
|
||||
"nlu_info": nlu_info}
|
||||
|
||||
# 可选:本地调试入口
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user