Compare commits

...

24 Commits

Author SHA1 Message Date
Rock Chin
a724bfe155 Release v2.2.2 2023-03-15 20:39:10 +08:00
Rock Chin
179a372bfe feat: 更改到process.py处理长消息 2023-03-15 20:33:44 +08:00
Rock Chin
651d765ab0 doc: 添加New Bing说明 2023-03-15 17:33:31 +08:00
Rock Chin
7ddc853f63 chore: 忽略保存的公告 2023-03-15 15:50:14 +08:00
Rock Chin
1bd1bfc725 chore: 删除测试公告 2023-03-15 15:47:24 +08:00
Rock Chin
f6ec0fda7a Merge pull request #280 from RockChinQ/announcement
[Feat] 添加公告输出功能
2023-03-15 15:46:58 +08:00
Rock Chin
7be368ae8c feat: 添加公告功能 2023-03-15 15:43:36 +08:00
Rock Chin
f67db2617b debug: 测试公告内容1 2023-03-15 15:37:07 +08:00
Rock Chin
ed5bf8100f chore: 添加公告内容 2023-03-15 15:22:19 +08:00
Rock Chin
0ef8a1c9ae chore: 为new bing忽略cookies.json 2023-03-15 11:24:45 +08:00
Rock Chin
32460cbf78 doc: 添加GPT-4公告 2023-03-15 11:04:10 +08:00
Rock Chin
6f6c9c222c doc: 添加网页版GPT-4说明 2023-03-15 10:57:29 +08:00
Rock Chin
438d0ed1ea Merge pull request #277 from zyckk4/dev
chore: 去除多余import
2023-03-14 13:11:47 +08:00
zyckk4
3ef1c71cad chore: 去除多余import 2023-03-14 13:03:50 +08:00
Rock Chin
aaadf6b8ba doc: 部署方式依赖项指令 2023-03-14 10:57:02 +08:00
Rock Chin
6af614f319 doc: 整理致谢列表 2023-03-14 10:54:46 +08:00
Rock Chin
c75dbd67df doc: 整理致谢列表 2023-03-14 10:53:32 +08:00
Rock Chin
dc3d186e2a Merge pull request #274 from RockChinQ/dependabot/pip/openai-approx-eq-0.27.2
chore(deps): update openai requirement from ~=0.27.0 to ~=0.27.2
2023-03-13 17:48:10 +08:00
dependabot[bot]
44550feddd chore(deps): update openai requirement from ~=0.27.0 to ~=0.27.2
Updates the requirements on [openai](https://github.com/openai/openai-python) to permit the latest version.
- [Release notes](https://github.com/openai/openai-python/releases)
- [Commits](https://github.com/openai/openai-python/compare/v0.27.0...v0.27.2)

---
updated-dependencies:
- dependency-name: openai
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-13 09:05:46 +00:00
Rock Chin
a0810d5f63 Merge pull request #271 from RockChinQ/config-covering
feat: 支持json格式的配置文件 (#265)
2023-03-13 11:05:11 +08:00
Rock Chin
cfc97fb22d feat: 支持json格式的配置文件 (#265) 2023-03-13 10:58:15 +08:00
Rock Chin
d67dbe8062 doc: 添加JSON格式情景预设的说明 2023-03-13 10:31:21 +08:00
Rock Chin
e89035e11c Release v2.2.1 2023-03-12 22:43:39 +08:00
Rock Chin
2ea711e629 fix: 更新包中包含新文件时更新失败 2023-03-12 22:43:02 +08:00
13 changed files with 102 additions and 20 deletions

5
.gitignore vendored
View File

@@ -13,4 +13,7 @@ sensitive.json
temp/ temp/
current_tag current_tag
scenario/ scenario/
!scenario/default-template.json !scenario/default-template.json
override.json
cookies.json
res/announcement_saved

View File

@@ -1,7 +1,9 @@
# QChatGPT🤖 # QChatGPT🤖
> 2023/3/3 官方接口疑似被墙,可考虑使用网络代理 [#198](https://github.com/RockChinQ/QChatGPT/issues/198)
> 2023/3/15 逆向库已支持New Bing使用方法查看[插件文档](https://github.com/RockChinQ/revLibs)
> 2023/3/15 逆向库已支持GPT-4模型使用方法查看[插件](https://github.com/RockChinQ/revLibs)
> 2023/3/3 官方接口疑似被墙,可考虑使用网络代理[#198](https://github.com/RockChinQ/QChatGPT/issues/198)
> 2023/3/3 现已在主线支持官方ChatGPT接口使用方法查看[#195](https://github.com/RockChinQ/QChatGPT/issues/195) > 2023/3/3 现已在主线支持官方ChatGPT接口使用方法查看[#195](https://github.com/RockChinQ/QChatGPT/issues/195)
> 2023/3/2 OpenAI已发布ChatGPT官方接口我们正在全力接入预计明日前完成请查看[此PR](https://github.com/RockChinQ/QChatGPT/pull/194)
> 2023/2/16 现已支持接入ChatGPT网页版详情请完成部署并查看底部**插件**小节或[此仓库](https://github.com/RockChinQ/revLibs) > 2023/2/16 现已支持接入ChatGPT网页版详情请完成部署并查看底部**插件**小节或[此仓库](https://github.com/RockChinQ/revLibs)
- 到[项目Wiki](https://github.com/RockChinQ/QChatGPT/wiki)可了解项目详细信息 - 到[项目Wiki](https://github.com/RockChinQ/QChatGPT/wiki)可了解项目详细信息
@@ -18,7 +20,9 @@
- OpenAI GPT-3.5模型(ChatGPT API), 本项目原生支持, 默认使用 - OpenAI GPT-3.5模型(ChatGPT API), 本项目原生支持, 默认使用
- OpenAI GPT-3模型, 本项目原生支持, 部署完成后前往config.py切换 - OpenAI GPT-3模型, 本项目原生支持, 部署完成后前往config.py切换
- ChatGPT网页版逆向API, 由[插件](https://github.com/RockChinQ/revLibs)接入 - ChatGPT网页版GPT-3.5模型, 由[插件](https://github.com/RockChinQ/revLibs)接入
- ChatGPT网页版GPT-4模型, 由[插件](https://github.com/RockChinQ/revLibs)接入
- New Bing逆向库, 由[插件](https://github.com/RockChinQ/revLibs)接入
### 故事续写 ### 故事续写
@@ -162,8 +166,7 @@ cd QChatGPT
2. 安装依赖 2. 安装依赖
```bash ```bash
pip3 install yiri-mirai openai colorlog func_timeout pip3 install yiri-mirai openai colorlog func_timeout dulwich Pillow
pip3 install dulwich
``` ```
3. 运行一次主程序,生成配置文件 3. 运行一次主程序,生成配置文件
@@ -224,12 +227,9 @@ python3 main.py
- [@the-lazy-me](https://github.com/the-lazy-me) 为本项目制作[视频教程](https://www.bilibili.com/video/BV15v4y1X7aP) - [@the-lazy-me](https://github.com/the-lazy-me) 为本项目制作[视频教程](https://www.bilibili.com/video/BV15v4y1X7aP)
- [@mikumifa](https://github.com/mikumifa) 本项目Docker部署仓库开发者 - [@mikumifa](https://github.com/mikumifa) 本项目Docker部署仓库开发者
- [@dominoar](https://github.com/dominoar) 为本项目开发多种插件 - [@dominoar](https://github.com/dominoar) 为本项目开发多种插件
- [@hissincn](https://github.com/hissincn) 本项目贡献者
- [@LINSTCL](https://github.com/LINSTCL) GPT-3.5官方模型适配贡献者
- [@Haibersut](https://github.com/Haibersut) 本项目贡献者
- [@万神的星空](https://github.com/qq255204159) 整合包发行 - [@万神的星空](https://github.com/qq255204159) 整合包发行
以及其他所有为本项目提供支持的朋友们。 以及所有[贡献者](https://github.com/RockChinQ/QChatGPT/graphs/contributors)和其他为本项目提供支持的朋友们。
## 👍赞赏 ## 👍赞赏

View File

@@ -79,9 +79,10 @@ default_prompt = {
"default": "如果我之后想获取帮助,请你说“输入!help获取帮助”", "default": "如果我之后想获取帮助,请你说“输入!help获取帮助”",
} }
# 实验性设置项: JSON完整情景导入 # 情景预设格式
# 预设prompt模式
# 参考值旧版本方式default | 完整情景full_scenario # 参考值旧版本方式default | 完整情景full_scenario
# 旧版本的格式为上述default_prompt中的内容或prompts目录下的文件名
# 完整情景预设的格式为JSON在JSON文件中列出对话的每个回合编写方法见scenario/default-template.json
preset_mode = "default" preset_mode = "default"
# 群内响应规则 # 群内响应规则

26
main.py
View File

@@ -1,4 +1,5 @@
import importlib import importlib
import json
import os import os
import shutil import shutil
import threading import threading
@@ -32,7 +33,7 @@ log_colors_config = {
'INFO': 'white', 'INFO': 'white',
'WARNING': 'yellow', 'WARNING': 'yellow',
'ERROR': 'red', 'ERROR': 'red',
'CRITICAL': 'bold_red', 'CRITICAL': 'cyan',
} }
@@ -143,9 +144,22 @@ def main(first_time_init=False):
setattr(config, key, getattr(config_template, key)) setattr(config, key, getattr(config_template, key))
logging.warning("[{}]不存在".format(key)) logging.warning("[{}]不存在".format(key))
is_integrity = False is_integrity = False
if not is_integrity: if not is_integrity:
logging.warning("配置文件不完整请依据config-template.py检查config.py") logging.warning("配置文件不完整请依据config-template.py检查config.py")
logging.warning("以上配置已被设为默认值将在5秒后继续启动... ") logging.warning("以上配置已被设为默认值将在5秒后继续启动... ")
# 检查override.json覆盖
if os.path.exists("override.json"):
override_json = json.load(open("override.json", "r", encoding="utf-8"))
for key in override_json:
if hasattr(config, key):
setattr(config, key, override_json[key])
logging.info("覆写配置[{}]为[{}]".format(key, override_json[key]))
else:
logging.error("无法覆写配置[{}]为[{}]该配置不存在请检查override.json是否正确".format(key, override_json[key]))
if not is_integrity:
time.sleep(5) time.sleep(5)
import pkg.utils.context import pkg.utils.context
@@ -293,13 +307,21 @@ def main(first_time_init=False):
import pkg.utils.updater import pkg.utils.updater
try: try:
if pkg.utils.updater.is_new_version_available(): if pkg.utils.updater.is_new_version_available():
pkg.utils.context.get_qqbot_manager().notify_admin("新版本可用,请发送 !update 进行自动更新\n更新日志:\n{}".format("\n".join(pkg.utils.updater.get_rls_notes()))) logging.info("新版本可用,请发送 !update 进行自动更新\n更新日志:\n{}".format("\n".join(pkg.utils.updater.get_rls_notes())))
else: else:
logging.info("当前已是最新版本") logging.info("当前已是最新版本")
except Exception as e: except Exception as e:
logging.warning("检查更新失败:{}".format(e)) logging.warning("检查更新失败:{}".format(e))
try:
import pkg.utils.announcement as announcement
new_announcement = announcement.fetch_new()
if new_announcement != "":
logging.critical("[公告] {}".format(new_announcement))
except Exception as e:
logging.warning("获取公告失败:{}".format(e))
return qqbot return qqbot

View File

@@ -1,5 +1,4 @@
# 长消息处理相关 # 长消息处理相关
import logging
import os import os
import time import time
import base64 import base64
@@ -67,7 +66,7 @@ def check_text(text: str) -> list:
"""检查文本是否为长消息,并转换成该使用的消息链组件""" """检查文本是否为长消息,并转换成该使用的消息链组件"""
if not hasattr(config, 'blob_message_threshold'): if not hasattr(config, 'blob_message_threshold'):
return [text] return [text]
if len(text) > config.blob_message_threshold: if len(text) > config.blob_message_threshold:
if not hasattr(config, 'blob_message_strategy'): if not hasattr(config, 'blob_message_strategy'):
raise AttributeError('未定义长消息处理策略') raise AttributeError('未定义长消息处理策略')

View File

@@ -4,6 +4,7 @@ import json
import datetime import datetime
import os import os
import threading import threading
import traceback
import pkg.openai.session import pkg.openai.session
import pkg.openai.manager import pkg.openai.manager
@@ -362,6 +363,7 @@ def process_command(session_name: str, text_message: str, mgr, config,
else: else:
pkg.utils.context.get_qqbot_manager().notify_admin("无新版本") pkg.utils.context.get_qqbot_manager().notify_admin("无新版本")
except Exception as e0: except Exception as e0:
traceback.print_exc()
pkg.utils.context.get_qqbot_manager().notify_admin("更新失败:{}".format(e0)) pkg.utils.context.get_qqbot_manager().notify_admin("更新失败:{}".format(e0))
return return

View File

@@ -1,6 +1,5 @@
# 普通消息处理模块 # 普通消息处理模块
import logging import logging
import time
import openai import openai
import pkg.utils.context import pkg.utils.context
import pkg.openai.session import pkg.openai.session
@@ -64,7 +63,7 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str,
reply = event.get_return_value("reply") reply = event.get_return_value("reply")
if not event.is_prevented_default(): if not event.is_prevented_default():
reply = blob.check_text(prefix + text) reply = prefix + text
except openai.error.APIConnectionError as e: except openai.error.APIConnectionError as e:
err_msg = str(e) err_msg = str(e)
if err_msg.__contains__('Error communicating with OpenAI'): if err_msg.__contains__('Error communicating with OpenAI'):

View File

@@ -26,6 +26,7 @@ import pkg.plugin.host as plugin_host
import pkg.plugin.models as plugin_models import pkg.plugin.models as plugin_models
import pkg.qqbot.ignore as ignore import pkg.qqbot.ignore as ignore
import pkg.qqbot.banlist as banlist import pkg.qqbot.banlist as banlist
import pkg.qqbot.blob as blob
processing = [] processing = []
@@ -157,6 +158,7 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
reply[0][:min(100, len(reply[0]))] + ( reply[0][:min(100, len(reply[0]))] + (
"..." if len(reply[0]) > 100 else ""))) "..." if len(reply[0]) > 100 else "")))
reply = [mgr.reply_filter.process(reply[0])] reply = [mgr.reply_filter.process(reply[0])]
reply = blob.check_text(reply[0])
else: else:
logging.info("回复[{}]消息".format(session_name)) logging.info("回复[{}]消息".format(session_name))

44
pkg/utils/announcement.py Normal file
View File

@@ -0,0 +1,44 @@
import base64
import os
import requests
def read_latest() -> str:
resp = requests.get(
url="https://api.github.com/repos/RockChinQ/QChatGPT/contents/res/announcement",
)
obj_json = resp.json()
b64_content = obj_json["content"]
# 解码
content = base64.b64decode(b64_content).decode("utf-8")
return content
def read_saved() -> str:
# 已保存的在res/announcement_saved
# 检查是否存在
if not os.path.exists("res/announcement_saved"):
with open("res/announcement_saved", "w") as f:
f.write("")
with open("res/announcement_saved", "r") as f:
content = f.read()
return content
def write_saved(content: str):
# 已保存的在res/announcement_saved
with open("res/announcement_saved", "w") as f:
f.write(content)
def fetch_new() -> str:
latest = read_latest()
saved = read_saved()
if latest.replace(saved, "").strip() == "":
return ""
else:
write_saved(latest)
return latest.replace(saved, "").strip()

File diff suppressed because one or more lines are too long

View File

@@ -126,6 +126,15 @@ def update_all(cli: bool = False) -> bool:
dst = src.replace(source_root, ".") dst = src.replace(source_root, ".")
if os.path.exists(dst): if os.path.exists(dst):
os.remove(dst) os.remove(dst)
# 检查目标文件夹是否存在
if not os.path.exists(os.path.dirname(dst)):
os.makedirs(os.path.dirname(dst))
# 检查目标文件是否存在
if not os.path.exists(dst):
# 创建目标文件
open(dst, "w").close()
shutil.copy(src, dst) shutil.copy(src, dst)
# 把current_tag写入文件 # 把current_tag写入文件

View File

@@ -1,5 +1,5 @@
requests~=2.28.1 requests~=2.28.1
openai~=0.27.0 openai~=0.27.2
dulwich~=0.21.3 dulwich~=0.21.3
colorlog~=6.6.0 colorlog~=6.6.0
yiri-mirai~=0.2.6.1 yiri-mirai~=0.2.6.1

1
res/announcement Normal file
View File

@@ -0,0 +1 @@