Compare commits

...

16 Commits

Author SHA1 Message Date
Rock Chin
9e25d0f9e4 Release v2.4.5 2023-05-31 18:31:25 +08:00
Rock Chin
23cd7be711 Merge pull request #487 from RockChinQ/feat-banlist-syntax-check
feat: 初始化流程异常处理
2023-05-31 18:25:46 +08:00
Rock Chin
025b9e33f1 feat: 初始化流程异常处理 2023-05-31 18:24:01 +08:00
Rock Chin
bab2f64913 doc(README_en.md): 添加wakapi计时 2023-05-29 11:12:07 +08:00
Rock Chin
b00e09aa9c doc: 添加wakapi计时 2023-05-29 11:10:49 +08:00
Rock Chin
0b109fdc7a Merge pull request #479 from RockChinQ/dependabot/pip/openai-approx-eq-0.27.7
chore(deps): update openai requirement from ~=0.27.6 to ~=0.27.7
2023-05-22 17:13:50 +08:00
dependabot[bot]
018fea2ddb chore(deps): update openai requirement from ~=0.27.6 to ~=0.27.7
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.6...v0.27.7)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-22 09:05:00 +00:00
Rock Chin
f8a3cc4352 doc: 折起OpenAI注册步骤 2023-05-21 18:25:35 +08:00
Rock Chin
6ab853acc1 doc: 修改关于HuggingChat的说明 2023-05-21 17:50:35 +08:00
Rock Chin
e825dea02f chore: 排除hugchat.json 2023-05-21 17:47:42 +08:00
Rock Chin
cf8740d16e Merge branch 'master' of https://github.com/RockChinQ/QChatGPT 2023-05-21 17:33:47 +08:00
Rock Chin
9c4809e26f chore: 发布revLibs相关公告 2023-05-21 17:33:44 +08:00
Rock Chin
0a232fd9ef Merge pull request #477 from RockChinQ/feature-detailed-cfg-cmd
[Feat] 支持使用!cfg指令修改子配置项
2023-05-21 15:59:59 +08:00
Rock Chin
23016a0791 doc: 更新wiki说明 2023-05-21 15:58:21 +08:00
Rock Chin
cdcc67ff23 feat(!cfg): 使用eval()函数进行类型转换 2023-05-21 15:53:56 +08:00
Rock Chin
92274bfc34 feat(!cfg): 支持使用点号索引子配置项 2023-05-21 15:49:56 +08:00
9 changed files with 213 additions and 163 deletions

1
.gitignore vendored
View File

@@ -25,3 +25,4 @@ bin/
.vscode .vscode
test_* test_*
venv/ venv/
hugchat.json

View File

@@ -7,6 +7,7 @@
[English](README_en.md) | 简体中文 [English](README_en.md) | 简体中文
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/RockChinQ/QChatGPT?style=flat-square)](https://github.com/RockChinQ/QChatGPT/releases/latest) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/RockChinQ/QChatGPT?style=flat-square)](https://github.com/RockChinQ/QChatGPT/releases/latest)
![Wakapi Count](https://wakapi.dev/api/badge/RockChinQ/interval:any/project:QChatGPT)
> 2023/4/27 正在对纯Python实现的QQ登录框架、YAML配置文件、异步编程等功能进行概念验证欢迎体验[LightQChat](https://github.com/RockChinQ/LightQChat)项目 > 2023/4/27 正在对纯Python实现的QQ登录框架、YAML配置文件、异步编程等功能进行概念验证欢迎体验[LightQChat](https://github.com/RockChinQ/LightQChat)项目
> 2023/4/24 支持使用go-cqhttp登录QQ请查看[此文档](https://github.com/RockChinQ/QChatGPT/wiki/go-cqhttp%E9%85%8D%E7%BD%AE) > 2023/4/24 支持使用go-cqhttp登录QQ请查看[此文档](https://github.com/RockChinQ/QChatGPT/wiki/go-cqhttp%E9%85%8D%E7%BD%AE)
@@ -33,7 +34,7 @@
- ChatGPT网页版GPT-3.5模型, 由[插件](https://github.com/RockChinQ/revLibs)接入 - ChatGPT网页版GPT-3.5模型, 由[插件](https://github.com/RockChinQ/revLibs)接入
- ChatGPT网页版GPT-4模型, 目前需要ChatGPT Plus订阅, 由[插件](https://github.com/RockChinQ/revLibs)接入 - ChatGPT网页版GPT-4模型, 目前需要ChatGPT Plus订阅, 由[插件](https://github.com/RockChinQ/revLibs)接入
- New Bing逆向库, 由[插件](https://github.com/RockChinQ/revLibs)接入 - New Bing逆向库, 由[插件](https://github.com/RockChinQ/revLibs)接入
- HuggingChat, 由[插件](https://github.com/RockChinQ/revLibs)接入, 无需账号,仅支持英文 - HuggingChat, 由[插件](https://github.com/RockChinQ/revLibs)接入, 仅支持英文
### 故事续写 ### 故事续写
@@ -161,6 +162,9 @@
### - 注册OpenAI账号 ### - 注册OpenAI账号
<details>
<summary>点此查看步骤</summary>
> 若您要直接使用非OpenAI的模型如New Bing可跳过此步骤直接进行之后的部署完成后按照相关插件的文档进行配置即可 > 若您要直接使用非OpenAI的模型如New Bing可跳过此步骤直接进行之后的部署完成后按照相关插件的文档进行配置即可
参考以下文章自行注册 参考以下文章自行注册
@@ -171,6 +175,8 @@
注册成功后请前往[个人中心查看](https://beta.openai.com/account/api-keys)api_key 注册成功后请前往[个人中心查看](https://beta.openai.com/account/api-keys)api_key
完成注册后,使用以下自动化或手动部署步骤 完成注册后,使用以下自动化或手动部署步骤
</details>
### - 自动化部署 ### - 自动化部署
<details> <details>

View File

@@ -7,6 +7,7 @@
English | [简体中文](README.md) English | [简体中文](README.md)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/RockChinQ/QChatGPT?style=flat-square)](https://github.com/RockChinQ/QChatGPT/releases/latest) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/RockChinQ/QChatGPT?style=flat-square)](https://github.com/RockChinQ/QChatGPT/releases/latest)
![Wakapi Count](https://wakapi.dev/api/badge/RockChinQ/interval:any/project:QChatGPT)
- Refer to [Wiki](https://github.com/RockChinQ/QChatGPT/wiki) to get further information. - Refer to [Wiki](https://github.com/RockChinQ/QChatGPT/wiki) to get further information.
- Official QQ group: 656285629 - Official QQ group: 656285629
@@ -27,7 +28,7 @@ English | [简体中文](README.md)
- ChatGPT website edition (GPT-3.5), see [revLibs plugin](https://github.com/RockChinQ/revLibs) - ChatGPT website edition (GPT-3.5), see [revLibs plugin](https://github.com/RockChinQ/revLibs)
- ChatGPT website edition (GPT-4), ChatGPT plus subscription required, see [revLibs plugin](https://github.com/RockChinQ/revLibs) - ChatGPT website edition (GPT-4), ChatGPT plus subscription required, see [revLibs plugin](https://github.com/RockChinQ/revLibs)
- New Bing, see [revLibs plugin](https://github.com/RockChinQ/revLibs) - New Bing, see [revLibs plugin](https://github.com/RockChinQ/revLibs)
- HuggingChat, see [revLibs plugin](https://github.com/RockChinQ/revLibs), no accounts required, English only - HuggingChat, see [revLibs plugin](https://github.com/RockChinQ/revLibs), English only
### Story ### Story

12
main.py
View File

@@ -133,6 +133,7 @@ def start(first_time_init=False):
print("更新openai库失败:{}, 请忽略或自行更新".format(e)) print("更新openai库失败:{}, 请忽略或自行更新".format(e))
known_exception_caught = False known_exception_caught = False
try:
try: try:
sh = reset_logging() sh = reset_logging()
@@ -255,6 +256,17 @@ def start(first_time_init=False):
threading.Thread( threading.Thread(
target=run_bot_wrapper target=run_bot_wrapper
).start() ).start()
except Exception as e:
traceback.print_exc()
if isinstance(e, KeyboardInterrupt):
logging.info("程序被用户中止")
sys.exit(0)
elif isinstance(e, SyntaxError):
logging.error("配置文件存在语法错误,请检查配置文件:\n1. 是否存在中文符号\n2. 是否已按照文件中的说明填写正确")
sys.exit(1)
else:
logging.error("初始化失败:{}".format(e))
sys.exit(1)
finally: finally:
# 判断若是Windows输出选择模式可能会暂停程序的警告 # 判断若是Windows输出选择模式可能会暂停程序的警告
if os.name == 'nt': if os.name == 'nt':

View File

@@ -8,7 +8,7 @@ def config_operation(cmd, params):
config = pkg.utils.context.get_config() config = pkg.utils.context.get_config()
reply_str = "" reply_str = ""
if len(params) == 0: if len(params) == 0:
reply = ["[bot]err:请输入配置项"] reply = ["[bot]err:请输入!cmd cfg查看使用方法"]
else: else:
cfg_name = params[0] cfg_name = params[0]
if cfg_name == 'all': if cfg_name == 'all':
@@ -26,45 +26,61 @@ def config_operation(cmd, params):
else: else:
reply_str += "{}: {}\n".format(cfg, getattr(config, cfg)) reply_str += "{}: {}\n".format(cfg, getattr(config, cfg))
reply = [reply_str] reply = [reply_str]
elif cfg_name in dir(config): else:
cfg_entry_path = cfg_name.split('.')
try:
if len(params) == 1: if len(params) == 1:
# 按照配置项类型进行格式化 cfg_entry = getattr(config, cfg_entry_path[0])
if isinstance(getattr(config, cfg_name), str): if len(cfg_entry_path) > 1:
reply_str = "[bot]配置项{}: \"{}\"\n".format(cfg_name, getattr(config, cfg_name)) for i in range(1, len(cfg_entry_path)):
elif isinstance(getattr(config, cfg_name), dict): cfg_entry = cfg_entry[cfg_entry_path[i]]
if isinstance(cfg_entry, str):
reply_str = "[bot]配置项{}: \"{}\"\n".format(cfg_name, cfg_entry)
elif isinstance(cfg_entry, dict):
reply_str = "[bot]配置项{}: {}\n".format(cfg_name, reply_str = "[bot]配置项{}: {}\n".format(cfg_name,
json.dumps(getattr(config, cfg_name), json.dumps(cfg_entry,
ensure_ascii=False, indent=4)) ensure_ascii=False, indent=4))
else: else:
reply_str = "[bot]配置项{}: {}\n".format(cfg_name, getattr(config, cfg_name)) reply_str = "[bot]配置项{}: {}\n".format(cfg_name, cfg_entry)
reply = [reply_str] reply = [reply_str]
else: else:
cfg_value = " ".join(params[1:]) cfg_value = " ".join(params[1:])
# 类型转换如果是json则转换为字典 # 类型转换如果是json则转换为字典
if cfg_value == 'true': # if cfg_value == 'true':
cfg_value = True # cfg_value = True
elif cfg_value == 'false': # elif cfg_value == 'false':
cfg_value = False # cfg_value = False
elif cfg_value.isdigit(): # elif cfg_value.isdigit():
cfg_value = int(cfg_value) # cfg_value = int(cfg_value)
elif cfg_value.startswith('{') and cfg_value.endswith('}'): # elif cfg_value.startswith('{') and cfg_value.endswith('}'):
cfg_value = json.loads(cfg_value) # cfg_value = json.loads(cfg_value)
else: # else:
try: # try:
cfg_value = float(cfg_value) # cfg_value = float(cfg_value)
except ValueError: # except ValueError:
pass # pass
cfg_value = eval(cfg_value)
# 检查类型是否匹配 cfg_entry = getattr(config, cfg_entry_path[0])
if isinstance(getattr(config, cfg_name), type(cfg_value)): if len(cfg_entry_path) > 1:
setattr(config, cfg_name, cfg_value) for i in range(1, len(cfg_entry_path) - 1):
pkg.utils.context.set_config(config) cfg_entry = cfg_entry[cfg_entry_path[i]]
if isinstance(cfg_entry[cfg_entry_path[-1]], type(cfg_value)):
cfg_entry[cfg_entry_path[-1]] = cfg_value
reply = ["[bot]配置项{}修改成功".format(cfg_name)] reply = ["[bot]配置项{}修改成功".format(cfg_name)]
else: else:
reply = ["[bot]err:配置项{}类型不匹配".format(cfg_name)] reply = ["[bot]err:配置项{}类型不匹配".format(cfg_name)]
else: else:
setattr(config, cfg_entry_path[0], cfg_value)
reply = ["[bot]配置项{}修改成功".format(cfg_name)]
except AttributeError:
reply = ["[bot]err:未找到配置项 {}".format(cfg_name)] reply = ["[bot]err:未找到配置项 {}".format(cfg_name)]
except ValueError:
reply = ["[bot]err:未找到配置项 {}".format(cfg_name)]
# else:
# reply = ["[bot]err:未找到配置项 {}".format(cfg_name)]
return reply return reply

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
requests~=2.28.1 requests~=2.28.1
openai~=0.27.6 openai~=0.27.7
dulwich~=0.21.5 dulwich~=0.21.5
colorlog~=6.6.0 colorlog~=6.6.0
yiri-mirai~=0.2.7 yiri-mirai~=0.2.7

View File

@@ -4,5 +4,11 @@
"time": "2023-04-24 16:05:20", "time": "2023-04-24 16:05:20",
"timestamp": 1682323520, "timestamp": 1682323520,
"content": "现已支持使用go-cqhttp替换mirai作为QQ登录框架, 请更新并查看 https://github.com/RockChinQ/QChatGPT/wiki/go-cqhttp%E9%85%8D%E7%BD%AE" "content": "现已支持使用go-cqhttp替换mirai作为QQ登录框架, 请更新并查看 https://github.com/RockChinQ/QChatGPT/wiki/go-cqhttp%E9%85%8D%E7%BD%AE"
},
{
"id": 1,
"time": "2023-05-21 17:33:18",
"timestamp": 1684661598,
"content": "NewBing不再需要鉴权若您正在使用revLibs逆向库插件请立即使用!plugin update revLibs命令更新插件到最新版。"
} }
] ]

View File

@@ -225,7 +225,7 @@
格式: `!cfg <配置项名称> <配置项新值>` 格式: `!cfg <配置项名称> <配置项新值>`
以修改`default_prompt`示例 以修改`default_prompt`示例
``` ```
!cfg default_prompt 我是Rock Chin !cfg default_prompt "我是Rock Chin"
``` ```
输出示例 输出示例
@@ -243,7 +243,15 @@
``` ```
!~all !~all
!~default_prompt !~default_prompt
!~default_prompt 我是Rock Chin !~default_prompt "我是Rock Chin"
```
5. 配置项名称支持使用点号(.)拼接以索引子配置项
例如: `openai_config.api_key`将索引`config`字典中的`openai_config`字典中的`api_key`字段,可以通过这个方式查看或修改此子配置项
```
!~openai_config.api_key
``` ```
</details> </details>