feat:优化流程

This commit is contained in:
yujj128
2025-06-24 14:20:38 +08:00
parent 2913269558
commit 465c8cf181

View File

@@ -38,6 +38,7 @@ def is_json(myjson):
json_object = json.loads(myjson) json_object = json.loads(myjson)
return True return True
except ValueError: except ValueError:
print("json检查未通过")
return False return False
@@ -105,6 +106,7 @@ def query_room_info(data: dict, params: dict) -> str:
if (region in b.get('name', 'default') or region in b.get('typeName', 'default')) and b.get('capacity',0) >= data.get('capacity', 0): if (region in b.get('name', 'default') or region in b.get('typeName', 'default')) and b.get('capacity',0) >= data.get('capacity', 0):
new_list.append(b) new_list.append(b)
if len(new_list) >= DEFAULT_QUERY_SIZE: if len(new_list) >= DEFAULT_QUERY_SIZE:
print("regin--------------- {0}".format(new_list))
return json.dumps(new_list, ensure_ascii=False) return json.dumps(new_list, ensure_ascii=False)
else: else:
for b in result: for b in result:
@@ -112,6 +114,7 @@ def query_room_info(data: dict, params: dict) -> str:
new_list.append(b) new_list.append(b)
if len(new_list) >= DEFAULT_QUERY_SIZE: if len(new_list) >= DEFAULT_QUERY_SIZE:
return json.dumps(new_list, ensure_ascii=False) return json.dumps(new_list, ensure_ascii=False)
print("no regin-------------- {0}".format(new_list))
return json.dumps(new_list, ensure_ascii=False) return json.dumps(new_list, ensure_ascii=False)
@@ -303,7 +306,6 @@ def build_prompt(params):
qry_room_info_for_mart_str = ''' qry_room_info_for_mart_str = '''
{ {
"func_name":"query_room", "func_name":"query_room",
"capacity":20, //参会人数没有则返回0, "capacity":20, //参会人数没有则返回0,
"Region":"成都", //会议室所在区域没有则返回None "Region":"成都", //会议室所在区域没有则返回None
@@ -324,8 +326,7 @@ def build_prompt(params):
qry_book_info_for_mart_str = ''' qry_book_info_for_mart_str = '''
{ {
"func_name":"query_booking_info"
"func_name":"query_booking_info",
} }
''' '''
@@ -367,8 +368,8 @@ def build_prompt(params):
{book_for_mart_str} {book_for_mart_str}
3. 用户需要查询已有的会议室预订情况或者预订情况时,实时查询,禁止使用历史对话数据,结果请按照以下的json示例返回,不需要返回其他的多余数据,返回示例如下: 3. 用户需要查询已有的会议室预订情况或者预订情况时,实时查询,禁止使用历史对话数据,结果请按照以下的json示例返回,不需要返回其他的多余数据,返回示例如下:
{qry_book_info_for_mart_str} {qry_book_info_for_mart_str}
4. 如果用户需要取消预订会议时,请根据上下文提取用户取消信息,分两种情况: 4. 如果用户需要取消预订会议时,分两种情况:
(1)用户未提供要取消的会议号ID,返回已预定会议情况供用户选择,切记禁止使用历史对话中的旧数据!,查询调用如下: (1)用户未提供要取消的会议号ID,返回已预定会议情况供用户选择,实时查询,禁止使用历史对话中的旧数据!,查询调用如下:
{qry_book_info_for_mart_str} 返回格式规范:{return_booking_info_str} {qry_book_info_for_mart_str} 返回格式规范:{return_booking_info_str}
(2)用户给出了需要取消的会议号ID,如果用户从已预定会议列表中选择了需要取消的会议,则提取会议ID并提示用户是否确认取消取消示例如下: (2)用户给出了需要取消的会议号ID,如果用户从已预定会议列表中选择了需要取消的会议,则提取会议ID并提示用户是否确认取消取消示例如下:
{cancel_meeting_info_for_mart_str} {cancel_meeting_info_for_mart_str}
@@ -616,7 +617,8 @@ def process_chat(user_id: str, user_input: str, params: dict):
# 触发函数调用------ # 触发函数调用------
logger.info(f"触发系统函数调用==>:{fun_name}") logger.info(f"触发系统函数调用==>:{fun_name}")
book_promot = func(data=data, params=params) book_promot = func(data=data, params=params)
dialog_manager.add_message(user_id, 'user', book_promot) logger.info("test point book_promot => {0} ".format(book_promot))
# dialog_manager.add_message(user_id, 'user', book_promot)
else: else:
book_promot = f''' book_promot = f'''
@@ -631,6 +633,7 @@ def process_chat(user_id: str, user_input: str, params: dict):
请帮用户解析结果,并根据结果给予用户相应自然语言反馈 请帮用户解析结果,并根据结果给予用户相应自然语言反馈
''' '''
new_history = [] new_history = []
logger.info("test point completed the function call ")
query_history = dialog_manager.get_history(user_id) query_history = dialog_manager.get_history(user_id)
new_history.extend(query_history) new_history.extend(query_history)
resp = call_openai_api(model=MODEL_NAME, user_query=book_promot, resp = call_openai_api(model=MODEL_NAME, user_query=book_promot,
@@ -640,11 +643,12 @@ def process_chat(user_id: str, user_input: str, params: dict):
temperature=config("MODEL_TEMPERATURE", cast=float, default=0.5), temperature=config("MODEL_TEMPERATURE", cast=float, default=0.5),
) )
content = resp["choices"][0]["message"]["content"] content = resp["choices"][0]["message"]["content"]
logger.info("final content => {0}".format(content))
new_content = check_and_process_think(content) new_content = check_and_process_think(content)
add_message_async(dialog_manager, user_id, 'assistant', content) add_message_async(dialog_manager, user_id, 'assistant', content)
return {'response': new_content} return {'response': new_content}
else: else:
logger.info("no func ")
add_message_async(dialog_manager, user_id, 'assistant', content) add_message_async(dialog_manager, user_id, 'assistant', content)
if reasoning_content: if reasoning_content:
add_message_async(dialog_manager, user_id, 'assistant', reasoning_content) add_message_async(dialog_manager, user_id, 'assistant', reasoning_content)