What is AWS Bedrock
Amazon Bedrock is a fully managed service and it is serverless in nature that provides a selection of high-performing foundation models (FMs) from leading AI companies, including AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon itself. The service offers a unified API and a range of features to simplify the development of generative AI applications, making it accessible to a wider range of users without compromising on privacy and security.
Features in AWS Bedrock
Agents for Amazon Bedrock:
Facilitates the creation and deployment of fully managed agents capable of executing complex business tasks.
Achieves this by dynamically invoking APIs, providing a seamless and efficient process for handling various tasks.
Amazon Bedrock Developer Experience:
Simplifies the development process for developers by offering a user-friendly experience.
Enables easy collaboration with a diverse range of high-performing foundation models (FMs), providing flexibility in choosing and working with models.
Knowledge Bases for Amazon Bedrock:
Allows users to connect foundation models (FMs) to data sources within the managed service.
This connection supports retrieval augmented generation (RAG), enhancing the FM's capabilities and making it more knowledgeable about specific domains and organizations.
Amazon Bedrock Security and Compliance:
Ensures the development of generative AI applications that adhere to stringent data security and compliance standards.
Addresses standards such as GDPR and HIPAA, emphasizing the importance of privacy and compliance in the deployment of AI solutions.
Enable Model Access
Login to AWS Console
https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/
Go to Bedrock and Select —> Model Access
Enable Required Model Access
Select the Model you need an Access - Submit
You have to wait till it list as Access
Enable Logging for Troubleshooting
I want to enable logging for Text, Image, Embedding.
Like to Select only Cloudwatch logs, You can enable S3 and Cloudwatch Logs Also
Provided the Log group Name
Let us Test via AWS CLI
Hope you connected with AWS CLI with AccessKey/Secret Credential some Local IDE - Here I am using my Local Laptop with upgraded CLI
In case if you use —> Sagemaker Domain —> Launch App —> Studio -> Provide IAM Role (My Next Blog, I can share information on using Bedrock in Sagemaker Studio Notebook)
Upgrade AWS CLI, Boto and Boto-core
% pip install --no-build-isolation --force-reinstall "boto3>=1.28.57" "awscli>=1.29.57" "botocore>=1.31.57"
List Foundation Model Provider - AWS CLI
$ aws bedrock list-foundation-models | grep providerName | sort -u
      "providerName": "AI21 Labs",
      "providerName": "Amazon",
      "providerName": "Anthropic",
      "providerName": "Cohere",
      "providerName": "Meta",
      "providerName": "Stability AI",
List Foundation Models - AWS CLI
aws bedrock list-foundation-models | grep "modelId" | sort -nr | awk '{print $2}' | sed -e 's/,//g'
"stability.stable-diffusion-xl-v1"
"stability.stable-diffusion-xl-v0"
"stability.stable-diffusion-xl"
"meta.llama2-13b-chat-v1"
"cohere.embed-multilingual-v3"
"cohere.embed-english-v3"
"cohere.command-text-v14"
"cohere.command-light-text-v14"
"anthropic.claude-v2"
"anthropic.claude-v1"
"anthropic.claude-instant-v1"
"amazon.titan-tg1-medium"
"amazon.titan-tg1-large"
"amazon.titan-text-lite-v1"
"amazon.titan-text-express-v1"
"amazon.titan-embed-text-v1"
"amazon.titan-embed-g1-text-02"
"ai21.j2-ultra-v1"
"ai21.j2-ultra"
"ai21.j2-mid-v1"
"ai21.j2-mid"
"ai21.j2-jumbo-instruct"
"ai21.j2-grande-instruct"
Invoke a LLM Model - using Bedrock CLI
aws bedrock-runtime invoke-model \
--model-id ai21.j2-ultra-v1 \
--body "{\"prompt\":\"Write a Article about Cricket World Cup 2011\",\"maxTokens\":200,\"temperature\":0.7,\"topP\":1,\"stopSequences\":[],\"countPenalty\":{\"scale\":0},\"presencePenalty\":{\"scale\":0},\"frequencyPenalty\":{\"scale\":0}}" \
--cli-binary-format raw-in-base64-out \
--region us-east-1 \
invoke-model-output.txt
Explanation for CLI
Parse the Output using jq
$ cat invoke-model-output.txt| jq -r '.completions[].data.text' The 2011 Cricket World Cup was the tenth edition of the Cricket World Cup, the premier international limited-overs cricket tournament. It was held from 19 February to 2 April 2011 in the Indian subcontinent. The 2011 World Cup featured 14 teams, the largest number of teams to play in a Cricket World Cup. The ten Test-playing nations automatically qualified for the tournament, as did Bangladesh and Kenya, who finished in the top two of the 2009 ICC World Cricket League Division Two tournament. The remaining two spots were determined by the 2009 ICC World Cup Qualifier, in which Canada edged out the United Arab Emirates for the final place. The tournament's format consisted of two groups of seven teams, with each team playing the other six teams in its group, and the top four teams from each group qualifying for the quarter-finals. The 2011 Cricket World Cup was one of the most successful World Cups in history, with a number of record-breaking performances. The semi-finals were contested by the four top teams, with India defeating Pakistan in the semi-finals and South Africa defeating New Zealand. The final was contested between India and Sri Lanka, with India winning by six wickets. India's victory marked the first time they had won the Cricket World Cup. Overall, the tournament was enjoyed by millions of cricket fans around the world,
Interesting :)