feat:优化流程
This commit is contained in:
@@ -190,7 +190,7 @@ def book_meeting(params: dict, data: dict) -> str:
|
||||
"""
|
||||
|
||||
new_data = {
|
||||
"subject": params.get('subject',"会议主题"),
|
||||
"subject": data["subject"],
|
||||
"meetingRoomId": data["room_id"],
|
||||
"meetingRoomName": "会议室名称",
|
||||
"meetingDateTimeStamp": int(datetime.now().timestamp() * 1000),
|
||||
@@ -276,6 +276,7 @@ def cancel_meeting(params: dict) -> str:
|
||||
|
||||
def check_and_process_think(content: str) -> str:
|
||||
filtered_text = re.sub(r"<think\b[^>]*>.*?</think>", '', content, flags=re.DOTALL)
|
||||
filtered_text = re.sub(r'^.*?</think>', '', filtered_text, flags=re.DOTALL)
|
||||
return filtered_text
|
||||
|
||||
|
||||
@@ -292,6 +293,7 @@ def build_prompt(params):
|
||||
{
|
||||
"room_id":"11", //会议室ID
|
||||
"capacity":20,
|
||||
"subject":"会议主题"
|
||||
"start_time":"2025-06-04 09:30:10",
|
||||
"end_time":"2025-06-04 12:30:10",
|
||||
"user_confirm":1 //用户是否确认,
|
||||
@@ -334,15 +336,18 @@ def build_prompt(params):
|
||||
请按以下步骤处理:
|
||||
1. 解析用户预订需求(时间、人数、设备要求等),name或typeName字段里面可能包含了区域信息,注意根据地理信息过滤
|
||||
2. 当用户需要帮忙预订会议室时,根据可用会议室列表推荐合适选项,推荐选项时,没有用户明确需要预订哪间会议室时,不需要提取用户预订信息,直接返回推荐会议室列表,按照自然语言返回即可
|
||||
3. 只有当用户确定要预订某间会议室,而不是在询问合适会议室时,请根据上下文提取用户预订信息,预订时间等信息并返回而不是直接提示预订成功,结果请只返回json格式得预订信息且不需要包含多余的描述内容以及<think>标签等,输出结果示例如下:
|
||||
3. 只有当用户确定要预订某间会议室,而不是在询问合适会议室时,请根据上下文提取用户预订信息,预订时间,会议主题等信息并返回,如果没有会议主题则默认主题为'默认主题',最后提示用户确认预定信息是否准确,输出结果示例如下:
|
||||
{book_for_mart_str}
|
||||
4. 用户需要查询已有的会议室预订情况或者预订情况时,结果请按照以下的json示例返回,不需要返回其他的多余数据,返回示例如下:
|
||||
{qry_book_info_for_mart_str}
|
||||
5. 如果用户需要取消预订会议时,请根据上下文提取用户取消信息,如果没有获取到会议号ID,请先提示用户提供会议号ID。提取结果请按照以下的json示例返回,不需要返回其他的多余数据,返回示例如下:
|
||||
{cancel_meeting_info_for_mart_str}
|
||||
5. 当用户需要取消预订会议,分两种情况:
|
||||
(1)用户未提供要取消的会议号ID,返回已预定会议情况供用户选择,切记禁止使用历史对话中的旧数据!,结果请返回json格式,返回示例如下:
|
||||
{qry_book_info_for_mart_str}
|
||||
(2)用户给出了需要取消的会议号ID,如果用户未从已预定会议列表中进行选择,则提示用户选择,如果用户已选择则提取会议ID,并提示用户是否确认取消,取消示例如下:
|
||||
{cancel_meeting_info_for_mart_str}
|
||||
6. 如果用户需要修改已有的会议时,请根据上下文提取用户修改预订信息,如果没有获取到会议号ID,开始时间,结束时间,请先用自然对话提示用户提供相应的信息而不是提取json数据。提取结果请按照以下的json示例返回,不需要返回其他的多余数据,返回示例如下:
|
||||
{edit_meeting_info_for_mart_str}
|
||||
7. 如果当用户再次请求预订会议室时,请不要按照json格式直接提取用户的预订信息,而是请重新查看现有会议室的最新情况,基于用户需求给用户推荐合理的会议室,推荐选项时不需要提取用户预订信息按照json格式返回,只需要重新给用户推荐选项即可,按照正常自然语言对话返回
|
||||
7. 如果当用户再次请求预订会议室时,请不要按照json格式直接提取用户预订信息,而是请重新查看现有会议室的最新情况,基于用户需求给用户推荐合理的会议室,推荐选项时不需要提取用户预订信息按照json格式返回,只需要重新给用户推荐选项即可,按照正常自然语言对话返回
|
||||
8. 如果用户需要解析调用API返回的结果,请解析用户提供的相应结果信息,并给予自然语言反馈,不需要返回json数据
|
||||
9. 用户其他需求,请按照自然语言对话返回
|
||||
|
||||
@@ -558,7 +563,8 @@ def process_chat(user_id: str, user_input: str, params: dict):
|
||||
logger.info(f"process chat content is : {content}")
|
||||
new_content = check_and_process_think(content=content)
|
||||
if 'json' in new_content or is_json(new_content):
|
||||
new_content = new_content.replace("json", '')
|
||||
# new_content = new_content.replace("json", '')
|
||||
new_content = new_content.split('```json')[-1].split('```')[0]
|
||||
new_content = new_content.replace("`", '')
|
||||
data = json.loads(new_content)
|
||||
fun_name = data.get("func_name", None)
|
||||
@@ -593,11 +599,14 @@ def process_chat(user_id: str, user_input: str, params: dict):
|
||||
temperature=config("MODEL_TEMPERATURE", cast=float, default=0.5),
|
||||
)
|
||||
content = resp["choices"][0]["message"]["content"]
|
||||
new_content = check_and_process_think(content)
|
||||
add_message_async(dialog_manager, user_id, 'assistant', content)
|
||||
return {'response': resp}
|
||||
return {'response': new_content}
|
||||
else:
|
||||
|
||||
add_message_async(dialog_manager, user_id, 'assistant', content)
|
||||
if reasoning_content:
|
||||
add_message_async(dialog_manager, user_id, 'assistant', reasoning_content)
|
||||
return {'response': resp}
|
||||
# result = check_and_process_think(content)
|
||||
# new_content = new_content.split('```json')[-1].split('```')[0]
|
||||
return {'response': new_content}
|
||||
|
||||
@@ -5,7 +5,9 @@ import requests
|
||||
from decouple import config
|
||||
from yj_room_agent.yj_logger import logger
|
||||
from copy import deepcopy
|
||||
import urllib3
|
||||
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
APPKEY = config('APPKEY', default="")
|
||||
APPSECRET = config('APPSECRET', default="")
|
||||
|
||||
@@ -22,7 +24,7 @@ CANCEL_MEETING = config('CANCEL_MEETING', default="")
|
||||
# CANCEL_MEETING2 = config('CANCEL_MEETING2', default="")
|
||||
EDIT_MEETING = config('EDIT_MEETING', default="")
|
||||
DEFAULT_HEADER = {'Content-Type': 'application/json'}
|
||||
page_size = config('DEFAULT_PAGESIZE', default=800, cast=int)
|
||||
page_size = config('DEFAULT_PAGESIZE', default=100, cast=int)
|
||||
|
||||
|
||||
def check_required_params(required_fields, params):
|
||||
@@ -69,7 +71,7 @@ def get_access_token(tenant_id):
|
||||
raise Exception("该租户无法获取中心域名=>detail error: " + f"{str(ex)}")
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
respones = requests.get(url=request_url, params=params, headers=headers)
|
||||
respones = requests.get(url=request_url, params=params, headers=headers,verify=False)
|
||||
logger.info("Get token response => {0}".format(respones))
|
||||
logger.info(f"status_code: {respones.status_code}")
|
||||
if respones.status_code == 200:
|
||||
@@ -80,7 +82,7 @@ def get_access_token(tenant_id):
|
||||
else:
|
||||
logger.error(f"请求失败 状态码: {respones.status_code}")
|
||||
raise Exception(f"请求获取token失败 status_code: {respones.status_code} "
|
||||
f"message: {respones}")
|
||||
f"message: {respones.content}")
|
||||
|
||||
|
||||
'''
|
||||
@@ -95,7 +97,7 @@ def get_domain(params):
|
||||
logger.info("url => {0} params = > {1}".format(request_url,params))
|
||||
respones = requests.get(url=request_url,
|
||||
params=params,
|
||||
headers=headers)
|
||||
headers=headers,verify=False)
|
||||
|
||||
logger.info("Get domain respones => {0}".format(respones))
|
||||
if respones.status_code == 200:
|
||||
@@ -109,7 +111,7 @@ def get_domain(params):
|
||||
else:
|
||||
logger.error(f"请求失败 状态码: {respones.status_code}")
|
||||
raise Exception(f"请求获取domain失败 status_code: {respones.status_code} "
|
||||
f"message: {respones}")
|
||||
f"message: {respones.content}")
|
||||
|
||||
|
||||
'''
|
||||
@@ -128,7 +130,7 @@ def query_meetingroom_type(params: dict):
|
||||
gateway_url, token_url = get_domain({"tenantId": tenant_id})
|
||||
request_url = gateway_url + QUERY_MEETING_ROOM_TYPE
|
||||
respones = requests.get(url=request_url, params=params,
|
||||
headers=header)
|
||||
headers=header,verify=False)
|
||||
logger.info("meeting type respones => {0}".format(respones.json()))
|
||||
|
||||
return respones.json()
|
||||
@@ -148,11 +150,11 @@ def query_meetingroom(params: dict):
|
||||
tenant_id = params.get("ytenantId", None)
|
||||
gateway_url, token_url = get_domain({"tenantId": tenant_id})
|
||||
request_url = gateway_url + QUERY_MEETING_ROOM
|
||||
logger.debug("request url => {0}".format(request_url))
|
||||
logger.info("request url => {0}".format(request_url))
|
||||
params['pageSize'] = page_size
|
||||
logger.debug("query_meetingroom params => {0}".format(params))
|
||||
respones = requests.get(url=request_url, params=params,
|
||||
headers=header)
|
||||
headers=header,verify=False)
|
||||
logger.info("meeting room respones => {0}".format(respones.json()))
|
||||
return respones.json()
|
||||
|
||||
@@ -173,12 +175,12 @@ def query_meetingbooking_info(params: dict):
|
||||
tenant_id = params.get("ytenantId", None)
|
||||
gateway_url, token_url = get_domain({"tenantId": tenant_id})
|
||||
request_url = gateway_url + QUERY_MEETINGBOOKING_INFO
|
||||
logger.debug("request url => {0}".format(request_url))
|
||||
params['pageSize'] = 800
|
||||
logger.info("request url => {0}".format(request_url))
|
||||
params['pageSize'] = page_size
|
||||
logger.debug("query_meetingbooking_info params => {0}".format(params))
|
||||
respones = requests.get(url=request_url, params=params,
|
||||
headers=header)
|
||||
logger.info("meeting room respones => {0}".format(respones.json()))
|
||||
headers=header,verify=False)
|
||||
logger.debug("meeting room respones => {0}".format(respones.json()))
|
||||
return respones.json()
|
||||
|
||||
|
||||
@@ -200,8 +202,8 @@ def book_meeting(params: dict, data: dict):
|
||||
logger.debug("request url => {0}".format(request_url))
|
||||
logger.debug("book_meeting params => {0}".format(params))
|
||||
respones = requests.post(url=request_url, params=params,
|
||||
headers=header, data=json.dumps(data))
|
||||
logger.info("book meeting respones => {0}".format(respones.json()))
|
||||
headers=header, data=json.dumps(data),verify=False)
|
||||
logger.debug("book meeting respones => {0}".format(respones.json()))
|
||||
return respones.json()
|
||||
|
||||
|
||||
@@ -220,11 +222,11 @@ def edit_meeting_info(params: dict, data: dict):
|
||||
tenant_id = params.get("tenantId", None)
|
||||
gateway_url, token_url = get_domain({"tenantId": tenant_id})
|
||||
request_url = gateway_url + EDIT_MEETING
|
||||
logger.debug("request url => {0}".format(request_url))
|
||||
logger.info("request url => {0}".format(request_url))
|
||||
logger.debug("edit_meeting_info params => "
|
||||
"{0} data => {1}".format(params,data))
|
||||
respones = requests.post(url=request_url, params=params,
|
||||
headers=header, data=json.dumps(data))
|
||||
headers=header, data=json.dumps(data),verify=False)
|
||||
logger.info(f"edit_meeting_info respone is {respones} ")
|
||||
return respones.json()
|
||||
|
||||
@@ -249,6 +251,6 @@ def cancel_meeting(params: dict):
|
||||
params['isSendMail'] = True
|
||||
params['isSendMsg'] = True
|
||||
respones = requests.get(url=request_url, params=params,
|
||||
headers=header)
|
||||
headers=header,verify=False)
|
||||
logger.info("cancel meeting respones => {0}".format(respones))
|
||||
return respones.json()
|
||||
|
||||
Reference in New Issue
Block a user