Add gpt-4-1106-preview support
but it's not available on the account yet
This commit is contained in:
parent
b863783905
commit
576e7d9de0
2 changed files with 16 additions and 5 deletions
|
@ -12,11 +12,13 @@ from core.utils.storedata import get_stored_list, update_stored_list
|
|||
|
||||
ONE_K = Decimal('1000')
|
||||
# https://openai.com/pricing
|
||||
BASE_COST_GPT_3_5 = Decimal('0.002') # gpt-3.5-turbo: $0.002 / 1K tokens
|
||||
BASE_COST_GPT_3_5 = Decimal('0.002') # gpt-3.5-turbo-1106: $0.002 / 1K tokens
|
||||
BASE_COST_GPT_4 = Decimal('0.03') # gpt-4-1106-preview: $0.03 / 1K tokens
|
||||
# We are not tracking specific tool usage like searches b/c I'm too lazy, use a universal multiplier
|
||||
THIRD_PARTY_MULTIPLIER = Decimal('1.5')
|
||||
PROFIT_MULTIPLIER = Decimal('1.1') # At the time we are really just trying to break even
|
||||
PRICE_PER_1K_TOKEN = BASE_COST_GPT_3_5 * THIRD_PARTY_MULTIPLIER * PROFIT_MULTIPLIER
|
||||
PRICE_PER_1K_TOKEN_GPT4 = BASE_COST_GPT_4 * THIRD_PARTY_MULTIPLIER * PROFIT_MULTIPLIER
|
||||
USD_TO_CNY = Decimal('7.1') # Assuming 1 USD = 7.1 CNY
|
||||
CNY_TO_PETAL = 100 # 100 petal = 1 CNY
|
||||
|
||||
|
@ -51,7 +53,7 @@ async def load_or_refresh_cache():
|
|||
return exchanged_petal_data["exchanged_petal"]
|
||||
|
||||
|
||||
async def count_petal(tokens: int):
|
||||
async def count_petal(tokens: int, gpt4: bool = False):
|
||||
Logger.info(f'{tokens} tokens have been consumed while calling AI.')
|
||||
petal_exchange_rate = await load_or_refresh_cache()
|
||||
price = tokens / ONE_K * PRICE_PER_1K_TOKEN
|
||||
|
|
|
@ -39,10 +39,17 @@ assistant = sync_client.beta.assistants.create(
|
|||
model="gpt-3.5-turbo-1106"
|
||||
)
|
||||
|
||||
assistant_gpt4 = sync_client.beta.assistants.create(
|
||||
name="AkariBot",
|
||||
instructions=INSTRUCTIONS,
|
||||
tools=[{"type": "code_interpreter"}],
|
||||
model="gpt-4-1106-preview"
|
||||
)
|
||||
|
||||
a = module('ask', developers=['Dianliang233'], desc='{ask.help.desc}')
|
||||
|
||||
|
||||
@a.command('[--verbose] <question> {{ask.help}}')
|
||||
@a.command('[-4] <question> {{ask.help}}')
|
||||
@a.regex(r'^(?:question||问|問)[\::]\s?(.+?)[??]$', flags=re.I, desc='{ask.help.regex}')
|
||||
async def _(msg: Bot.MessageSession):
|
||||
is_superuser = msg.check_super_user()
|
||||
|
@ -56,8 +63,10 @@ async def _(msg: Bot.MessageSession):
|
|||
if c == 0 or msg.target.target_from == 'TEST|Console' or is_superuser:
|
||||
if hasattr(msg, 'parsed_msg'):
|
||||
question = msg.parsed_msg['<question>']
|
||||
gpt4 = bool(msg.parsed_msg['-4'])
|
||||
else:
|
||||
question = msg.matched_msg[0]
|
||||
gpt4 = False
|
||||
if await check_bool(question):
|
||||
await msg.finish(rickroll(msg))
|
||||
|
||||
|
@ -69,7 +78,7 @@ async def _(msg: Bot.MessageSession):
|
|||
])
|
||||
run = await client.beta.threads.runs.create(
|
||||
thread_id=thread.id,
|
||||
assistant_id=assistant.id,
|
||||
assistant_id=assistant_gpt4.id if gpt4 else assistant.id,
|
||||
)
|
||||
while True:
|
||||
run = await client.beta.threads.runs.retrieve(
|
||||
|
@ -88,7 +97,7 @@ async def _(msg: Bot.MessageSession):
|
|||
tokens = count_token(res)
|
||||
|
||||
if not is_superuser:
|
||||
petal = await count_petal(tokens)
|
||||
petal = await count_petal(tokens, gpt4)
|
||||
msg.data.modify_petal(-petal)
|
||||
else:
|
||||
petal = 0
|
||||
|
|
Reference in a new issue