Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor spelling, grammatical, and code fixes #237

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ea4fa04
Minor spelling and grammatical fixes. Updated streaming loop in bedro…
jicomusic Apr 23, 2024
d53e7c2
Minor spelling and grammatical fixes. Updated langchain examples in 2…
jicomusic Apr 23, 2024
da5134d
Minor spelling and grammatical fixes. Added an example to 1_managed-r…
jicomusic Apr 25, 2024
f542933
Minor spelling and grammatical fixes.
jicomusic Apr 25, 2024
6487339
Minor spelling and grammatical fixes.
jicomusic Apr 29, 2024
f912cc5
Minor spelling and grammatical fixes.
jicomusic Apr 29, 2024
631448f
Merge pull request #1
jicowan Apr 29, 2024
2a21105
Minor spelling and grammatical fixes. Updated code to use langchain_a…
jicomusic Apr 30, 2024
318b91e
Minor spelling and grammatical fixes. Updated code to use langchain_a…
jicomusic Apr 30, 2024
7e87816
Merge pull request #2 from jicowan/06_OpenSource_examples
jicowan Apr 30, 2024
c0d3b5d
Minor spelling and grammatical fixes. Updated code to use langchain_a…
jicomusic Apr 30, 2024
55f0aaf
Merge remote-tracking branch 'origin/06_OpenSource_examples' into 06_…
jicomusic Apr 30, 2024
cb6a80c
Minor spelling and grammatical fixes. Updated code to use langchain_a…
jicomusic Apr 30, 2024
bc902b3
Merge pull request #3 from jicowan/06_OpenSource_examples
jicowan Apr 30, 2024
add925e
Minor spelling and grammatical fixes. Updated code to use langchain_a…
jicomusic May 2, 2024
f87bb2c
Added LCEL example to 01_qa_w_rag_claude.ipynb
jicomusic May 3, 2024
d377ca6
Fixed lots of code, grammar, and spelling issues with 02_rag_claude_t…
jicomusic May 3, 2024
d8e803a
Merge pull request #4
jicowan May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
132 changes: 63 additions & 69 deletions 00_Prerequisites/bedrock_basics.ipynb

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions 01_Text_generation/00_text_generation_w_bedrock.ipynb
Expand Up @@ -31,18 +31,18 @@
"To demonstrate the text generation capability of Amazon Bedrock, we will explore the use of Boto3 client to communicate with Amazon Bedrock API. We will demonstrate different configurations available as well as how simple input can lead to desired outputs.\n",
"\n",
"#### Pattern\n",
"We will simply provide the Amazon Bedrock API with an input consisting of a task, an instruction and an input for the model under the hood to generate an output without providing any additional example. The purpose here is to demonstrate how the powerful LLMs easily understand the task at hand and generate compelling outputs.\n",
"We will simply provide the Amazon Bedrock API with an input consisting of a task, an instruction and an input for the model under the hood to generate an output without providing any additional example. The purpose here is to demonstrate how LLMs easily understand the task at hand and generate compelling outputs.\n",
"\n",
"![](./images/bedrock.jpg)\n",
"\n",
"#### Use case\n",
"To demonstrate the generation capability of models in Amazon Bedrock, let's take the use case of email generation.\n",
"\n",
"#### Persona\n",
"You are Bob a Customer Service Manager at AnyCompany and some of your customers are not happy with the customer service and are providing negative feedbacks on the service provided by customer support engineers. Now, you would like to respond to those customers humbly aplogizing for the poor service and regain trust. You need the help of an LLM to generate a bulk of emails for you which are human friendly and personalized to the customer's sentiment from previous email correspondence.\n",
"You are Bob a Customer Service Manager at AnyCompany and some of your customers are not happy with the customer service and are providing negative feedbacks on the service provided by customer support engineers. Now, you would like to respond to those customers humbly apologizing for the poor service and regain their trust. You need the help of an LLM to generate a bulk of emails for you which are human friendly and personalized to the customer's sentiment from previous email correspondence.\n",
"\n",
"#### Implementation\n",
"To fulfill this use case, in this notebook we will show how to generate an email with a thank you note based on the customer's previous email.We will use the Amazon Titan Text Large model using the Amazon Bedrock API with Boto3 client. "
"To fulfill this use case, in this notebook we will show how to generate an email with a thank-you note based on the customer's previous email. We will use the Amazon Titan Text Large model using the Amazon Bedrock API with Boto3 client. "
]
},
{
Expand All @@ -57,12 +57,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "776fd083",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import os\n",
Expand All @@ -72,7 +70,9 @@
"import botocore\n",
"\n",
"boto3_bedrock = boto3.client('bedrock-runtime')"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -86,19 +86,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "45ee2bae-6415-4dba-af98-a19028305c98",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# create the prompt\n",
"prompt_data = \"\"\"\n",
"Command: Write an email from Bob, Customer Service Manager, to the customer \"John Doe\" \n",
"who provided negative feedback on the service provided by our customer support \n",
"engineer\"\"\"\n"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -112,12 +112,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "8af670eb-ad02-40df-a19c-3ed835fac8d9",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"body = json.dumps({\n",
" \"inputText\": prompt_data, \n",
Expand All @@ -128,7 +126,9 @@
" \"topP\":0.9\n",
" }\n",
" }) "
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -141,7 +141,7 @@
"- `contentType`: The content type of the output\n",
"- `body`: A json string consisting of the prompt and the configurations\n",
"\n",
"Check [documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids-arns.html) for Available text generation model Ids"
"Check the [documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids-arns.html) for Available text generation model Ids"
]
},
{
Expand All @@ -164,12 +164,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "ecaceef1-0f7f-4ae5-8007-ff7c25335251",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"modelId = 'amazon.titan-tg1-large' # change this to use a different version from the model provider\n",
"accept = 'application/json'\n",
Expand All @@ -186,29 +184,31 @@
" \n",
" if error.response['Error']['Code'] == 'AccessDeniedException':\n",
" print(f\"\\x1b[41m{error.response['Error']['Message']}\\\n",
" \\nTo troubeshoot this issue please refer to the following resources.\\\n",
" \\nTo troubleshoot this issue please refer to the following resources.\\\n",
" \\nhttps://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_access-denied.html\\\n",
" \\nhttps://docs.aws.amazon.com/bedrock/latest/userguide/security-iam.html\\x1b[0m\\n\")\n",
" \n",
" else:\n",
" raise error\n"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"execution_count": null,
"id": "3748383a-c140-407f-a7f6-8f140ad57680",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# The relevant portion of the response begins after the first newline character\n",
"# Below we print the response beginning after the first occurence of '\\n'.\n",
"# Below we print the response beginning after the first occurrence of '\\n'.\n",
"\n",
"email = outputText[outputText.index('\\n')+1:]\n",
"print(email)\n"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -223,12 +223,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad073290",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"output = []\n",
"try:\n",
Expand All @@ -251,13 +249,15 @@
" \n",
" if error.response['Error']['Code'] == 'AccessDeniedException':\n",
" print(f\"\\x1b[41m{error.response['Error']['Message']}\\\n",
" \\nTo troubeshoot this issue please refer to the following resources.\\\n",
" \\nTo troubleshoot this issue please refer to the following resources.\\\n",
" \\nhttps://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_access-denied.html\\\n",
" \\nhttps://docs.aws.amazon.com/bedrock/latest/userguide/security-iam.html\\x1b[0m\\n\")\n",
" \n",
" else:\n",
" raise error"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -286,11 +286,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "9cdf9261-1002-4da7-9124-943f72b43486",
"metadata": {},
"source": [],
"outputs": [],
"source": []
"execution_count": null
}
],
"metadata": {
Expand Down Expand Up @@ -871,9 +871,9 @@
],
"instance_type": "ml.t3.medium",
"kernelspec": {
"display_name": "Python 3 (Data Science 3.0)",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/sagemaker-data-science-310-v1"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down