superdup95 commited on
Commit
548b54a
1 Parent(s): f65b699

Update api_usage.py

Browse files
Files changed (1) hide show
  1. api_usage.py +22 -9
api_usage.py CHANGED
@@ -434,12 +434,16 @@ def check_key_aws_availability(key):
434
  quarantine = True
435
 
436
  enable_region = check_bedrock_invoke(session)
 
 
 
 
 
 
437
  cost = check_aws_billing(session)
438
- if enable_region:
439
- return True, username[0], root, admin, quarantine, enable_region, cost
440
- if root or admin:
441
- return True, username[0], root, admin, quarantine, "None", cost
442
- return True, username[0], root, admin, quarantine, "None", cost
443
 
444
  def check_username(session):
445
  try:
@@ -469,13 +473,13 @@ def invoke_claude(session, region, modelId):
469
  response = bedrock_runtime.invoke_model(body=body, modelId=modelId)
470
  except bedrock_runtime.exceptions.ValidationException as error:
471
  #print(error.response['Error'])
472
- return region
 
473
  except bedrock_runtime.exceptions.AccessDeniedException as error:
474
  #print(error.response['Error'])
475
  return
476
  except bedrock_runtime.exceptions.ResourceNotFoundException as error:
477
  #print(error.response['Error'])
478
- return invoke_claude(session, region, "anthropic.claude-v2:1")
479
  except Exception as e:
480
  #print(e)
481
  return
@@ -483,12 +487,21 @@ def invoke_claude(session, region, modelId):
483
  def check_bedrock_invoke(session):
484
  regions = ['us-east-1', 'us-west-2', 'eu-central-1', 'ap-southeast-1', 'ap-northeast-1']
485
  enable_region = []
 
486
  with concurrent.futures.ThreadPoolExecutor() as executer:
487
  futures = [executer.submit(invoke_claude, session, region, "anthropic.claude-v2") for region in regions]
488
  for future in concurrent.futures.as_completed(futures):
489
  if future.result():
490
- enable_region.append(future.result())
491
- return enable_region
 
 
 
 
 
 
 
 
492
 
493
  def check_aws_billing(session):
494
  try:
 
434
  quarantine = True
435
 
436
  enable_region = check_bedrock_invoke(session)
437
+ enable_region_v2 = "None"
438
+ enable_region_sonnet = "None"
439
+ if enable_region[0]:
440
+ enable_region_v2 = enable_region[0]
441
+ if enable_region[1]:
442
+ enable_region_sonnet = enable_region[1]
443
  cost = check_aws_billing(session)
444
+ if enable_region[0]:
445
+ return True, username[0], root, admin, quarantine, enable_region_v2, enable_region_sonnet, cost
446
+ return True, username[0], root, admin, quarantine, enable_region_v2, enable_region_sonnet, cost
 
 
447
 
448
  def check_username(session):
449
  try:
 
473
  response = bedrock_runtime.invoke_model(body=body, modelId=modelId)
474
  except bedrock_runtime.exceptions.ValidationException as error:
475
  #print(error.response['Error'])
476
+ if 'max_tokens_to_sample' in error.response['Error']['Message']:
477
+ return region
478
  except bedrock_runtime.exceptions.AccessDeniedException as error:
479
  #print(error.response['Error'])
480
  return
481
  except bedrock_runtime.exceptions.ResourceNotFoundException as error:
482
  #print(error.response['Error'])
 
483
  except Exception as e:
484
  #print(e)
485
  return
 
487
  def check_bedrock_invoke(session):
488
  regions = ['us-east-1', 'us-west-2', 'eu-central-1', 'ap-southeast-1', 'ap-northeast-1']
489
  enable_region = []
490
+ enable_region_sonnet = []
491
  with concurrent.futures.ThreadPoolExecutor() as executer:
492
  futures = [executer.submit(invoke_claude, session, region, "anthropic.claude-v2") for region in regions]
493
  for future in concurrent.futures.as_completed(futures):
494
  if future.result():
495
+ enable_region.append(future.result())
496
+ futures = [executer.submit(invoke_claude, session, region, "anthropic.claude-v2:1") for region in regions]
497
+ for future in concurrent.futures.as_completed(futures):
498
+ if future.result():
499
+ enable_region.append(future.result())
500
+ futures = [executer.submit(invoke_claude, session, region, "anthropic.claude-3-sonnet-20240229-v1:0") for region in regions]
501
+ for future in concurrent.futures.as_completed(futures):
502
+ if future.result():
503
+ enable_region_sonnet.append(future.result())
504
+ return enable_region, enable_region_sonnet
505
 
506
  def check_aws_billing(session):
507
  try: