Skip to content

Commit

Permalink
优化:修复一些已知问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonely-Sails committed Aug 30, 2024
1 parent ff37e08 commit 7eaf595
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
9 changes: 5 additions & 4 deletions BotServer/Plugins/Expand/Ai.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from openai import AsyncClient
from openai import RateLimitError, BadRequestError
from pathlib import Path
from tempfile import TemporaryDirectory

Expand All @@ -7,13 +9,12 @@
from nonebot.rule import to_me

from Scripts.Config import config
from Scripts.Globals import openai
from Scripts.Network import download
from Scripts.Utils import Rules, get_permission

logger.debug('加载 Ai 功能完毕!')
messages = [{'role': 'system', 'content': config.ai_role_message}]
client = openai.AsyncClient(base_url='https://api.moonshot.cn/v1', api_key=config.ai_api_key)
client = AsyncClient(base_url='https://api.moonshot.cn/v1', api_key=config.ai_api_key)

matcher = on_message(rule=to_me() & Rules.command_rule, priority=15, block=False, )

Expand All @@ -33,9 +34,9 @@ async def handle_message(bot: Bot, event: GroupMessageEvent):
completion = await client.chat.completions.create(
messages=messages, model='moonshot-v1-8k', temperature=0.3
)
except openai.RateLimitError:
except RateLimitError:
await matcher.finish(MessageSegment.reply(event.message_id) + '啊哦!你问的太快啦,我的脑袋转不过来了 TwT')
except openai.BadRequestError as error:
except BadRequestError as error:
await matcher.finish(MessageSegment.reply(event.message_id) + F'啊哦!遇到错误:{error.message}')
response = completion.choices[0]
if text := response.message.content:
Expand Down
13 changes: 1 addition & 12 deletions BotServer/Scripts/Globals.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
from importlib import util

from nonebot.log import logger

from Scripts.Config import config

uuid_caches: dict[str, str] = {}
cpu_occupation: dict[str, list] = {}
ram_occupation: dict[str, list] = {}

openai = None
render_template = None

if config.ai_enabled:
if util.find_spec('openai') is None:
logger.error('你已开启 Ai 功能,但却没有安装 OpenAi 库!请先安装后再启动。')
exit(1)
if config.image_mode:
if util.find_spec('nonebot_plugin_htmlrender') is None:
logger.error('你已开启图片模式,但却没有安装对应的库!请先安装后再启动。')
exit(1)
from .Render import render_template

# LtNsttMj1tUSaieZRjvHHk2h2AZOEKIG
# https://crafatar.com/avatars/{uuid}
4 changes: 4 additions & 0 deletions BotServer/Scripts/Managers/Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ async def disconnect(self):
logger.success(F'已断开与服务器 [{self.name}] 的连接!')

async def send_data(self, event_type: str, data: object = None, wait: bool = True):
if self.websocket.closed:
logger.info(F'检测到与服务器 [{self.name}] 的连接已断开!')
self.status = False
return None
try:
message_data = {'type': event_type}
if data is not None:
Expand Down
2 changes: 1 addition & 1 deletion BotServer/Scripts/Managers/Version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class VersionManager:
version: str = 'v2.0.4'
version: str = 'v2.0.5'
latest_version: str = None

def check_update(self):
Expand Down

0 comments on commit 7eaf595

Please sign in to comment.