mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
feat: 赞赏码发送
This commit is contained in:
parent
618487947b
commit
d72c364962
|
@ -21,7 +21,7 @@ mirai_http_api_config = {
|
|||
# [必需] OpenAI的配置
|
||||
# api_key: OpenAI的API Key
|
||||
# 若只有一个api-key,请直接修改以下内容中的"openai_api_key"为你的api-key
|
||||
|
||||
#
|
||||
# 如准备了多个api-key,可以以字典的形式填写,程序会自动选择可用的api-key
|
||||
# 例如
|
||||
# openai_config = {
|
||||
|
@ -63,6 +63,10 @@ response_rules = {
|
|||
# 请在sensitive.json中添加敏感词
|
||||
sensitive_word_filter = True
|
||||
|
||||
# 启动时是否发送赞赏码
|
||||
# 仅当使用量已经超过2048字时发送
|
||||
encourage_sponsor_at_start = True
|
||||
|
||||
# 每次向OpenAI接口发送对话记录上下文的字符数
|
||||
# 最大不超过(4096 - max_tokens)个字符,max_tokens为上述completion_api_params中的max_tokens
|
||||
# 注意:较大的prompt_submit_length会导致OpenAI账户额度消耗更快
|
||||
|
@ -72,7 +76,7 @@ prompt_submit_length = 1024
|
|||
# 具体请查看OpenAI的文档: https://beta.openai.com/docs/api-reference/completions/create
|
||||
completion_api_params = {
|
||||
"model": "text-davinci-003",
|
||||
"temperature": 0.6, # 数值越低得到的回答越理性,取值范围[0, 1]
|
||||
"temperature": 0.9, # 数值越低得到的回答越理性,取值范围[0, 1]
|
||||
"max_tokens": 512, # 每次向OpenAI请求的最大字符数, 不高于4096
|
||||
"top_p": 1, # 生成的文本的文本与要求的符合度, 取值范围[0, 1]
|
||||
"frequency_penalty": 0.2,
|
||||
|
|
18
main.py
18
main.py
|
@ -6,6 +6,7 @@ import time
|
|||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
try:
|
||||
import colorlog
|
||||
except ImportError:
|
||||
|
@ -197,6 +198,23 @@ def main(first_time_init=False):
|
|||
else:
|
||||
logging.info('热重载完成')
|
||||
|
||||
# 发送赞赏码
|
||||
if hasattr(config, 'encourage_sponsor_at_start') \
|
||||
and config.encourage_sponsor_at_start \
|
||||
and pkg.utils.context.get_openai_manager().audit_mgr.get_total_text_length() >= 2048:
|
||||
|
||||
logging.info("发送赞赏码")
|
||||
from mirai import MessageChain, Plain, Image
|
||||
import pkg.utils.constants
|
||||
message_chain = MessageChain([
|
||||
Plain("自2022年12月初以来,开发者已经花费了大量时间和精力来维护本项目,如果您觉得本项目对您有帮助,欢迎赞赏开发者,"
|
||||
"以支持项目稳定运行😘"),
|
||||
Image(base64=pkg.utils.constants.alipay_qr_b64),
|
||||
Image(base64=pkg.utils.constants.wechat_qr_b64),
|
||||
Plain("(本消息仅在启动时发送至管理员,如果您不想再看到此消息,请在config.py中将encourage_sponsor_at_start设置为False)")
|
||||
])
|
||||
pkg.utils.context.get_qqbot_manager().notify_admin_message_chain(message_chain)
|
||||
|
||||
time.sleep(5)
|
||||
import pkg.utils.updater
|
||||
try:
|
||||
|
|
|
@ -96,6 +96,14 @@ class DataGatherer:
|
|||
# 遍历其中所有模型,求和
|
||||
return sum(self.usage[key_md5]["image"].values())
|
||||
|
||||
def get_total_text_length(self):
|
||||
total = 0
|
||||
for key in self.usage:
|
||||
if "text" not in self.usage[key]:
|
||||
continue
|
||||
total += sum(self.usage[key]["text"].values())
|
||||
return total
|
||||
|
||||
def dump_to_db(self):
|
||||
pkg.utils.context.get_database_manager().dump_usage_json(self.usage)
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ class OpenAIInteract:
|
|||
self.key_mgr = pkg.openai.keymgr.KeysManager(api_key)
|
||||
self.audit_mgr = pkg.audit.gatherer.DataGatherer()
|
||||
|
||||
logging.info("文字总使用量:%d", self.audit_mgr.get_total_text_length())
|
||||
|
||||
openai.api_key = self.key_mgr.get_using_key()
|
||||
|
||||
pkg.utils.context.set_openai_manager(self)
|
||||
|
|
|
@ -295,3 +295,10 @@ class QQBotManager:
|
|||
logging.info("通知管理员:{}".format(message))
|
||||
send_task = self.bot.send_friend_message(config.admin_qq, "[bot]{}".format(message))
|
||||
threading.Thread(target=asyncio.run, args=(send_task,)).start()
|
||||
|
||||
def notify_admin_message_chain(self, message):
|
||||
config = pkg.utils.context.get_config()
|
||||
if hasattr(config, "admin_qq") and config.admin_qq != 0:
|
||||
logging.info("通知管理员:{}".format(message))
|
||||
send_task = self.bot.send_friend_message(config.admin_qq, message)
|
||||
threading.Thread(target=asyncio.run, args=(send_task,)).start()
|
||||
|
|
3
pkg/utils/constants.py
Normal file
3
pkg/utils/constants.py
Normal file
File diff suppressed because one or more lines are too long
BIN
res/alipay.jpg
Normal file
BIN
res/alipay.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
Loading…
Reference in New Issue
Block a user