revert changes
This commit is contained in:
parent
8ed72ad00d
commit
9ddba60784
2 changed files with 6 additions and 13 deletions
|
@ -10,7 +10,7 @@ from config import Config
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
from core.builtins import Bot, Plain, Image
|
from core.builtins import Bot, Plain, Image
|
||||||
from core.component import module
|
from core.component import module
|
||||||
from core.dirty_check import check, check_bool, rickroll
|
from core.dirty_check import check_bool, rickroll
|
||||||
from core.exceptions import ConfigValueError, NoReportException
|
from core.exceptions import ConfigValueError, NoReportException
|
||||||
from core.petal import count_petal
|
from core.petal import count_petal
|
||||||
from core.utils.cooldown import CoolDown
|
from core.utils.cooldown import CoolDown
|
||||||
|
@ -131,7 +131,8 @@ if Config('openai_api_key'):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
chain.append(Plain(msg.locale.t('ask.message.text2img.error', text=content)))
|
chain.append(Plain(msg.locale.t('ask.message.text2img.error', text=content)))
|
||||||
|
|
||||||
chain = await check_output(msg, chain)
|
if await check_bool(res):
|
||||||
|
await msg.finish(f"{rickroll(msg)}\n{msg.locale.t('petal.message.cost', count=petal)}")
|
||||||
if petal != 0:
|
if petal != 0:
|
||||||
chain.append(Plain(msg.locale.t('petal.message.cost', count=petal)))
|
chain.append(Plain(msg.locale.t('petal.message.cost', count=petal)))
|
||||||
await msg.send_message(chain)
|
await msg.send_message(chain)
|
||||||
|
@ -170,11 +171,3 @@ if Config('openai_api_key'):
|
||||||
|
|
||||||
def count_token(text: str):
|
def count_token(text: str):
|
||||||
return len(enc.encode(text, allowed_special="all")) + SPECIAL_TOKEN_LENGTH + INSTRUCTIONS_LENGTH
|
return len(enc.encode(text, allowed_special="all")) + SPECIAL_TOKEN_LENGTH + INSTRUCTIONS_LENGTH
|
||||||
|
|
||||||
async def check_output(msg: Bot.MessageSession, output: list):
|
|
||||||
output = await check(*output)
|
|
||||||
output = [block['content'] for block in output]
|
|
||||||
for content in output:
|
|
||||||
if isinstance(content, Plain):
|
|
||||||
content.text = content.text.replace("<吃掉了>", msg.locale.t("check.redacted"))
|
|
||||||
return output
|
|
|
@ -4,7 +4,7 @@ import re
|
||||||
from config import Config
|
from config import Config
|
||||||
from core.builtins import Bot
|
from core.builtins import Bot
|
||||||
from core.component import module
|
from core.component import module
|
||||||
from core.dirty_check import check, check_bool, rickroll
|
from core.dirty_check import check_bool, rickroll
|
||||||
from core.exceptions import ConfigValueError
|
from core.exceptions import ConfigValueError
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
from core.petal import count_petal
|
from core.petal import count_petal
|
||||||
|
@ -81,11 +81,11 @@ async def _(msg: Bot.MessageSession):
|
||||||
Logger.info(f'{tokens} tokens have been consumed while calling AI.')
|
Logger.info(f'{tokens} tokens have been consumed while calling AI.')
|
||||||
petal = 0
|
petal = 0
|
||||||
|
|
||||||
output = (await check(output))[0]['content'].replace("<吃掉了>", msg.locale.t("check.redacted"))
|
|
||||||
|
|
||||||
if petal != 0:
|
if petal != 0:
|
||||||
output = f"{output}\n{msg.locale.t('petal.message.cost', count=petal)}"
|
output = f"{output}\n{msg.locale.t('petal.message.cost', count=petal)}"
|
||||||
await wait_msg.delete()
|
await wait_msg.delete()
|
||||||
|
if await check_bool(output):
|
||||||
|
await msg.finish(f"{rickroll(msg)}\n{msg.locale.t('petal.message.cost', count=petal)}")
|
||||||
if msg.target.target_from != 'TEST|Console' and not is_superuser:
|
if msg.target.target_from != 'TEST|Console' and not is_superuser:
|
||||||
qc.reset()
|
qc.reset()
|
||||||
await msg.finish(output, disable_secret_check=True)
|
await msg.finish(output, disable_secret_check=True)
|
||||||
|
|
Reference in a new issue