Archived
1
0
Fork 0

try get exchange rate by api

This commit is contained in:
多羅狼 2023-11-06 01:37:20 +08:00 committed by GitHub
parent 52e07cb5b1
commit c842848571
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,11 +13,17 @@ 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
exchange_rate_api_key = Config('exchange_rate_api_key')
exchange_rate_api_url = f'https://v6.exchangerate-api.com/v6/{exchange_rate_api_key}/pair/USD/CNY/1.0'
exchange_rate_data = await get_url(exchange_rate_api_url, 200, fmt='json')
if data['result'] == "success":
USD_TO_CNY = Decimal(exchange_rate_data['conversion_result'])
else:
USD_TO_CNY = Decimal('7.3') # Assuming 1 USD = 7.3 CNY
async def count_petal(tokens):
USD_TO_CNY = Decimal('7.3')
CNY_TO_PETAL = 100 # Assuming 1 USD = 7.3 CNY, 100 petal = 1 CNY
CNY_TO_PETAL = 100 # 100 petal = 1 CNY
price = tokens / ONE_K * PRICE_PER_1K_TOKEN
petal = price * USD_TO_CNY * CNY_TO_PETAL
return petal
@ -79,4 +85,4 @@ def lost_petal(msg: Bot.MessageSession, amount):
p = [p]
update_stored_list(msg.target.client_name, 'lostpetal', p)
msg.data.modify_petal(-amount)
return msg.locale.t('petal.message.lost.success', amount=amount)
return msg.locale.t('petal.message.lost.success', amount=amount)