增加商机分析信息追加功能
This commit is contained in:
parent
92e9fdb7dc
commit
f88d23ed4a
|
|
@ -126,6 +126,29 @@ def analysis_stream():
|
||||||
message = data.get('message', '')
|
message = data.get('message', '')
|
||||||
knowledge_id = data.get('knowledge_id', '')
|
knowledge_id = data.get('knowledge_id', '')
|
||||||
|
|
||||||
|
intent_categories =["analyze_sales","provide_sales_info"]
|
||||||
|
|
||||||
|
classification_result_str = zhipu_alltool_service.func_call_classify(message, intent_categories)
|
||||||
|
print(f'classification_result: {classification_result_str}')
|
||||||
|
classification_result = json.loads(classification_result_str)
|
||||||
|
|
||||||
|
|
||||||
|
additional_business_info = ""
|
||||||
|
if classification_result.get('category') == 'analyze_sales':
|
||||||
|
# do analyze sales as before
|
||||||
|
pass
|
||||||
|
elif classification_result.get('category') == 'provide_sales_info':
|
||||||
|
contain_project_info = zhipu_alltool_service.func_call_yes_or_no(message, "是否包含项目信息")
|
||||||
|
print(f'contain_project_info: {contain_project_info}')
|
||||||
|
contain_project_info = json.loads(contain_project_info)
|
||||||
|
if contain_project_info.get('answer') == 'yes':
|
||||||
|
additional_business_info = message
|
||||||
|
else:
|
||||||
|
return "请在补充信息中包含项目信息"
|
||||||
|
else:
|
||||||
|
return "输入意图判断不明,请明确意图"
|
||||||
|
|
||||||
|
|
||||||
# 获取business info
|
# 获取business info
|
||||||
prompt_get_business_info = f"""
|
prompt_get_business_info = f"""
|
||||||
请根据用户提供的如下信息,查找相关的 '当前详细状态及Close节奏','Sales stage' 信息,并返回给用户:
|
请根据用户提供的如下信息,查找相关的 '当前详细状态及Close节奏','Sales stage' 信息,并返回给用户:
|
||||||
|
|
@ -141,6 +164,15 @@ def analysis_stream():
|
||||||
prompt_analysis = f"""
|
prompt_analysis = f"""
|
||||||
请根据查询到的上述商机信息:
|
请根据查询到的上述商机信息:
|
||||||
{business_info}
|
{business_info}
|
||||||
|
"""
|
||||||
|
|
||||||
|
if additional_business_info and additional_business_info != "":
|
||||||
|
prompt_analysis += f"""
|
||||||
|
同时,请考虑以下额外的商机信息:
|
||||||
|
{additional_business_info}
|
||||||
|
"""
|
||||||
|
|
||||||
|
prompt_analysis += f"""
|
||||||
根据如下各销售阶段的销售阶段任务、销售关键动作、阶段转化标准:
|
根据如下各销售阶段的销售阶段任务、销售关键动作、阶段转化标准:
|
||||||
{analysis_rule}
|
{analysis_rule}
|
||||||
结合上述商机信息的对应阶段,分析并判断其销售动作是否完成了前一阶段的准出标准,以及是否支持将销售阶段转化到当前阶段
|
结合上述商机信息的对应阶段,分析并判断其销售动作是否完成了前一阶段的准出标准,以及是否支持将销售阶段转化到当前阶段
|
||||||
|
|
@ -149,6 +181,9 @@ def analysis_stream():
|
||||||
3. **销售动作与销售阶段的关系**
|
3. **销售动作与销售阶段的关系**
|
||||||
4. **判断结果**
|
4. **判断结果**
|
||||||
5. **销售阶段分析报告**
|
5. **销售阶段分析报告**
|
||||||
|
|
||||||
|
如果用户在下面的输入指令中指定了只需要上面所列的某个或某几个分析,请只输出指定分析的结果,如果未指定,请输出所有分析结果
|
||||||
|
{message}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def event_stream():
|
def event_stream():
|
||||||
|
|
@ -178,6 +213,15 @@ def alltool_classify_non_stream():
|
||||||
print(f'response: {response}')
|
print(f'response: {response}')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@zhipu_controller.route('/zhipu/alltool/yes-no/non-stream', methods=['POST'])
|
||||||
|
def alltool_classify_yes_no_non_stream():
|
||||||
|
data = request.json
|
||||||
|
message = data.get('message', '')
|
||||||
|
question = data.get('question', '')
|
||||||
|
response = zhipu_alltool_service.func_call_yes_or_no(message,question)
|
||||||
|
print(f'response: {response}')
|
||||||
|
return response
|
||||||
|
|
||||||
@zhipu_controller.route('/zhipu/file/submit', methods=['POST'])
|
@zhipu_controller.route('/zhipu/file/submit', methods=['POST'])
|
||||||
def submit_report():
|
def submit_report():
|
||||||
data = request.json
|
data = request.json
|
||||||
|
|
@ -191,3 +235,4 @@ def submit_report():
|
||||||
def get_file_list():
|
def get_file_list():
|
||||||
file_list = zhipu_file_service.get_file_list()
|
file_list = zhipu_file_service.get_file_list()
|
||||||
return file_list
|
return file_list
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,11 @@ class ZhipuAlltoolService:
|
||||||
self.app_secret_key = "d54f764a1d67c17d857bd3983b772016.GRjowY0fyiMNurLc"
|
self.app_secret_key = "d54f764a1d67c17d857bd3983b772016.GRjowY0fyiMNurLc"
|
||||||
logger.info("ZhipuAlltoolService initialized with model: %s", self.model_name)
|
logger.info("ZhipuAlltoolService initialized with model: %s", self.model_name)
|
||||||
|
|
||||||
def func_call_classify(self, message):
|
def func_call_classify(self, message, categories:list=None):
|
||||||
logger.info("Starting web_search call")
|
logger.info("Starting func_call_classify call")
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
default_categories = ["web_search", "retrive_knowledge", "generate_report", "update_report", "clear_report"]
|
||||||
|
categories = categories if categories else default_categories
|
||||||
client = ZhipuAI(api_key=self.app_secret_key)
|
client = ZhipuAI(api_key=self.app_secret_key)
|
||||||
tools = [
|
tools = [
|
||||||
{
|
{
|
||||||
|
|
@ -25,7 +27,8 @@ class ZhipuAlltoolService:
|
||||||
"properties": {
|
"properties": {
|
||||||
"category": {
|
"category": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "用户的意图有以下选项:web_search,retrive_knowledge,generate_report,update_report,clear_report",
|
# "description": "用户的意图有以下选项:web_search,retrive_knowledge,generate_report,update_report,clear_report",
|
||||||
|
"description": "用户的意图有以下选项:" + ",".join(categories)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["category"],
|
"required": ["category"],
|
||||||
|
|
@ -52,6 +55,49 @@ class ZhipuAlltoolService:
|
||||||
logger.error("Error in web_search call: %s", str(e))
|
logger.error("Error in web_search call: %s", str(e))
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
def func_call_yes_or_no(self, message, question):
|
||||||
|
logger.info("Starting func_call_yes_or_no call")
|
||||||
|
|
||||||
|
client = ZhipuAI(api_key=self.app_secret_key)
|
||||||
|
tools = [
|
||||||
|
{
|
||||||
|
"type": "function",
|
||||||
|
"function": {
|
||||||
|
"name": "classify_user_input",
|
||||||
|
"description": "根据用户输入的信息和问题,回答yes或者no",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"answer": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "判断结果有以下选项:yes,no"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["answer"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
messages = [
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": f"{question}:{message}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
try:
|
||||||
|
response = client.chat.completions.create(
|
||||||
|
model="glm-4-flash", # 填写需要调用的模型名称
|
||||||
|
messages= messages,
|
||||||
|
tools= tools,
|
||||||
|
tool_choice="auto"
|
||||||
|
)
|
||||||
|
print(response)
|
||||||
|
return response.choices[0].message.tool_calls[0].function.arguments
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Error in web_search call: %s", str(e))
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def web_search_sse(self, message):
|
def web_search_sse(self, message):
|
||||||
logger.info("Starting web_search_sse call")
|
logger.info("Starting web_search_sse call")
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue