Skip to content

Commit 8616f3b

Browse files
authored
Merge pull request #3 from Azure-Samples/genai-new
New GenAIScript challenge
2 parents 482f378 + 2fbdcb0 commit 8616f3b

File tree

6 files changed

+155
-0
lines changed

6 files changed

+155
-0
lines changed

β€Ž.github/steps/0-welcome.mdβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This is a hands-on experience designed for you to work through a series of quest
1616
- LangChain.js
1717
- Azure AI Agents Service
1818
- MCP Tools
19+
- Automation with GenAIScript
1920

2021
## πŸ—ΊοΈ How it works
2122

@@ -49,4 +50,6 @@ Click on a quest and follow the instructions to get started.
4950

5051
[![Static Badge](https://img.shields.io/badge/Quest-I_want_to_create_templates-pink)](../../issues/new?title=Quest:+I+want+to+create+templates&labels=quest&body=πŸ“„+Let%27s+create+templates+to+streamline+future+projects%21+Excited+to+design+and+build%21%0A%0A**Please+wait+about+15+seconds.+This+issue+will+automatically+close+and+the+README+will+update+with+your+next+instructions.**)
5152

53+
[![Static Badge](https://img.shields.io/badge/Quest-I_want_to_automate_code_reviews-crimson)](../../issues/new?title=Quest:+I+want+to+automate+code+reviews&labels=quest&body=πŸ“„+Let%27s+use+AI+to+review+your+code%21%0A%0A**Please+click+on+Create+below,+then+wait+about+15+seconds.+This+issue+will+automatically+close+and+the+README+will+update+with+your+next+instructions.**)
54+
5255

File renamed without changes.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# βš™οΈ Quest: I want to automate code reviews
2+
3+
> To reset your progress and select a different quest, click this button:
4+
>
5+
> [![Reset Progess](https://img.shields.io/badge/Reset--Progress-ff3860?logo=mattermost)](../../issues/new?title=Reset+Quest&labels=reset-quest&body=πŸ”„+I+want+to+reset+my+AI+learning+quest+and+start+from+the+beginning.%0A%0A**Please+click+on+Create+below,+then+wait+about+15+seconds.+Your+progress+will+be+reset,+this+issue+will+automatically+close,+and+you+will+be+taken+back+to+the+Welcome+step+to+select+a+new+quest.**)
6+
7+
## πŸ“‹ Pre-requisites
8+
9+
1. A GitHub account
10+
2. [Visual Studio Code](https://code.visualstudio.com/) installed
11+
3. [Node.js](https://nodejs.org/en) installed
12+
13+
## πŸ“ Overview
14+
15+
You will build an **automated code review system** that uses AI to analyze code changes and provide feedback. This system will help you ensure that your code meets the quality standards best practices of your project, while also learning how to use AI to automate some of your development tasks.
16+
17+
## 🧠 Use GenAIScript in VS Code
18+
19+
[GenAIScript](https://microsoft.github.io/genaiscript/) is an extension of the JavaScript language that allows you to write scripts that can interact with AI models. You can create advanced AI agents and workflows in very few lines of code, making it easier to build AI applications. It comes with a Command Line Interface (CLI) that allows you to run scripts, and a Visual Studio Code extension that provides an interactive editor for writing and running your scripts.
20+
21+
Let's start by installing the GenAIScript extension in Visual Studio Code:
22+
23+
1. Click on the **Extensions** icon in the left sidebar of Visual Studio Code, search for **GenAIScript** and **install**.
24+
25+
2. After installation, you will see a new **GenAIScript** icon in the left sidebar and also in the status bar at the bottom of the window. Click on the **GenAIScript** icon in the status bar and select **Start GenAIScript server**.
26+
27+
3. It will take some time to start the server, as it first install all the required dependencies.
28+
29+
### Set up GitHub token
30+
31+
To use GenAIScript with GitHub Models, you need to set up a GitHub token.
32+
33+
1. Open [this link](https://github.com/marketplace/models/azure-openai/gpt-4-1/playground) in a new tab and click on the **Use this model** button.
34+
35+
![Use model](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/use-gh-model.png?raw=true)
36+
37+
Follow the instructions provided to get a free developer key, named Personal Access Token (classic).
38+
39+
2. Create a new file in your project root called `.env` and add the following line:
40+
41+
```text
42+
GITHUB_TOKEN=<your_github_token_here>
43+
```
44+
45+
## βœ… Activity: Create a code review script
46+
47+
Now that you have GenAIScript installed, let's create a script that will analyze code changes and provide feedback.
48+
49+
1. Create a new file in your project directory called `code-review.genai.js`.
50+
51+
2. Open the file and add the following code:
52+
53+
```javascript
54+
const changes = await git.diff({ staged: true });
55+
56+
defDiff("CODE_CHANGES", changes);
57+
58+
$`## Role
59+
You are a senior developer whose job is to review code changes and provide meaningful feedback.
60+
61+
## Task
62+
Review <CODE_CHANGES>, point out possible mistakes or bad practices, and provide suggestions for improvement.
63+
- Be specific about what's wrong and why it's wrong
64+
- Reference proper coding standards and best practices
65+
- Be brief to get your point across
66+
`;
67+
```
68+
69+
Let's break down what this script does:
70+
- It uses the `git.diff()` function to get the staged changes in your Git repository.
71+
- The `defDiff()` function defines a variable `CODE_CHANGES` that contains the code changes, to provide context to the AI model.
72+
- The `$` template literal is used to define the prompt AI model. It instructs the model to review the code changes, point out mistakes, and provide suggestions for improvement.
73+
74+
### Test the code review script
75+
76+
Open the terminal in Visual Studio Code and run the following command to add some changes to your Git repository:
77+
78+
```bash
79+
git add .
80+
```
81+
82+
Then while your `code-review.genai.js` file is open, select the **Run GenAIScript** button at the top right corner of the editor, or use the command palette (Ctrl+Shift+P) and type `GenAIScript: Run Script`.
83+
84+
![Run GenAIScript button](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/run-genaiscript.png?raw=true)
85+
86+
You should then see a new tab open with the AI's code review feedback. It should point out a few things since the model has no knowledge of GenAIScript here, but you can use this as a starting point. Experiment with tweaking the prompt to get more specific feedback based on your coding standards and practices.
87+
88+
### Quest Checklist
89+
90+
To complete this quest and **AUTOMATICALLY UPDATE** your progress, you MUST push your code to the repository as described below.
91+
92+
**Checklist**
93+
- [ ] Have a `code-review.genai.js` file at the root of your project
94+
95+
1. In the terminal, run the following commands to add, commit, and push your changes to the repository:
96+
97+
```bash
98+
git add .
99+
git commit -m "Add code review script"
100+
git push
101+
```
102+
103+
2. After pushing your changes, **WAIT ABOUT 15 SECONDS FOR GITHUB ACTIONS TO UPDATE YOUR README**.
104+
105+
**Checklist**
106+
107+
[![Complete Quest](https://img.shields.io/badge/Complete--Quest-ff3860?logo=esbuild)](/issues/new?title=Quest:+I+want+a+Production-Ready+Template+to+customize&labels=quest&body=πŸš€+I%27ve+browsed+through+the+AI+App+Template+gallery%21%0A%0A**After+you+click+on+Create+below,+wait+about+15+seconds.+This+issue+will+automatically+close,+and+the+README+will+update+with+your+next+instructions.**)
108+
109+
## πŸ“š Further Reading
110+
111+
Here are some additional resources to help you learn more about the Azure Developer CLI (azd) and the templates available:
112+
113+
- [More automation ideas with GenAIScript sample collection](https://microsoft.github.io/genaiscript/samples/)
114+
- [Learn about Generative AI with JavaScript on YouTube](https://aka.ms/genai-js)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Step 9, Complete Quest - Code Review
2+
3+
on:
4+
workflow_dispatch:
5+
issues:
6+
types: [opened]
7+
8+
permissions:
9+
contents: write
10+
issues: write
11+
12+
jobs:
13+
update_step_on_complete_quest:
14+
if: |
15+
github.event.issue.title == 'Quest: I want to automate code reviews'
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Update to step 9
22+
uses: skills/action-update-step@v2
23+
with:
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
from_step: 9
26+
to_step: 10
27+
28+
- name: Comment and close issue
29+
uses: peter-evans/close-issue@v3
30+
with:
31+
comment: |
32+
πŸŽ‰ Congratulations! You've completed the Code Review quest. Your progress has been updated and you can now continue to the next step.
33+
34+
πŸ‘‰ [Go to the main README to continue](../README.md)

β€Ž.gitignoreβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,6 @@ FodyWeavers.xsd
399399

400400
# JetBrains Rider
401401
*.sln.iml
402+
403+
# Environment variables
404+
.env

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- πŸ“Š Connect to external data with RAG, add conversation history with **LangChain.js**
2020
- πŸ€– Build an AI Agent with **Azure AI Foundry Extension**
2121
- 🧰 Extend Agent with MCP Tools using the **AI Toolkit Extension**
22+
- ⚑ Automate your dev workflows with **GitHub Models** and **GenAIScript** _(NO AZURE ACCOUNT NEEDED)_
2223

2324
## 🏁 How to get started
2425

0 commit comments

Comments
Β (0)