From d8f127aeb458ee7b1bb378851030ad5b86042259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E9=9B=A8?= Date: Thu, 5 Jun 2025 20:35:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BB=A3=E7=A0=81-=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 6 ++--- yj_room_agent/LLM/ai_service.py | 44 +++++++++++++++++++++++---------- yj_room_agent/urls.py | 2 +- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.env b/.env index 36e5d4c..6a846dc 100644 --- a/.env +++ b/.env @@ -1,9 +1,9 @@ #api key -MODEL_API_KEY=sk-9nng4v6qsdiw42r6d3re4nym15hiti29 +MODEL_API_KEY=sk-42b5a1479b3b4a1b8176c13c6e2249f0 #模型地址 -MODEL_BASE_URL=https://gateout.yced.com.cn/v1 +MODEL_BASE_URL=https://api.deepseek.com #模型名称 -MODEL_NAME=deepseek +MODEL_NAME=deepseek-chat #放行host地址 DJANGO_ALLOWED_HOSTS=192.168.237.130,127.0.0.1,10.212.27.4 #是否开启debug模式 diff --git a/yj_room_agent/LLM/ai_service.py b/yj_room_agent/LLM/ai_service.py index 47b8052..9bc8fa1 100644 --- a/yj_room_agent/LLM/ai_service.py +++ b/yj_room_agent/LLM/ai_service.py @@ -10,6 +10,11 @@ MODEL_NAME = config('MODEL_NAME', default="") BASE_URL = config('MODEL_BASE_URL', default="") +def parse_time(time_str: str) -> int: + timestamp = datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S").timestamp() + return int(timestamp) + + def is_json(myjson): try: json_object = json.loads(myjson) @@ -41,6 +46,7 @@ def query_room_info(params) -> str: return str(result) + def book_room(data: dict, params: dict) -> str: # resp = requests.post('http://127.0.0.1:8000/myapi/room/', data) """ @@ -57,14 +63,25 @@ def book_room(data: dict, params: dict) -> str: :params: ytenantId (not null) :return: """ + new_data = { + "startDateTime": parse_time(data["start_time"]), + "endDateTime": parse_time(data["end_time"]), + "qzId": "", + "content": "", + "subject": "", + "ownnerId": "15764457249", + "meetingroomId": data["room_id"], + "personAmount": data["capacity"], + } tenant_id = params.get('ytenantId', None) if not tenant_id: raise Exception("ytenantId 不能为空") access_token = getinfo.get_access_token(tenant_id) params['access_token'] = access_token - content = getinfo.book_meeting_room(params, data) + content = getinfo.book_meeting_room(params, new_data) return content + def query_booking_info(params: dict): tenant_id = params.get('ytenantId', None) access_token = getinfo.get_access_token(tenant_id) @@ -97,17 +114,17 @@ def build_prompt(params): time_now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # 增强提示词模板 template = f"""你是一个专业的OA会议预订助手,请根据以下信息提供服务: - 现在时间是 :{time_now} - 可用会议室信息: - {room_info} - 请按以下步骤处理: - 1. 解析用户预订需求(时间、人数、设备要求等) - 2. 根据可用会议室列表推荐合适选项,推荐选项时不需要提取用户预订信息,待用户确认是再提取。按照正常自然语言对话返回 - 3. 如果用户确定要预订某间会议室,而不是在询问合适会议室时,请帮根据上下文我提取用户预订信息,预订时间等信息并返回,结果请只返回json格式得预订信息且不需要包含多余的描述内容以及标签等,输出结果示例如下: - {for_mart_str} - 4. 当用户再次发起预订会议室时,不要直接提取用户的预订信息而是请重新查看现有会议室的最新情况,基于用户需求给用户推荐合理的会议室,推荐选项时不需要提取用户预订信息,不要返回json数据,待用户确认是再提取。按照正常自然语言对话返回 - 5. 如果用户需要解析调用预订会议室返回的结果,请解析用户提供的相应结果信息,并给予自然语言反馈,不需要返回json数据 - 6. 用户其他需求,请按照自然语言对话返回 + 现在时间是 :{time_now} + 可用会议室信息: + {room_info} + 请按以下步骤处理: + 1. 解析用户预订需求(时间、人数、设备要求等) + 2. 根据可用会议室列表推荐合适选项,推荐选项时,没有用户明确需要预订哪间会议室时,不需要提取用户预订信息,直接返回推荐会议室列表,按照自然语言返回即可 + 3. 只有当用户确定要预订某间会议室,而不是在询问合适会议室时,请根据上下文提取用户预订信息,预订时间等信息并返回而不是直接提示预订成功,结果请只返回json格式得预订信息且不需要包含多余的描述内容以及标签等,输出结果示例如下: + {for_mart_str} + 4. 如果当用户再次请求预订会议室时,请不要按照json格式直接提取用户的预订信息,而是请重新查看现有会议室的最新情况,基于用户需求给用户推荐合理的会议室,推荐选项时不需要提取用户预订信息按照json格式返回,只需要重新给用户推荐选项即可,按照正常自然语言对话返回 + 5. 如果用户需要解析调用预订会议室返回的结果,请解析用户提供的相应结果信息,并给予自然语言反馈,不需要返回json数据 + 6. 用户其他需求,请按照自然语言对话返回 """ return template @@ -190,8 +207,9 @@ def process_chat(user_id: str, user_input: str, params: dict): resp = call_openai_api(model=MODEL_NAME, system_prompt=prompt, user_query=user_input, api_key=config('MODEL_API_KEY'), history=history) + print(resp) content = resp["choices"][0]["message"]["content"] - reasoning_content = resp["choices"][0]["message"]["reasoning_content"] + reasoning_content = resp["choices"][0]["message"].get('reasoning_content') print(content) new_content = check_and_process_think(content=content) if 'json' in new_content or is_json(new_content): diff --git a/yj_room_agent/urls.py b/yj_room_agent/urls.py index afb526b..4855807 100644 --- a/yj_room_agent/urls.py +++ b/yj_room_agent/urls.py @@ -21,7 +21,7 @@ from yj_room_agent import views urlpatterns = [ path('admin/', admin.site.urls), path('test/', views.hello, name='hello'), - path('chat/', views.room_chat), + path('book_room/', views.room_chat, name='room_chat'), path('getMeetingType/', views.query_meeting_type), path('getMeeting/', views.query_meeting), path('getMeetingBookingDetails/', views.query_meetingooking_info),