Skip to content

Commit

Permalink
added exception logger
Browse files Browse the repository at this point in the history
  • Loading branch information
areibman committed Mar 26, 2024
1 parent c529dc5 commit ebcc4d2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tokencost/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import aiohttp
import asyncio
import logging

"""
Prompt (aka context) tokens are based on number of words + other chars (eg spaces and punctuation) in input.
Expand Down Expand Up @@ -46,7 +47,7 @@ async def update_token_costs():
TOKEN_COSTS = await fetch_costs()
print("TOKEN_COSTS updated successfully.")
except Exception as e:
print(f"Failed to update TOKEN_COSTS: {e}")
logging.error(f"Failed to update TOKEN_COSTS: {e}")

with open(os.path.join(os.path.dirname(__file__), "model_prices.json"), "r") as f:
TOKEN_COSTS_STATIC = json.load(f)
Expand All @@ -56,5 +57,5 @@ async def update_token_costs():
try:
asyncio.run(update_token_costs())
except Exception:
print('Failed to update token costs. Using static costs.')
logging.error('Failed to update token costs. Using static costs.')
TOKEN_COSTS = TOKEN_COSTS_STATIC

0 comments on commit ebcc4d2

Please sign in to comment.