Archived
1
0
Fork 0

Update petal.py

This commit is contained in:
yzhh 2023-11-06 12:34:17 +08:00
parent 5607c1ea5e
commit 7c9b2c8a3b

View file

@ -1,7 +1,7 @@
import os
import json
from datetime import datetime
from datetime import datetime, timedelta
from decimal import Decimal
from config import Config
@ -17,6 +17,7 @@ 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
async def get_exchange_rate():
api_key = Config('exchange_rate_api_key')
api_url = f'https://v6.exchangerate-api.com/v6/{api_key}/pair/USD/CNY/1.0'
@ -25,6 +26,7 @@ async def get_exchange_rate():
return data['conversion_result']
return None
async def load_or_refresh_cache():
cache_dir = Config('cache_path')
file_path = os.path.join(cache_dir, 'exchange_rate_cache.json')
@ -44,6 +46,7 @@ async def load_or_refresh_cache():
return exchange_rate_data
return None
async def count_petal(tokens):
exchange_rate = await load_or_refresh_cache()
if exchange_rate:
@ -55,6 +58,7 @@ async def count_petal(tokens):
petal = price * USD_TO_CNY * CNY_TO_PETAL
return petal
async def gained_petal(msg: Bot.MessageSession, amount):
if Config('openai_api_key') and Config('enable_get_petal'):
limit = Config('gained_petal_limit', 10)