浏览代码

feat: knowledge base send file

master
zhayujie 9 个月前
父节点
当前提交
d67d6b7948
共有 1 个文件被更改,包括 22 次插入0 次删除
  1. +22
    -0
      bot/linkai/link_ai_bot.py

+ 22
- 0
bot/linkai/link_ai_bot.py 查看文件

@@ -15,6 +15,7 @@ from config import conf, pconf
import threading
from common import memory, utils
import base64
import os

class LinkAIBot(Bot):
# authentication failed
@@ -389,6 +390,11 @@ class LinkAIBot(Bot):
for url in image_urls:
if url.endswith(".mp4"):
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:
reply_type = ReplyType.IMAGE_URL
reply = Reply(reply_type, url)
@@ -396,6 +402,22 @@ class LinkAIBot(Bot):
except Exception as 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):
def session_msg_query(self, query, session_id):
session = self.build_session(session_id)


正在加载...
取消
保存