Skip to content

Commit 11462df

Browse files
committed
removed AWS reference
2 parents 1e9ab4b + 65ae500 commit 11462df

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

.doc_gen/metadata/bedrock_metadata.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ bedrock_Hello:
2929
- description:
3030
snippet_files:
3131
- javascriptv3/example_code/bedrock/hello.js
32+
Python:
33+
versions:
34+
- sdk_version: 3
35+
github: python/example_code/bedrock
36+
sdkguide:
37+
excerpts:
38+
- description:
39+
snippet_tags:
40+
- bedrock.example_code.hello_bedrock.complete
3241
services:
3342
bedrock: {ListFoundationModels}
3443

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
5+
# snippet-start:[bedrock.example_code.hello_bedrock.complete]
6+
7+
"""
8+
Lists the available Amazon Bedrock models.
9+
"""
10+
import logging
11+
import json
12+
import boto3
13+
14+
15+
from botocore.exceptions import ClientError
16+
17+
18+
logging.basicConfig(level=logging.INFO)
19+
logger = logging.getLogger(__name__)
20+
21+
22+
def list_foundation_models(bedrock_client):
23+
"""
24+
Gets a list of available Amazon Bedrock foundation models.
25+
26+
:return: The list of available bedrock foundation models.
27+
"""
28+
29+
try:
30+
response = bedrock_client.list_foundation_models()
31+
models = response["modelSummaries"]
32+
logger.info("Got %s foundation models.", len(models))
33+
return models
34+
35+
except ClientError:
36+
logger.error("Couldn't list foundation models.")
37+
raise
38+
39+
40+
def main():
41+
"""Entry point for the example. Change region to the region
42+
that you want to use."""
43+
44+
region = "us-east-1"
45+
46+
bedrock_client = boto3.client(service_name="bedrock", region_name=region)
47+
48+
fm_models = list_foundation_models(bedrock_client)
49+
for model in fm_models:
50+
print(f"Model: {model["modelName"]}")
51+
print(json.dumps(model, indent=2))
52+
print("---------------------------\n")
53+
54+
logger.info("Done.")
55+
56+
if __name__ == "__main__":
57+
main()
58+
59+
# snippet-end:[bedrock.example_code.hello_bedrock.complete]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import pytest
5+
import subprocess
6+
import sys
7+
8+
files_under_test = [
9+
# Text models
10+
"hello_bedrock.py"
11+
]
12+
13+
14+
@pytest.mark.integ
15+
@pytest.mark.parametrize("file", files_under_test)
16+
def test_hello_bedrock(file):
17+
result = subprocess.run(
18+
[sys.executable, file],
19+
capture_output=True,
20+
text=True,
21+
)
22+
assert result.stdout != ""
23+
assert result.returncode == 0

0 commit comments

Comments
 (0)