Skip to content

Commit

Permalink
Added code generation module and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
awsdabra committed Aug 15, 2023
1 parent 7e3c85b commit 43b01d3
Show file tree
Hide file tree
Showing 9 changed files with 4,193 additions and 0 deletions.
995 changes: 995 additions & 0 deletions 06_CodeGeneration/00_code_generatation_w_bedrock.ipynb

Large diffs are not rendered by default.

1,025 changes: 1,025 additions & 0 deletions 06_CodeGeneration/01_sql_query_generate_w_bedrock.ipynb

Large diffs are not rendered by default.

967 changes: 967 additions & 0 deletions 06_CodeGeneration/02_code_interpret_w_langchain.ipynb

Large diffs are not rendered by default.

1,132 changes: 1,132 additions & 0 deletions 06_CodeGeneration/03_code_translate_w_langchain.ipynb

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions 06_CodeGeneration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Lab 6 - Code Generation

## Overview

In this lab, you will learn to use LLMs on Amazon Bedrock for code generation, SQL query creation, code explanation, and code translation across languages. We will demo Bedrock's API (boto3) as well as its integration with LangChain.

First, we will generate Python code and SQL queries by providing context about a dataset. Next, we will explain code and translate between languages. We will explore these use cases with both the Bedrock API directly and via LangChain integration.

## Audience

Architects and developers who want to learn how to use Amazon Bedrock LLMs to generate, explain and translate code.

Some of the business use cases for code generation include:

- Code Translation
- Code Explain and Reviews
- Database or SQL query generation
- Rapid Prototyping
- Issue Identification
- Bug Fixing
- Code Optimization

## Workshop Notebooks

1. [Code Generation](./00_code_generatation_w_bedrock.ipynb)- Demonstrates how to generate Python code using Natural language. It shows examples of prompting to generate simple functions, classes, and full programs in Python for Data Analyst to perform sales analysis on a given Sales CSV dataset.

2. [Database or SQL Query Generation](./01_sql_query_generate_w_bedrock.ipynb) - Focuses on generating SQL queries with Amazon Bedrock APIs. It includes examples of generating both simple and complex SQL statements for a given data set and database schema.

3. [Code Explanation](./02_code_interpret_w_langchain.ipynb) - Uses Bedrock's foundation models to generate explanations for complex C++ code snippets. It shows how to carefully craft prompts to get the model to generate comments and documentation that explain the functionality and logic of complicated C++ code examples. Prompts can be easily updated for another programming languages.

4. [Code Translation ](./03_code_translate_w_langchain.ipynb) - 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.


## Architecture

![Bedrock](./images/bedrock-code-gen.png)
![Bedrock](./images/bedrock-code-gen-langchain.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 06_CodeGeneration/images/bedrock-code-gen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions 06_CodeGeneration/sales.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
date,product_id,price,units_sold
2023-01-01,P001,50,20
2023-01-02,P002,60,15
2023-01-03,P001,50,18
2023-01-04,P003,70,30
2023-01-05,P001,50,25
2023-01-06,P002,60,22
2023-01-07,P003,70,24
2023-01-08,P001,50,28
2023-01-09,P002,60,17
2023-01-10,P003,70,29
2023-02-11,P001,50,23
2023-02-12,P002,60,19
2023-02-13,P001,50,21
2023-02-14,P003,70,31
2023-03-15,P001,50,26
2023-03-16,P002,60,20
2023-03-17,P003,70,33
2023-04-18,P001,50,27
2023-04-19,P002,60,18
2023-04-20,P003,70,32
2023-04-21,P001,50,22
2023-04-22,P002,60,16
2023-04-23,P003,70,34
2023-05-24,P001,50,24
2023-05-25,P002,60,21
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Labs include:
- **Questions Answering** \[Estimated time to complete - 45 mins\]
- **Chatbot** \[Estimated time to complete - 45 mins\]
- **Image Generation** \[Estimated time to complete - 30 mins\]
- **Code Generation** \[Estimated time to complete - 30 mins\]

<div align="center">

Expand Down Expand Up @@ -117,3 +118,13 @@ This repository contains notebook examples for the Bedrock Architecture Patterns
### Text to Image

- [Image Generation with Stable Diffusion](./05_Image/Bedrock%20Stable%20Diffusion%20XL.ipynb): This notebook demonstrates image generation with using the Stable Diffusion model

### Code Generation, SQL Generation, Code Translation and Explanation

1. [Code Generation](./06_CodeGeneration/00_code_generatation_w_bedrock.ipynb)- Demonstrates how to generate Python code using Natural language. It shows examples of prompting to generate simple functions, classes, and full programs in Python for Data Analyst to perform sales analysis on a given Sales CSV dataset.

2. [Database or SQL Query Generation](./06_CodeGeneration/01_sql_query_generate_w_bedrock.ipynb) - Focuses on generating SQL queries with Amazon Bedrock APIs. It includes examples of generating both simple and complex SQL statements for a given data set and database schema.

3. [Code Explanation](./06_CodeGeneration/02_code_interpret_w_langchain.ipynb) - Uses Bedrock's foundation models to generate explanations for complex C++ code snippets. It shows how to carefully craft prompts to get the model to generate comments and documentation that explain the functionality and logic of complicated C++ code examples. Prompts can be easily updated for another programming languages.

4. [Code Translation ](./06_CodeGeneration/03_code_translate_w_langchain.ipynb) - 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.

0 comments on commit 43b01d3

Please sign in to comment.