mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-21 22:27:13 +08:00
feat: knowledge base send file
This commit is contained in:
@@ -15,6 +15,7 @@ from config import conf, pconf
|
|||||||
import threading
|
import threading
|
||||||
from common import memory, utils
|
from common import memory, utils
|
||||||
import base64
|
import base64
|
||||||
|
import os
|
||||||
|
|
||||||
class LinkAIBot(Bot):
|
class LinkAIBot(Bot):
|
||||||
# authentication failed
|
# authentication failed
|
||||||
@@ -389,6 +390,11 @@ class LinkAIBot(Bot):
|
|||||||
for url in image_urls:
|
for url in image_urls:
|
||||||
if url.endswith(".mp4"):
|
if url.endswith(".mp4"):
|
||||||
reply_type = ReplyType.VIDEO_URL
|
reply_type = ReplyType.VIDEO_URL
|
||||||
|
elif url.endswith(".pdf") or url.endswith(".doc") or url.endswith(".docx"):
|
||||||
|
reply_type = ReplyType.FILE
|
||||||
|
url = _download_file(url)
|
||||||
|
if not url:
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
reply_type = ReplyType.IMAGE_URL
|
reply_type = ReplyType.IMAGE_URL
|
||||||
reply = Reply(reply_type, url)
|
reply = Reply(reply_type, url)
|
||||||
@@ -396,6 +402,22 @@ class LinkAIBot(Bot):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
|
|
||||||
|
def _download_file(url: str):
|
||||||
|
try:
|
||||||
|
file_path = "tmp"
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
os.makedirs(file_path)
|
||||||
|
file_name = url.split("/")[-1] # 获取文件名
|
||||||
|
file_path = os.path.join(file_path, file_name)
|
||||||
|
response = requests.get(url)
|
||||||
|
with open(file_path, "wb") as f:
|
||||||
|
f.write(response.content)
|
||||||
|
return file_path
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn(e)
|
||||||
|
|
||||||
|
|
||||||
class LinkAISessionManager(SessionManager):
|
class LinkAISessionManager(SessionManager):
|
||||||
def session_msg_query(self, query, session_id):
|
def session_msg_query(self, query, session_id):
|
||||||
session = self.build_session(session_id)
|
session = self.build_session(session_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user