MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / usage_demo

Function usage_demo

python/example_code/bedrock/bedrock_wrapper.py:77–109  ·  view source on GitHub ↗

Shows how to list the available foundation models. This demonstration gets the list of available foundation models and prints their respective summaries.

()

Source from the content-addressed store, hash-verified

75
76
77def usage_demo():
78 """
79 Shows how to list the available foundation models.
80 This demonstration gets the list of available foundation models and
81 prints their respective summaries.
82 """
83 logging.basicConfig(level=logging.INFO)
84 print("-" * 88)
85 print("Welcome to the Amazon Bedrock demo.")
86 print("-" * 88)
87
88 bedrock_client = boto3.client(service_name="bedrock", region_name="us-east-1")
89
90 wrapper = BedrockWrapper(bedrock_client)
91
92 print("Listing the available foundation models.")
93
94 try:
95 for model in wrapper.list_foundation_models():
96 print_model_details(model)
97 except ClientError:
98 logger.exception("Couldn't list foundation models.")
99 raise
100
101 print("Getting the details of an individual foundation model.")
102
103 model_id = "amazon.titan-embed-text-v1"
104
105 try:
106 print_model_details(wrapper.get_foundation_model(model_id))
107 except ClientError:
108 logger.exception(f"Couldn't get foundation model {model_id}.")
109 raise
110
111
112def print_model_details(model):

Callers 1

bedrock_wrapper.pyFile · 0.70

Calls 4

get_foundation_modelMethod · 0.95
BedrockWrapperClass · 0.85
print_model_detailsFunction · 0.85

Tested by

no test coverage detected