New aws error
#7
by
Gdudjdhq9shdy7whsy7
- opened
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/gradio/queueing.py", line 625, in process_events
response = await route_utils.call_process_api(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/gradio/route_utils.py", line 322, in call_process_api
output = await app.get_blocks().process_api(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/gradio/blocks.py", line 2042, in process_api
result = await self.call_function(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/gradio/blocks.py", line 1589, in call_function
prediction = await anyio.to_thread.run_sync( # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
return await get_async_backend().run_sync_in_worker_thread(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2461, in run_sync_in_worker_thread
return await future
^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 962, in run
result = context.run(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/gradio/utils.py", line 883, in wrapper
response = f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "/home/user/app/app.py", line 371, in process_keys
return asyncio.run(process_keys_async(keys, rate_limit, claude_model))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/user/app/app.py", line 365, in process_keys_async
r = await sort_key(line, rate_limit, claude_model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/app/app.py", line 49, in sort_key
return await get_key_aws_info(_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/app/app.py", line 212, in get_key_aws_info
key_avai = await check_key_aws_availability(key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/app/api_usage.py", line 606, in check_key_aws_availability
models_billing = await check_model_billing(async_session, access_id, access_secret)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/app/api_usage.py", line 726, in check_model_billing
cost_info = await asyncio.gather(*(get_service_cost_and_usage(session, key, secret, service) for service in services))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/app/awsLib.py", line 163, in get_service_cost_and_usage
end_date = now.replace(day=30).strftime('%Y-%m-%d')
^^^^^^^^^^^^^^^^^^^
ValueError: day is out of range for month
import calendar
async def get_service_cost_and_usage(session, key, secret, service="Claude 3 Sonnet (Amazon Bedrock Edition)"):
now = datetime.now(UTC) # Use UTC for AWS requests
six_months_ago = now - relativedelta(months=6)
start_date = six_months_ago.replace(day=1).strftime('%Y-%m-%d')
# Get the last day of the current month
last_day = calendar.monthrange(now.year, now.month)[1]
end_date = now.replace(day=last_day).strftime('%Y-%m-%d')
payload = {
"TimePeriod": {
"Start": start_date,
"End": end_date
},
"Granularity": "MONTHLY",
"Metrics": ["BlendedCost"],
"Filter": {
"Dimensions": {
"Key": "SERVICE",
"Values": [service]
}
}
}
json_payload = json.dumps(payload)
return await send_signed_request_ce(session, "ce", json_payload, key_id=key, secret_key=secret), service
AI mentioned that this is how you can accurately calculate dates, so I wrote up some code as a reference in case it might help.
should work now, thanks for reporting
superdup95
changed discussion status to
closed