mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-23 07:35:06 +01:00
remove failing credit_grants API call (fix #163)
This commit is contained in:
@@ -282,19 +282,6 @@ class OpenAIHelper:
|
||||
num_tokens += 3 # every reply is primed with <|start|>assistant<|message|>
|
||||
return num_tokens
|
||||
|
||||
def get_grant_balance(self):
|
||||
"""Gets remaining grant balance for new users from OpenAI API.
|
||||
|
||||
:return: remaining grant balance
|
||||
"""
|
||||
headers = {
|
||||
"Authorization": f"Bearer {openai.api_key}"
|
||||
}
|
||||
response = requests.get("https://api.openai.com/dashboard/billing/credit_grants", headers=headers)
|
||||
billing_data = json.loads(response.text)
|
||||
balance = billing_data["total_available"]
|
||||
return balance
|
||||
|
||||
def get_billing_current_month(self):
|
||||
"""Gets billed usage for current month from OpenAI API.
|
||||
|
||||
|
||||
@@ -118,9 +118,6 @@ class ChatGPTTelegramBot:
|
||||
text_budget += f"You have a remaining budget of ${budget:.2f} this month.\n"
|
||||
# add OpenAI account information for admin request
|
||||
if self.is_admin(update):
|
||||
grant_balance = self.openai.get_grant_balance()
|
||||
if grant_balance > 0.0:
|
||||
text_budget += f"Your remaining OpenAI grant balance is ${grant_balance:.2f}.\n"
|
||||
text_budget += f"Your OpenAI account was billed ${self.openai.get_billing_current_month():.2f} this month."
|
||||
|
||||
usage_text = text_current_conversation + text_today + text_month + text_budget
|
||||
|
||||
Reference in New Issue
Block a user