|
@@ -93,12 +93,12 @@ def call_llm(prompt: str, bot_id: str,coze_access_token:str):
|
|
|
while True:
|
|
|
res_retrieve = requests.get(f" https://api.coze.cn/v3/chat/retrieve?chat_id={chat_id}&conversation_id={conversation_id}", headers=req_head)
|
|
|
res_json = res_retrieve.json()
|
|
|
- # 首先判断状态码是否为0
|
|
|
+ # 首先判断网络状态是否为200
|
|
|
if res_retrieve.status_code != 200:
|
|
|
logger.error(f"网络状态码失败,错误码:{res_retrieve.status_code }")
|
|
|
coze_response = f"网络状态码失败,错误码:{res_retrieve.status_code }"
|
|
|
return coze_response
|
|
|
- # 首先判断状态码是否为0
|
|
|
+ # 判断状态码是否为0
|
|
|
if res_json["code"] != 0 :
|
|
|
logger.error(f"API调用失败,错误码:{res_json['code']}")
|
|
|
coze_response = f"API调用失败,错误码:{res_json['code']}"
|
|
@@ -150,6 +150,27 @@ def qiwei_post(username: str, answer: str,agentid:str):
|
|
|
logger.info(res.json())
|
|
|
#return res.json()
|
|
|
|
|
|
+def qiwei_post_loading(username: str, answer: str,agentid:str):
|
|
|
+ req_data = {
|
|
|
+ "touser": username,
|
|
|
+ "toparty": "",
|
|
|
+ "totag": "",
|
|
|
+ "msgtype": "text",
|
|
|
+ "agentid": agentid,
|
|
|
+ "text": {"content": answer},
|
|
|
+ "image": {
|
|
|
+ "media_id": "MEDIA_ID"
|
|
|
+ },
|
|
|
+ "safe": 0,
|
|
|
+ "enable_id_trans": 0,
|
|
|
+ "enable_duplicate_check": 0,
|
|
|
+ "duplicate_check_interval": 1800
|
|
|
+ }
|
|
|
+ res = requests.post(f"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={qiwei_get()}", json=req_data)
|
|
|
+ # print(res.json())
|
|
|
+ logger.info(res.json())
|
|
|
+ #return res.json()
|
|
|
+
|
|
|
#问题传入字节服务器进行回答后发送给企业微信,行内服务器只进行接收然后发给字节,防止网络延迟
|
|
|
def post_consumer_api(user_query, decrypt_data):
|
|
|
data = {
|
|
@@ -169,17 +190,18 @@ async def consumer(
|
|
|
request: Request
|
|
|
):
|
|
|
# print(f"请求:{user_query}")
|
|
|
-
|
|
|
body = await request.body()
|
|
|
body = body.decode()
|
|
|
body = json.loads(body)
|
|
|
user_query = body["user_query"]
|
|
|
decrypt_data = body["decrypt_data"]
|
|
|
-
|
|
|
-
|
|
|
- logger.info(f"consumer 请求:{user_query}")
|
|
|
username = decrypt_data.get('FromUserName', '')
|
|
|
agentid = decrypt_data.get('AgentID', '')
|
|
|
+
|
|
|
+ qiwei_post(username, "正在加载,请稍后...", agentid)
|
|
|
+ logger.info("正在加载,请稍后...")
|
|
|
+ logger.info(f"consumer 请求:{user_query}")
|
|
|
+
|
|
|
# 返回coze结果
|
|
|
coze_response = call_llm(prompt=user_query,bot_id=bot_id,coze_access_token = coze_access_token)
|
|
|
# answer = coze_response['messages'][1]['content']#v2
|