Shows how to list the available foundation models. This demonstration gets the list of available foundation models and prints their respective summaries.
()
| 75 | |
| 76 | |
| 77 | def 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 | |
| 112 | def print_model_details(model): |
no test coverage detected