diff --git a/06_CodeGeneration/00_code_generatation_w_bedrock.ipynb b/06_CodeGeneration/00_code_generatation_w_bedrock.ipynb index 38c3e545..f3de3465 100644 --- a/06_CodeGeneration/00_code_generatation_w_bedrock.ipynb +++ b/06_CodeGeneration/00_code_generatation_w_bedrock.ipynb @@ -47,7 +47,7 @@ "- Price (price at which each product was sold)\n", "\n", "#### Implementation\n", - "To fulfill this use case, in this notebook we will show how to generate code for a given prompt.We will use the Anthropic Claude v2 using the Amazon Bedrock API with Boto3 client. " + "To fulfill this use case, in this notebook we will show how to generate code for a given prompt. We will use the Anthropic Claude v2 using the Amazon Bedrock API with Boto3 client. " ] }, { @@ -87,7 +87,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Optional - To execute the generated code in this notebook\n", + "# To execute the generated code in this notebook\n", "%pip install matplotlib" ] }, @@ -442,13 +442,11 @@ "metadata": {}, "source": [ "## Conclusion\n", - "You have now experimented with using `boto3` SDK which provides a vanilla exposure to Amazon Bedrock API. Using this API you generate a python program to analyze and visualize given sales data'\n", + "You have now experimented with using `boto3` SDK which provides a vanilla exposure to Amazon Bedrock API. Using this API you generate a python program to analyze and visualize given sales data.\n", "\n", "### Take aways\n", "- Adapt this notebook to experiment with different models available through Amazon Bedrock such as Amazon Titan and AI21 Labs Jurassic models.\n", - "- Change the prompts to your specific usecase and evaluate the output of different models.\n", - "- Play with the token length to understand the latency and responsiveness of the service.\n", - "- Apply different prompt engineering principles to get better outputs.\n", + "\n", "\n", "## Thank You" ] diff --git a/06_CodeGeneration/01_sql_query_generate_w_bedrock.ipynb b/06_CodeGeneration/01_sql_query_generate_w_bedrock.ipynb index 31135b55..ae1bebff 100644 --- a/06_CodeGeneration/01_sql_query_generate_w_bedrock.ipynb +++ b/06_CodeGeneration/01_sql_query_generate_w_bedrock.ipynb @@ -33,7 +33,7 @@ "#### 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", "\n", - "![](./images/bedrock-code-gen.png)\n", + "![](./images/sql-query-generation.png)\n", "\n", "#### Use case\n", "Let's take the use case to generate SQL queries to analyze sales data, focusing on trends, top products and average sales.\n", @@ -173,29 +173,6 @@ " }) " ] }, - { - "cell_type": "markdown", - "id": "c4ca6751", - "metadata": {}, - "source": [ - "The Amazon Bedrock API provides you with an API `invoke_model` which accepts the following:\n", - "- `modelId`: This is the model ARN for the various foundation models available under Amazon Bedrock\n", - "- `accept`: The type of input request\n", - "- `contentType`: The content type of the output\n", - "- `body`: A json string consisting of the prompt and the configurations\n", - "\n", - "Available text generation models under Amazon Bedrock have the following IDs:\n", - "- `amazon.titan-tg1-large`\n", - "- `amazon.titan-e1t-medium`\n", - "- `ai21.j2-grande-instruct`\n", - "- `ai21.j2-jumbo-instruct`\n", - "- `ai21.j2-mid`\n", - "- `ai21.j2-ultra`\n", - "- `anthropic.claude-instant-v1`\n", - "- `anthropic.claude-v1`\n", - "- `anthropic.claude-v2`" - ] - }, { "cell_type": "markdown", "id": "088cf6bf-dd73-4710-a0cc-6c11d220c431", @@ -417,8 +394,6 @@ "\n", "### Take aways\n", "- Adapt this notebook to experiment with different models available through Amazon Bedrock such as Anthropic Claude and AI21 Labs Jurassic models.\n", - "- Change the prompts to your specific usecase and evaluate the output of different models.\n", - "- Play with the token length to understand the latency and responsiveness of the service.\n", "- Apply different prompt engineering principles to get better outputs.\n", "\n", "## Thank You" diff --git a/06_CodeGeneration/02_code_interpret_w_langchain.ipynb b/06_CodeGeneration/02_code_interpret_w_langchain.ipynb index 5421c908..b4780973 100644 --- a/06_CodeGeneration/02_code_interpret_w_langchain.ipynb +++ b/06_CodeGeneration/02_code_interpret_w_langchain.ipynb @@ -7,8 +7,7 @@ "tags": [] }, "source": [ - "# Bedrock with LangChain using a Prompt that includes Context\n", - "\n", + "# Bedrock with LangChain - Explain/Interpret a code snippet or program \n", "> *This notebook should work well with the **`Data Science 3.0`** kernel in SageMaker Studio*" ] }, @@ -28,17 +27,17 @@ "**Note:** *This notebook can be run within or outside of AWS environment.*\n", "\n", "#### Context\n", - "In the previous example `01_sql_query_generation_w_bedrock.ipynb`, we explored how to use Bedrock API. LangChain framework to communicate with Amazon Bedrock API. In this notebook we will try to add a bit more complexity with the help of `PromptTemplates` to leverage the LangChain framework for the similar use case. `PrompTemplates` allow you to create generic shells which can be populated with information later and get model outputs based on different scenarios.\n", + "In the previous example `01_sql_query_generation_w_bedrock.ipynb`, we explored how to use Bedrock API. In this notebook we will try to add a bit more complexity with the help of `PromptTemplates` to leverage the LangChain framework. `PrompTemplates` allow you to create generic shells which can be populated with information later and get model outputs based on different scenarios.\n", "\n", - "As part of this notebook we will explore the use of Amazon Bedrock integration within LangChain framework and how it could be used to generate text with the help of `PromptTemplate`.\n", + "As part of this notebook we will explore the use of Amazon Bedrock integration within LangChain framework and how it could be used to generate or explain code with the help of `PromptTemplate`.\n", "\n", "#### Pattern\n", "We will simply provide the LangChain implementation of 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", "\n", - "![](./images/bedrock-code-gen-langchain.png)\n", + "![](./images/code-interpret-langchain.png)\n", "\n", "#### Use case\n", - "To demonstrate the generation capability of models in Amazon Bedrock, let's take the use case of code explain.\n", + "To demonstrate the code generation capability of models in Amazon Bedrock, let's take the use case of code explain.\n", "\n", "#### Persona\n", "You are Joe, a Java software developer, has been tasked to support a legacy C++ application for Vehicle Fleet Management. You need help to explain or interpret certain complex C++ code snippets as you are performing analyis to identify the business logic and potential problems with the code.\n", diff --git a/06_CodeGeneration/03_code_translate_w_langchain.ipynb b/06_CodeGeneration/03_code_translate_w_langchain.ipynb index a6ab6437..4bc25c03 100644 --- a/06_CodeGeneration/03_code_translate_w_langchain.ipynb +++ b/06_CodeGeneration/03_code_translate_w_langchain.ipynb @@ -19,28 +19,23 @@ "source": [ "## Introduction\n", "\n", - "In this notebook we show you how to generate an email response to a customer who was not happy with the quality of customer service that they received from the customer support engineer. We will provide additional context to the model by providing the contents of the actual email that was received from the unhappy customer.\n", + "In this notebook, you will learn how to translate code from one programming language to another using LLMs on Amazon Bedrock. We will demonstrate the use of LLMs as well as how to utilize LangChain framework to integrate with Bedrock.\n", "\n", - "Because of additional context in the prompt, the text produced by the Amazon Titan Large language model in this notebook is of much better quality and relevance than the content produced earlier through zero-shot prompts.\n", - "\n", - "[LangChain](https://python.langchain.com/docs/get_started/introduction.html) is a framework for developing applications powered by language models. The key aspects of this framework allow us to augment the Large Language Models by chaining together various components to create advanced use cases.\n", - "\n", - "In this notebook we will use the Bedrock API provided by LangChain. The prompt used in this example creates a custom LangChain prompt template for adding context to the text generation request. \n", + "We will use Claude v2 model of Amazon Bedrock in this lab.\n", "\n", "**Note:** *This notebook can be run within or outside of AWS environment.*\n", "\n", "#### Context\n", - "In the previous example `02_code_interpret_w_langchain.ipynb`, we explored how to use LangChain framework to communicate with Amazon Bedrock API. In this notebook we will try to add a bit more complexity with the help of `PromptTemplates` to leverage the LangChain framework for the similar use case. `PrompTemplates` allow you to create generic shells which can be populated with information later and get model outputs based on different scenarios.\n", + "In the previous example `02_code_interpret_w_langchain.ipynb`, we explored how to use LangChain framework to communicate with Amazon Bedrock API. Similar to previous example of code interpret/explain, we will use LangChain and Amazon Bedrock APIs to translate code from one legacy programming language to another.\n", "\n", - "As part of this notebook we will explore the use of Amazon Bedrock integration within LangChain framework and how it could be used to generate text with the help of `PromptTemplate`.\n", "\n", "#### Pattern\n", "We will simply provide the LangChain implementation of 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", "\n", - "![](./images/bedrock-code-gen-langchain.png)\n", + "![](./images/code-translation-langchain.png)\n", "\n", "#### Use case\n", - "To demonstrate how you can use Amazon Bedrock LLMs to port code from one programming language to another.\n", + "To demonstrate how you can use Amazon Bedrock LLMs to translate code from one programming language to another.\n", "\n", "#### Persona\n", "Guides you through translating C++ code to Java using Amazon Bedrock and LangChain APIs. It shows techniques for prompting the model to port C++ code over to Java, handling differences in syntax, language constructs, and conventions between the languages.\n", @@ -422,7 +417,7 @@ "source": [ "## Summary\n", "\n", - "To conclude we learnt that invoking the LLM without any context might not yield the desired results. By adding context and further using the the prompt template to constrain the output from the LLM we are able to successfully get our desired output" + "In this example, you have learned how to translate a legacy C++ program to Java with a simple text prompt using Amazon Bedrock and langchain." ] } ], diff --git a/06_CodeGeneration/images/code-interpret-langchain.png b/06_CodeGeneration/images/code-interpret-langchain.png new file mode 100644 index 00000000..85b3c263 Binary files /dev/null and b/06_CodeGeneration/images/code-interpret-langchain.png differ diff --git a/06_CodeGeneration/images/code-translation-langchain.png b/06_CodeGeneration/images/code-translation-langchain.png new file mode 100644 index 00000000..6fd93581 Binary files /dev/null and b/06_CodeGeneration/images/code-translation-langchain.png differ diff --git a/06_CodeGeneration/images/sql-query-generation.png b/06_CodeGeneration/images/sql-query-generation.png new file mode 100644 index 00000000..207abb0b Binary files /dev/null and b/06_CodeGeneration/images/sql-query-generation.png differ