Update api_usage.py
Browse files- api_usage.py +4 -5
api_usage.py
CHANGED
|
@@ -459,23 +459,22 @@ def check_policy(iam, username):
|
|
| 459 |
except botocore.exceptions.ClientError as error:
|
| 460 |
return False, error.response['Error']['Code']
|
| 461 |
|
| 462 |
-
def invoke_claude(session, region):
|
| 463 |
try:
|
| 464 |
bedrock_runtime = session.client("bedrock-runtime", region_name=region)
|
| 465 |
body = json.dumps({
|
| 466 |
"prompt": "\n\nHuman:\n\nAssistant:",
|
| 467 |
"max_tokens_to_sample": 0
|
| 468 |
})
|
| 469 |
-
response = bedrock_runtime.invoke_model(body=body, 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
|
| 479 |
except Exception as e:
|
| 480 |
#print(e)
|
| 481 |
return
|
|
@@ -484,7 +483,7 @@ 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) for region in regions]
|
| 488 |
for future in concurrent.futures.as_completed(futures):
|
| 489 |
if future.result():
|
| 490 |
enable_region.append(future.result())
|
|
|
|
| 459 |
except botocore.exceptions.ClientError as error:
|
| 460 |
return False, error.response['Error']['Code']
|
| 461 |
|
| 462 |
+
def invoke_claude(session, region, modelId):
|
| 463 |
try:
|
| 464 |
bedrock_runtime = session.client("bedrock-runtime", region_name=region)
|
| 465 |
body = json.dumps({
|
| 466 |
"prompt": "\n\nHuman:\n\nAssistant:",
|
| 467 |
"max_tokens_to_sample": 0
|
| 468 |
})
|
| 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 |
except bedrock_runtime.exceptions.ResourceNotFoundException as error:
|
| 476 |
#print(error.response['Error'])
|
| 477 |
+
return invoke_claude(session, region, "anthropic.claude-v2:1")
|
| 478 |
except Exception as e:
|
| 479 |
#print(e)
|
| 480 |
return
|
|
|
|
| 483 |
regions = ['us-east-1', 'us-west-2', 'eu-central-1', 'ap-southeast-1', 'ap-northeast-1']
|
| 484 |
enable_region = []
|
| 485 |
with concurrent.futures.ThreadPoolExecutor() as executer:
|
| 486 |
+
futures = [executer.submit(invoke_claude, session, region, "anthropic.claude-v2") for region in regions]
|
| 487 |
for future in concurrent.futures.as_completed(futures):
|
| 488 |
if future.result():
|
| 489 |
enable_region.append(future.result())
|