Skip to content

Commit 86d6720

Browse files
authored
simplify variable setup, add graph rag step (#24)
* add graph rag step * add setup script * tide up notes * add image
1 parent c6c1dba commit 86d6720

File tree

15 files changed

+581
-20
lines changed

15 files changed

+581
-20
lines changed

docs/01-Lab-Setup.mdx

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ https://azure.microsoft.com/en-au/pricing/member-offers/credit-for-visual-studio
117117
| AZURE_OPENAI_API_DEPLOYMENT_NAME | completions |
118118
| AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME | embeddings |
119119
| AZURE_OPENAI_API_VERSION | 2023-09-01-preview |
120+
| GRAPH_RAG_API | https://arg-syd-aiapp1day-ca--miqityv.niceisland-66754352.eastus.azurecontainerapps.io |
120121

121122
### Azure Cosmos DB for MongoDB
122123

@@ -141,34 +142,58 @@ Let us test the connection to Cosmos DB instance and OpenAI service.
141142

142143
1. Open VS Code and navigate to the `aiapp1day` repository folder. If you are using Codespaces, you should already be in the repository folder.
143144

144-
2. Switch to VS Code `Search` tab, replace `<MONGODB_Name>` placeholder with your own database name. Search for `<MONGODB_Name>` and replace with `aiapp1day_xxxxx_xx` (for example: aiapp1day_daniel_66). Then click `Replace All` icon, there will be multiple items to be replaced. The placeholder string will be replaced in the whole repo so that you have a dedicated database on the shared Cosmos DB instance.
145+
2. Navigate to the setup folder `~/labs/00-Setup/` within the repository. Go to `Terminal` window in VS Code.
146+
```bash
147+
cd labs/00-Setup/
148+
```
145149

146-
:::info
147-
Make sure the `<` and `>` included in search & replace.
150+
3. Open `setup.sh`, let's update `<MONGODB_Name>` setting with your own database name. Replace `add_value` with `aiapp1day_xxxxx_xx` (for example: aiapp1day_daniel_66).
151+
152+
![edit setting](images/edit-settings.png)
148153

154+
:::info
149155
if you are deploying your own Azure resources, please update above shared keys and connection string with your own.
150156
:::
151157

152-
![alt text](images/setup.png)
158+
4. Update `<MONGODB_CONNECTION_STRING>` with `mongodb+srv://aiapp1dayadmin:Aiapp1daypassword123@arg-syd-aiapp1day-mongo.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000`
159+
160+
5. Update `<AZURE_OPENAI_API_INSTANCE_NAME>` with `arg-syd-aiapp1day-openai`
161+
162+
6. Update `<AZURE_OPENAI_API_KEY>` with `0f73b2e1cba543ce8c9518712a5b1efc`
153163

154-
3. Replace `<MONGODB_CONNECTION_STRING>` with `mongodb+srv://aiapp1dayadmin:Aiapp1daypassword123@arg-syd-aiapp1day-mongo.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000`
164+
7. Update `<GRAPH_RAG_API>` with `https://arg-syd-aiapp1day-ca--miqityv.niceisland-66754352.eastus.azurecontainerapps.io`
155165

156-
4. Replace `<AZURE_OPENAI_API_INSTANCE_NAME>` with `arg-syd-aiapp1day-openai`
166+
8. Go to terminal windows and run below bash command to replace all variables in the repo.
157167

158-
5. Replace `<AZURE_OPENAI_API_KEY>` with `0f73b2e1cba543ce8c9518712a5b1efc`
168+
```bash
169+
chmod +x setup.sh
170+
./setup.sh
171+
```
172+
173+
:::info
174+
If you have issue running above script, you can also carry out variable replacement manually.
175+
176+
Switch to VS Code `Search` tab, replace `<MONGODB_Name>` placeholder with your own database name.
177+
178+
Search for `<MONGODB_Name>` and replace with `aiapp1day_xxxxx_xx` (for example: aiapp1day_daniel_66).
179+
180+
Then click `Replace All` icon, there will be multiple items to be replaced. The placeholder string will be replaced in the whole repo so that you have a dedicated database on the shared Cosmos DB instance.
181+
182+
![alt text](images/setup.png)
183+
:::
159184

160-
6. Navigate to the setup test folder `~/labs/00-Setup/` within the repository.
185+
9. Install node packages for test program.
161186

162187
```bash
163188
npm install
164189
```
165190

166-
7. Test Connection to CosMos Db and OpenAI service. Run the following command in the terminal window to execute the script:
191+
10. Test Connection to CosMos Db and OpenAI service. Run the following command in the terminal window to execute the script:
167192

168193
```bash
169194
node test.js
170195
```
171196

172-
8. If you see below message in the console, you are ready to go! otherwise, please `YELL for help`.
197+
11. If you see below message in the console, you are ready to go! otherwise, please `YELL for help`.
173198

174199
![alt text](images/setup-test.png)

docs/02-Part-2-Building-Chatbot/4-Using-Langchain.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,27 @@ In this scenario, an agent will be equipped with two tools, one that uses a retr
343343
},
344344
});
345345
346+
const productFeedbackTool = new DynamicTool({
347+
name: "product_feedback_lookup_tool",
348+
description: `Searches Contoso Bike Store feedback based on the question.
349+
Returns the product name, sku and feedback in text format.
350+
If the product is not found, returns null.`,
351+
func: async (input) => {
352+
const url = `${graphRagAPI}/query/global`;
353+
const requestBody = {
354+
index_name: "bike",
355+
query: `whats the top 2 products based on: ${input}?`,
356+
community_level: 1
357+
};
358+
359+
const response = await axios.post(url, requestBody, {});
360+
return response.data.result;
361+
},
362+
});
363+
346364
// Generate OpenAI function metadata to provide to the LLM
347365
// The LLM will use this metadata to decide which tool to use based on the description.
348-
const tools = [productsRetrieverTool, productLookupTool];
366+
const tools = [productsRetrieverTool, productLookupTool, productFeedbackTool];
349367
const modelWithFunctions = chatModel.bind({
350368
functions: tools.map((tool) => convertToOpenAIFunction(tool)),
351369
});
@@ -440,7 +458,7 @@ In this scenario, an agent will be equipped with two tools, one that uses a retr
440458
Please think about the difference between `langchain-rag.js` and `langchain-agent.js`. Which one do you think is better?
441459
:::
442460
443-
12. Experiment with additional questions of your own.
461+
12. Experiment with additional questions of your own. For example, change the question in the `executeAgent` function to `What's the top 2 Tire based on feedback?`. It will use `productFeedbackTool` to invoike API call to Graph RAG endpoint.
444462
445463
## Summary
446464

docs/images/edit-settings.png

33.4 KB
Loading

labs/00-Setup/setup.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
# chmod +x setup.sh
3+
# ./setup.sh
4+
5+
# Define the search and replace pairs
6+
declare -A replacements=(
7+
["<MONGODB_Name>"]="add_value"
8+
["<MONGODB_CONNECTION_STRING>"]="add_value"
9+
["<AZURE_OPENAI_API_INSTANCE_NAME>"]="add_value"
10+
["<AZURE_OPENAI_API_KEY>"]="add_value"
11+
["<GRAPH_RAG_API>"]="add_value"
12+
# see examples below
13+
# ["<MONGODB_Name>"]="aiapp1day_daniel_66"
14+
# ["<MONGODB_CONNECTION_STRING>"]="mongodb+srv://aiapp1dayadmin:Aiapp1daypassword123@arg-syd-aiapp1day-mongo.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000"
15+
# ["<AZURE_OPENAI_API_INSTANCE_NAME>"]="arg-syd-aiapp1day-openai"
16+
# ["<AZURE_OPENAI_API_KEY>"]="0f73b2e1cba543ce8c9518712a5b1efc"
17+
# ["<GRAPH_RAG_API>"]="https://arg-syd-aiapp1day-ca--miqityv.niceisland-66754352.eastus.azurecontainerapps.io"
18+
)
19+
20+
# Check if parent directory exists
21+
if [ ! -d "../" ]; then
22+
echo "Parent directory not found!"
23+
exit 1
24+
fi
25+
26+
echo "Searching for .env and .js files..."
27+
28+
# Find .env and .js files in parent directory
29+
find /workspaces/aiapp1day/ -type f \( -name "*.env" -o -name "*.js" \) -not -path "*/node_modules/*" | while read -r file; do
30+
echo "Processing: $file"
31+
for search in "${!replacements[@]}"; do
32+
replace="${replacements[$search]}"
33+
sed -i "s|${search}|${replace}|g" "$file"
34+
done
35+
done
36+
37+
echo "Replacements complete!"

0 commit comments

Comments
 (0)