|
@@ -9,6 +9,7 @@ Email: me@gentlecp.com
|
|
Create Date: 2021/6/19
|
|
Create Date: 2021/6/19
|
|
-----------------End-----------------------------
|
|
-----------------End-----------------------------
|
|
"""
|
|
"""
|
|
|
|
+import re
|
|
import time
|
|
import time
|
|
|
|
|
|
from django.db.models.fields import return_None
|
|
from django.db.models.fields import return_None
|
|
@@ -132,10 +133,29 @@ def consumer(user_query,decrypt_data):
|
|
coze_response = call_llm(prompt=user_query,bot_id=bot_id,coze_access_token = coze_access_token)
|
|
coze_response = call_llm(prompt=user_query,bot_id=bot_id,coze_access_token = coze_access_token)
|
|
|
|
|
|
answer = coze_response['data'][1]['content'].replace(" ","")
|
|
answer = coze_response['data'][1]['content'].replace(" ","")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ image_counter = 1
|
|
|
|
+
|
|
|
|
+ def replace_with_counter(match):
|
|
|
|
+ nonlocal image_counter
|
|
|
|
+ alt_text = match.group(1) or f"示例图片{image_counter}"
|
|
|
|
+ url = match.group(2)
|
|
|
|
+ replacement = f'<a href="{url}">{alt_text}</a>'
|
|
|
|
+ image_counter += 1
|
|
|
|
+ return replacement
|
|
|
|
+
|
|
|
|
+ answer = re.sub(r'!\[(.*?)\]\((https?://[^)]+)\)', replace_with_counter, answer)
|
|
|
|
+
|
|
print(f"结果:{answer}")
|
|
print(f"结果:{answer}")
|
|
|
|
|
|
qiwei_post(username, answer, agentid)
|
|
qiwei_post(username, answer, agentid)
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
@app.get("/bot")
|
|
@app.get("/bot")
|
|
async def verify(msg_signature: str, timestamp: str, nonce: str, echostr: str):
|
|
async def verify(msg_signature: str, timestamp: str, nonce: str, echostr: str):
|
|
ret, sEchoStr = wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr)
|
|
ret, sEchoStr = wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr)
|
|
@@ -160,4 +180,6 @@ async def recv(msg_signature: str, timestamp: str, nonce: str, request: Request,
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
|
+
|
|
|
|
+
|
|
uvicorn.run("coze_bot_api:app", port=port, host='0.0.0.0', reload=False,ssl_keyfile="./key.pem", ssl_certfile="./cert.pem")
|
|
uvicorn.run("coze_bot_api:app", port=port, host='0.0.0.0', reload=False,ssl_keyfile="./key.pem", ssl_certfile="./cert.pem")
|