feat:日志整改
This commit is contained in:
3
.env
3
.env
@@ -5,11 +5,12 @@ MODEL_BASE_URL=https://api.deepseek.com
|
||||
#模型名称
|
||||
MODEL_NAME=deepseek-chat
|
||||
#模型活跃度
|
||||
MODEL_TEMPERATURE=1.0
|
||||
MODEL_TEMPERATURE=0.8
|
||||
#放行host地址
|
||||
DJANGO_ALLOWED_HOSTS=192.168.237.130,127.0.0.1,10.212.26.130
|
||||
#是否开启debug模式
|
||||
DJANGO_DEBUG_ENABLE=True
|
||||
DJANGO_LOG_LEVEL=INFO
|
||||
|
||||
DEFAULT_AUTH_URL = 'https://oa-pre.yced.com.cn/iuap-api-auth'
|
||||
DEFAULT_GATEWAY_URL = 'https://oa-pre.yced.com.cn/iuap-api-gateway '
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
from threading import Lock
|
||||
from datetime import datetime, timedelta
|
||||
import requests, json
|
||||
from django.db.models.expressions import result
|
||||
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from .openai_client import call_openai_api
|
||||
from decouple import config
|
||||
import threading, re
|
||||
from ..tools import getinfo, params_filter
|
||||
import logging
|
||||
|
||||
MODEL_NAME = config('MODEL_NAME', default="")
|
||||
BASE_URL = config('MODEL_BASE_URL', default="")
|
||||
|
||||
logger = logging.getLogger('django')
|
||||
|
||||
'''
|
||||
解析时间,转化为时间戳
|
||||
'''
|
||||
@@ -85,9 +87,10 @@ def query_room_info(params: dict) -> str:
|
||||
pageNum
|
||||
pageSize
|
||||
"""
|
||||
print("当前params : {0}".format(params))
|
||||
logger.info(f"当前params : {params}")
|
||||
tenant_id = params.get('tenantId', None)
|
||||
if not tenant_id:
|
||||
logger.error("query_room_info ,tenantId is None")
|
||||
raise Exception("tenantId 不能为空")
|
||||
|
||||
access_token = getinfo.get_access_token(tenant_id)
|
||||
@@ -261,7 +264,7 @@ def cancel_meeting(params: dict) -> str:
|
||||
}
|
||||
:return:
|
||||
"""
|
||||
print("当前params : {0}".format(params))
|
||||
logger.info(f"当前params : {params}")
|
||||
tenant_id = params.get('tenantId', None)
|
||||
if not tenant_id:
|
||||
raise Exception("tenantId 不能为空")
|
||||
@@ -350,7 +353,7 @@ class DialogManager:
|
||||
return self.dialogs.get(session_id, [])
|
||||
|
||||
def clear_history(self):
|
||||
print('开始定时执行清理历史消息')
|
||||
logger.info('----开始定时执行清理历史消息------')
|
||||
self.dialogs.clear()
|
||||
|
||||
def add_message(self, session_id, role, content):
|
||||
@@ -398,7 +401,7 @@ class DialogManager:
|
||||
response = requests.post(f"{BASE_URL}/chat/completions", data=json.dumps(payload, ensure_ascii=False),
|
||||
timeout=1000, headers=headers, verify=False)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
logger.info(response.text)
|
||||
return response.json().get("response", "摘要生成失败")
|
||||
|
||||
|
||||
@@ -501,10 +504,10 @@ 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, temperature=config("MODEL_TEMPERATURE", cast=float, default=0.5))
|
||||
print(resp)
|
||||
|
||||
content = resp["choices"][0]["message"]["content"]
|
||||
reasoning_content = resp["choices"][0]["message"].get('reasoning_content')
|
||||
print(content)
|
||||
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", '')
|
||||
@@ -517,6 +520,7 @@ def process_chat(user_id: str, user_input: str, params: dict):
|
||||
func = func_tion_call_map.get(fun_name, None)
|
||||
if func:
|
||||
# 触发函数调用------
|
||||
logger.info(f"触发系统函数调用==>:{fun_name}")
|
||||
book_promot = func(data=data, params=params)
|
||||
|
||||
else:
|
||||
@@ -538,6 +542,7 @@ def process_chat(user_id: str, user_input: str, params: dict):
|
||||
api_key=config('MODEL_API_KEY'),
|
||||
history=new_history,
|
||||
system_prompt='',
|
||||
temperature=config("MODEL_TEMPERATURE", cast=float, default=0.5),
|
||||
)
|
||||
content = resp["choices"][0]["message"]["content"]
|
||||
add_message_async(dialog_manager, user_id, 'assistant', content)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -9,7 +9,8 @@ https://docs.djangoproject.com/en/5.2/topics/settings/
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.2/ref/settings/
|
||||
"""
|
||||
|
||||
import os.path
|
||||
from email.policy import default
|
||||
from pathlib import Path
|
||||
|
||||
from decouple import config, Csv
|
||||
@@ -116,21 +117,40 @@ STATIC_URL = 'static/'
|
||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
# DEFAULT_AUTH_URL = 'https://oa-dev.yced.com.cn/iuap-api-auth'
|
||||
# DEFAULT_GATEWAY_URL = 'https://oa-dev.yced.com.cn/iuap-api-gateway '
|
||||
# TEMP_TENANT_ID = 'pr3rl2oj'
|
||||
# APPKEY = 'e5d615eb169944abb3a1db5bd699ca65'
|
||||
# APPSECRET = '84bb250c995c6161a97aebc2296abe558f6551ac'
|
||||
# DEFAULT_HEADER = {'Content-Type': 'application/json'}
|
||||
#
|
||||
# # General Purpose Interface
|
||||
# TOKEN_INTF = '/open-auth/selfAppAuth/getAccessToken'
|
||||
# GATEWAY_INTF = '/open-auth/dataCenter/getGatewayAddress'
|
||||
# # Service Interface
|
||||
# QUERY_MEETING_ROOM_TYPE = ['GET', '/yonbip/uspace/external/access/getMeetingRoomType']
|
||||
# QUERY_MEETING_ROOM = ['GET', '/yonbip/uspace/external/access/getMeetingRoom']
|
||||
# QUERY_MEETINGBOOKING_INFO = ['GET', '/yonbip/uspace/external/access/getDestineInformation']
|
||||
# BOOK_MEETING_ROOM = ['POST', '/yonbip/uspace/destine/Meeting']
|
||||
# CANCEL_MEETING = ['POST', '/yonbip/uspace/cancel/Meeting']
|
||||
# BOOKMEETING = ['POST', '/yonbip/uspace/external/access/book']
|
||||
|
||||
LOGGING = {
|
||||
'version': 1, # 配置版本,固定为 1
|
||||
'disable_existing_loggers': False, # 禁用默认日志器
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format':'%(asctime)s [%(threadName)s:%(thread)d] [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s'
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'console': { # 控制台日志处理器
|
||||
'level': 'INFO', # 日志级别设置为 DEBUG
|
||||
'class': 'logging.StreamHandler', # 使用 StreamHandler 输出到控制台
|
||||
'formatter': 'verbose'
|
||||
},
|
||||
'file': { # 文件日志处理器
|
||||
'level': 'INFO', # 日志级别设置为 DEBUG
|
||||
'class': 'logging.handlers.RotatingFileHandler', # 使用 FileHandler 输出到文件
|
||||
'filename': os.path.join(BASE_DIR,"logs/yj_room_agent.log"), # 日志文件名
|
||||
'maxBytes': 1024 * 1024 * 50,
|
||||
'backupCount': 5, # 最多保留5个备份文件,
|
||||
'formatter': 'verbose'
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'django': { # 默认的 Django 日志器
|
||||
'handlers': ["console", "file"], # 输出到控制台
|
||||
'level': config('DJANGO_LOG_LEVEL',default='INFO',cast=str), # 日志级别设置为 DEBUG
|
||||
'propagate': True, # 传播日志给父日志记录器
|
||||
},
|
||||
'myapp': { # 自定义的应用日志器
|
||||
"handlers": ['console', 'file'], # 输出到文件
|
||||
'level': config('DJANGO_LOG_LEVEL',default='INFO',cast=str), # 日志级别设置为 DEBUG
|
||||
'propagate': True, # 传播日志给父日志记录器
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from yonbip_open_api_sdk import sign_opt, request_opt
|
||||
from yj_room_agent import settings
|
||||
import requests
|
||||
import urllib
|
||||
from decouple import config
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger('django')
|
||||
|
||||
APPKEY = config('APPKEY', default="")
|
||||
APPSECRET = config('APPSECRET', default="")
|
||||
@@ -24,7 +23,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', 800)
|
||||
page_size = config('DEFAULT_PAGESIZE', default=800, cast=int)
|
||||
|
||||
|
||||
def check_required_params(required_fields, params):
|
||||
@@ -58,39 +57,42 @@ def get_access_token(tenant_id):
|
||||
params = {}
|
||||
params['timestamp'] = str(int(time.time() * 1000))
|
||||
params['appKey'] = APPKEY
|
||||
print(params)
|
||||
logger.info(f'get_access_token param is: {params}')
|
||||
app_secret = APPSECRET
|
||||
sort_param = sign_opt.opt_sort_data(params)
|
||||
print("sort_param", sort_param)
|
||||
logger.info(f"sort_param is {sort_param}")
|
||||
signature = sign_opt.opt_sha256(app_secret, sort_param)
|
||||
print("signature is ", signature)
|
||||
logger.info(f"signature is : {signature}")
|
||||
params["signature"] = signature
|
||||
try:
|
||||
gateway_url, token_url = get_domain({'tenantId': tenant_id})
|
||||
request_url = token_url + TOKEN_INTF
|
||||
print("no error")
|
||||
except Exception as ex:
|
||||
logger.error("该租户无法获取中心域名=>detail error: " + f"{str(ex)}")
|
||||
# request_url = settings.DEFAULT_AUTH_URL + settings.TOKEN_INTF
|
||||
raise Exception("该租户无法获取中心域名=>detail error: " + f"{str(ex)}")
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
respones = requests.get(url=request_url, params=params, headers=headers)
|
||||
result = respones.json()
|
||||
print("status_code:{0}".format(respones.status_code))
|
||||
logger.info(f"status_code: {respones.status_code}")
|
||||
if respones.status_code == 200:
|
||||
access_token = result.get("data", {}).get("access_token")
|
||||
print("access_token is {0}".format(result, access_token))
|
||||
logger.info("access_token is {0}".format(result, access_token))
|
||||
return access_token
|
||||
else:
|
||||
logger.error(f"请求失败 状态码: {respones.status_code}")
|
||||
raise Exception(f"请求失败 状态码: {respones.status_code}")
|
||||
|
||||
|
||||
'''
|
||||
获取租户所在中心域名
|
||||
'''
|
||||
|
||||
|
||||
def get_domain(params):
|
||||
request_url = DEFAULT_AUTH_URL + GATEWAY_INTF
|
||||
print("request_url is {0}".format(request_url))
|
||||
logger.info("get_domain request_url is: {0}".format(request_url))
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
respones = requests.get(url=request_url,
|
||||
params=params,
|
||||
@@ -101,10 +103,11 @@ def get_domain(params):
|
||||
data = result.get("data", {})
|
||||
gateway_url = data.get("gatewayUrl", None)
|
||||
token_url = data.get("tokenUrl", None)
|
||||
print("gateway_url is {0} token_url is {1}"
|
||||
"".format(gateway_url, token_url))
|
||||
logger.info("gateway_url is {0} token_url is {1}"
|
||||
"".format(gateway_url, token_url))
|
||||
return gateway_url, token_url
|
||||
else:
|
||||
logger.error(f"请求失败 状态码: {respones.status_code}")
|
||||
raise Exception(f"请求失败 状态码: {respones.status_code}")
|
||||
|
||||
|
||||
@@ -117,9 +120,8 @@ def query_meetingroom_type(params: dict):
|
||||
# ytenantId
|
||||
params = params.copy()
|
||||
params['ytenantId'] = params.pop('tenantId')
|
||||
print("now params ", params)
|
||||
logger.info(f"query_meetingroom_type params : {params}")
|
||||
tenant_id = params.get("ytenantId", None)
|
||||
print("tenant_id : ", tenant_id)
|
||||
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,
|
||||
@@ -136,24 +138,19 @@ def query_meetingroom(params: dict):
|
||||
# ytenantId
|
||||
params = params.copy()
|
||||
params['ytenantId'] = params.pop('tenantId')
|
||||
print("now params ", params)
|
||||
logger.info(f"query_meetingroom params : {params}")
|
||||
tenant_id = params.get("ytenantId", None)
|
||||
print("tenant_id : ", tenant_id)
|
||||
gateway_url, token_url = get_domain({"tenantId": tenant_id})
|
||||
request_url = gateway_url + QUERY_MEETING_ROOM
|
||||
print("request url ", request_url)
|
||||
logger.info(f"query_meetingroom request url : {request_url}")
|
||||
params['pageSize'] = page_size
|
||||
print("paramas ", params)
|
||||
|
||||
print("head is {0} type is {1}".format(DEFAULT_HEADER,type(DEFAULT_HEADER)))
|
||||
logger.info("head is {0} type is {1}".format(DEFAULT_HEADER, type(DEFAULT_HEADER)))
|
||||
respones = requests.get(url=request_url, params=params,
|
||||
headers=DEFAULT_HEADER)
|
||||
print("res is {0}".format(respones))
|
||||
logger.info("res is {0}".format(respones))
|
||||
return respones.json()
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
查询会议预定信息
|
||||
'''
|
||||
@@ -163,13 +160,11 @@ def query_meetingbooking_info(params: dict):
|
||||
# ytenantId
|
||||
params = params.copy()
|
||||
params['ytenantId'] = params.pop('tenantId')
|
||||
print("now params ", params)
|
||||
logger.info(f"query_meetingbooking_info params : {params} ")
|
||||
tenant_id = params.get("ytenantId", None)
|
||||
print("tenant_id : ", tenant_id)
|
||||
gateway_url, token_url = get_domain({"tenantId": tenant_id})
|
||||
request_url = gateway_url + QUERY_MEETINGBOOKING_INFO
|
||||
print("request url ", request_url)
|
||||
print("paramas ", params)
|
||||
logger.info(f"query_meetingbooking_info request url :{request_url}")
|
||||
params['pageSize'] = 800
|
||||
respones = requests.get(url=request_url, params=params,
|
||||
headers=DEFAULT_HEADER)
|
||||
@@ -177,8 +172,6 @@ def query_meetingbooking_info(params: dict):
|
||||
return respones.json()
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
预定会议
|
||||
'''
|
||||
@@ -186,17 +179,14 @@ def query_meetingbooking_info(params: dict):
|
||||
|
||||
def book_meeting(params: dict, data: dict):
|
||||
# tenantId
|
||||
print("now params ", params)
|
||||
logger.info(f"book_meeting params is :{params} ")
|
||||
tenant_id = params.get("tenantId", None)
|
||||
print("tenant_id : ", tenant_id)
|
||||
gateway_url, token_url = get_domain({"tenantId": tenant_id})
|
||||
request_url = gateway_url + BOOKMEETING
|
||||
print("request url ", request_url)
|
||||
print("paramas ", params)
|
||||
print("data: ", data)
|
||||
logger.info(f"book_meeting request url :{request_url}")
|
||||
respones = requests.post(url=request_url, params=params,
|
||||
headers=DEFAULT_HEADER, data=json.dumps(data))
|
||||
print("respone ", respones)
|
||||
logger.info(f"book_meeting respone is {respones} ")
|
||||
return respones.json()
|
||||
|
||||
|
||||
@@ -207,37 +197,32 @@ def book_meeting(params: dict, data: dict):
|
||||
|
||||
def edit_meeting_info(params: dict, data: dict):
|
||||
# tenantId
|
||||
print("now params ", params)
|
||||
logger.info(f"edit_meeting_info params is :{params}")
|
||||
tenant_id = params.get("tenantId", None)
|
||||
print("tenant_id : ", tenant_id)
|
||||
gateway_url, token_url = get_domain({"tenantId": tenant_id})
|
||||
request_url = gateway_url + EDIT_MEETING
|
||||
print("request url ", request_url)
|
||||
print("paramas ", params)
|
||||
print("data: ", data)
|
||||
print(f"edit_meeting_info request url is :{request_url} ")
|
||||
respones = requests.post(url=request_url, params=params,
|
||||
headers=DEFAULT_HEADER, data=json.dumps(data))
|
||||
print("respone ", respones)
|
||||
logger.info(f"edit_meeting_info respone is {respones} ")
|
||||
return respones.json()
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
取消会议
|
||||
'''
|
||||
|
||||
|
||||
def cancel_meeting(params: dict):
|
||||
# tenantId
|
||||
tenant_id = params.get('tenantId')
|
||||
print("now params ", params)
|
||||
print("tenant_id : ", tenant_id)
|
||||
logger.info(f"cancel_meeting params is :{params} ")
|
||||
gateway_url, token_url = get_domain({"tenantId": tenant_id})
|
||||
request_url = gateway_url + CANCEL_MEETING
|
||||
print("request url ", request_url)
|
||||
print("paramas ", params)
|
||||
params['isSendMail']=True
|
||||
params['isSendMsg']=True
|
||||
logger.info(f"cancel_meeting request url is :{request_url} ")
|
||||
params['isSendMail'] = True
|
||||
params['isSendMsg'] = True
|
||||
respones = requests.get(url=request_url, params=params,
|
||||
headers=DEFAULT_HEADER)
|
||||
print("respone ", respones)
|
||||
logger.info(f"cancel_meeting respone is {respones} ")
|
||||
return respones.json()
|
||||
|
||||
Reference in New Issue
Block a user