From cbfaa1a123a55aa9c55af0c7dc3f05edcbd8e117 Mon Sep 17 00:00:00 2001 From: Wizerd Date: Wed, 20 Dec 2023 23:16:49 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E6=94=AF=E6=8C=81=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.md | 12 ++++++++++++ docker-compose.yml | 1 + main.py | 20 ++++++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index e08c9b5..f321d9a 100644 --- a/Readme.md +++ b/Readme.md @@ -40,6 +40,8 @@ - [x] 支持 gpt-4-vision +- [x] 支持 Bot模式(QQ、微信机器人等建议开启) + - [ ] 支持 指定进程、线程数 - [ ] 优化 偶现的【0†source】引用bug @@ -281,6 +283,16 @@ services: ![api-5](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/299df56a-d245-4920-8892-94e1a9cc644a) +### Bot 模式 + +#### 开启 Bot 模式 + +![image](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/9c5fd974-58f2-4b96-839d-aef10f7a1cfc) + +#### 关闭 Bot 模式 + +![image](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/c1d3457f-b912-4572-b4e0-1118b48102d8) + ## Star 历史 ![Stargazers over time](https://api.star-history.com/svg?repos=Ink-Osier/PandoraToV1Api&type=Date) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 948d4f6..cb48e1b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,7 @@ services: - API_PREFIX=<本项目接口前缀> # 本项目/v1接口的前缀,示例:666,如果留空默认为原版本一致 - LOG_LEVEL=<日志等级> # 日志输出等级,可选值:DEBUG,INFO,WARNING,ERROR,CRITICAL - NEED_LOG_TO_FILE=<是否需要输出日志到文件> # 是否需要输出日志到文件,可选值:true,false + - BOT_MODE=false volumes: - ./log:/app/log - ./images:/app/images diff --git a/main.py b/main.py index 6866974..4dccff4 100644 --- a/main.py +++ b/main.py @@ -149,13 +149,14 @@ UPLOAD_BASE_URL = os.getenv('UPLOAD_BASE_URL', '') KEY_FOR_GPTS_INFO = os.getenv('KEY_FOR_GPTS_INFO', '') # 添加环境变量配置 API_PREFIX = os.getenv('API_PREFIX', '') +BOT_MODE = os.getenv('BOT_MODE', 'false').lower() == 'true' PANDORA_UPLOAD_URL = 'files.pandoranext.com' -VERSION = '0.2.0' +VERSION = '0.2.1' # VERSION = 'test' -UPDATE_INFO = '支持 GPT-4 文件上传' +UPDATE_INFO = '支持 BOT 模式' # UPDATE_INFO = '【仅供临时测试使用】 ' with app.app_context(): @@ -169,6 +170,9 @@ with app.app_context(): logger.info(f"LOG_LEVEL: {LOG_LEVEL}") logger.info(f"NEED_LOG_TO_FILE: {NEED_LOG_TO_FILE}") + logger.info(f"BOT_MODE: {BOT_MODE}") + + if not BASE_URL: raise Exception('BASE_URL is not set') @@ -681,7 +685,10 @@ def replace_complete_citation(text, citations): logger.debug(f"citation: {citation}") if cited_message_idx == int(citation_number): url = citation.get("metadata", {}).get("url", "") - return f"[[{citation_number}]({url})]" + if BOT_MODE == False: + return f"[[{citation_number}]({url})]" + else: + return "" return match.group(0) # 如果没有找到对应的引用,返回原文本 # 使用 finditer 找到第一个匹配项 @@ -806,7 +813,8 @@ def data_fetcher(upstream_response, data_queue, stop_event, last_data_time, api_ logger.debug(f"下载图片成功") image_data = image_download_response.content today_image_url = save_image(image_data) # 保存图片,并获取文件名 - new_text = f"\n![image]({UPLOAD_BASE_URL}/{today_image_url})\n[下载链接]({UPLOAD_BASE_URL}/{today_image_url})\n" + if BOT_MODE == False: + new_text = f"\n![image]({UPLOAD_BASE_URL}/{today_image_url})\n[下载链接]({UPLOAD_BASE_URL}/{today_image_url})\n" else: logger.error(f"下载图片失败: {image_download_response.text}") if last_content_type == "code": @@ -1252,8 +1260,8 @@ def images_generations(): # print(f"data_json: {data_json}") message = data_json.get("message", {}) - if message == {} or message == None: - logger.debug(f"message 为空: data_json: {data_json}") + if message == None: + logger.error(f"message 为空: data_json: {data_json}") message_status = message.get("status") content = message.get("content", {})