|
@@ -82,20 +82,19 @@ def call_llm(prompt: str, bot_id: str,coze_access_token:str):
|
|
|
]
|
|
|
}
|
|
|
res_create = requests.post(" https://api.coze.cn/v1/conversation/create", headers=req_head)
|
|
|
- coversition_id = res_create.json()["data"]["id"]
|
|
|
- res_chat = requests.post(f" https://api.coze.cn/v3/chat?conversation_id={coversition_id}", headers=req_head,json=req_data)
|
|
|
+ conversation_id = res_create.json()["data"]["id"]
|
|
|
+ res_chat = requests.post(f" https://api.coze.cn/v3/chat?conversation_id={conversation_id}", headers=req_head,json=req_data)
|
|
|
chat_id = res_chat.json()["data"]["id"]
|
|
|
while True:
|
|
|
- res_retrieve = requests.get(f" https://api.coze.cn/v3/chat/retrieve?chat_id={chat_id}&conversation_id={coversition_id}", headers=req_head)
|
|
|
+ res_retrieve = requests.get(f" https://api.coze.cn/v3/chat/retrieve?chat_id={chat_id}&conversation_id={conversation_id}", headers=req_head)
|
|
|
print(res_retrieve.json()["data"]["status"])
|
|
|
status = res_retrieve.json()["data"]["status"]
|
|
|
if status == "completed":
|
|
|
- res_message = requests.get(f" https://api.coze.cn/v3/chat/message/list?chat_id={chat_id}&conversation_id={coversition_id}", headers=req_head)
|
|
|
+ res_message = requests.get(f" https://api.coze.cn/v3/chat/message/list?chat_id={chat_id}&conversation_id={conversation_id}", headers=req_head)
|
|
|
# print(res_message.json())
|
|
|
return res_message.json()
|
|
|
time.sleep(1)
|
|
|
- # res.raise_for_status() # 检查响应状态码是否为200
|
|
|
- # return res.json()
|
|
|
+
|
|
|
|
|
|
|
|
|
def qiwei_get():
|
|
@@ -111,6 +110,9 @@ def qiwei_post(username: str, answer: str,agentid:str):
|
|
|
"msgtype": "text",
|
|
|
"agentid": agentid,
|
|
|
"text": {"content": answer},
|
|
|
+ "image": {
|
|
|
+ "media_id": "MEDIA_ID"
|
|
|
+ },
|
|
|
"safe": 0,
|
|
|
"enable_id_trans": 0,
|
|
|
"enable_duplicate_check": 0,
|
|
@@ -122,15 +124,14 @@ def qiwei_post(username: str, answer: str,agentid:str):
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
def consumer(user_query,decrypt_data):
|
|
|
print(f"请求:{user_query}")
|
|
|
username = decrypt_data.get('FromUserName', '')
|
|
|
agentid = decrypt_data.get('AgentID', '')
|
|
|
# 返回coze结果
|
|
|
coze_response = call_llm(prompt=user_query,bot_id=bot_id,coze_access_token = coze_access_token)
|
|
|
- answer = coze_response['data'][1]['content']
|
|
|
+ # answer = coze_response['messages'][1]['content']#v2
|
|
|
+ answer = coze_response['data'][1]['content'].replace(" ","") #v3 删除图片url中的空格
|
|
|
print(f"结果:{answer}")
|
|
|
# 主动发结果给qiwei
|
|
|
qiwei_post(username, answer, agentid)
|