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

[New Hack] 070-BuildYourOwnCoPilot - Updated #896

Merged
merged 49 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4e2f4b8
Merge pull request #1 from microsoft/master
joelhulen Sep 2, 2024
f5a7f58
Created WhatTheHack template stub
Sep 2, 2024
b69b89c
Add build modern AI apps hackathon
joelhulen Sep 2, 2024
ff8a6df
Rename and set folder name
joelhulen Oct 8, 2024
2430703
Add starter artifacts
joelhulen Oct 14, 2024
8e4d9cb
Update deployment steps
joelhulen Oct 18, 2024
c40e8ff
Remove old solutions and update coach guides
joelhulen Oct 18, 2024
851b284
Update challenge numbering in code
joelhulen Oct 20, 2024
9ea62b0
Update numbering
joelhulen Oct 20, 2024
b031611
Updated student challenges
joelhulen Oct 21, 2024
eb81762
Address spell check results
joelhulen Oct 21, 2024
9d10671
mark suggestions
markjbrown Oct 22, 2024
b9c78b2
Merge pull request #2 from markjbrown/xxx-BuildModernizeAIApps
joelhulen Oct 22, 2024
96f0a91
Add devcontainer file
joelhulen Oct 22, 2024
3c25af3
Fix spellcheck-related issues
joelhulen Oct 22, 2024
b1c6b66
Update features
joelhulen Oct 30, 2024
d31a979
Challenge updates
joelhulen Oct 30, 2024
11c0a2a
Added codespaces instructions
joelhulen Oct 30, 2024
e4e930d
Add debug instructions
joelhulen Oct 30, 2024
526dde7
Update gitignore files
joelhulen Oct 30, 2024
b889e29
Add notes about coach solutions
joelhulen Oct 31, 2024
90d50ae
Update README.md
perktime Nov 5, 2024
bc3986c
Update README.md
perktime Nov 5, 2024
d9157e2
Update Solution-02.md
perktime Nov 5, 2024
5c529aa
Update Solution-03.md
perktime Nov 5, 2024
e5f5dcd
Update Solution-04.md
perktime Nov 5, 2024
cfaa1ff
Update Solution-05.md
perktime Nov 5, 2024
55ca9fe
Update Challenge-03.md
perktime Nov 5, 2024
70b3d28
Update Challenge-04.md
perktime Nov 5, 2024
a39ce70
Update Challenge-05.md
perktime Nov 8, 2024
5efd315
Add missing TODOs to the solution project
joelhulen Nov 15, 2024
09fcad1
Clarify solutions
joelhulen Nov 15, 2024
5588e40
Update README.md
jrzyshr Dec 10, 2024
c6046a7
Update Challenge-00.md
jrzyshr Dec 10, 2024
de98e45
Update Challenge-00.md
jrzyshr Dec 10, 2024
4f3fb18
Update Challenge-00.md
jrzyshr Dec 10, 2024
6339e3a
Update .wordlist.txt
jrzyshr Dec 10, 2024
9bc101b
Update Challenge-01.md
jrzyshr Dec 10, 2024
bf3f00d
Update Challenge-02.md
jrzyshr Dec 10, 2024
074fdb6
Update Challenge-03.md
jrzyshr Dec 10, 2024
b181f45
Update Challenge-04.md
jrzyshr Dec 10, 2024
b9d1f09
Update Challenge-05.md
jrzyshr Dec 10, 2024
55ff6da
Update README.md
jrzyshr Dec 10, 2024
d5b8a03
Update README.md
jrzyshr Dec 10, 2024
687787e
Update README.md
jrzyshr Dec 10, 2024
5981fe1
Update README.md
jrzyshr Dec 10, 2024
a677065
Update README.md
jrzyshr Dec 10, 2024
f3785d9
Update README.md
jrzyshr Dec 10, 2024
164a0d3
Update README.md
jrzyshr Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions 070-BuildYourOwnCopilot/.wordlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
vectorize
vectorized
vectorizing
vectorization
OWASP
Blazor
githubusercontent
azuredeploy
CosmicWorks
Ciprian
Jichici
Hulen
TPM
Codespace
Codespaces
Codespace's
Binary file not shown.
59 changes: 59 additions & 0 deletions 070-BuildYourOwnCopilot/Coach/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# What The Hack - Build Your Own Copilot - Coach Guide

## Introduction

Welcome to the coach's guide for the Build Your Own Copilot What The Hack. Here you will find links to specific guidance for coaches for each of the challenges.

**NOTE:** If you are a Hackathon participant, this is the answer guide. Don't cheat yourself by looking at these during the hack! Go learn something. :)

## Coach's Guides

- Challenge 00: **[Prerequisites - Ready, Set, GO!](./Solution-00.md)**
- Prepare your workstation to work with Azure.
- Challenge 01: **[The Landing Before the Launch](./Solution-01.md)**
- Deploy the solution cloud services in preparation for the launch of the POC.
- Challenge 02: **[Now We're Flying](./Solution-02.md)**
- Experiment with system prompts.
- Challenge 03: **[What's Your Vector, Victor?](./Solution-03.md)**
- Load new data and observe automatic vectorization.
- Challenge 04: **[It's All About the Payload, The Sequel](./Solution-04.md)**
- Extend the solution to handle any type of JSON data.
- Challenge 05: **[The Colonel Needs a Promotion](./Solution-05.md)**
- Add new capability by creating Semantic Kernel plugins.
- Challenge 06: **[Getting Into the Flow](./Solution-06.md)**
- Use ML Prompt Flow to replace portions of the chat service.

## Coach Prerequisites

This hack has pre-reqs that a coach is responsible for understanding and/or setting up BEFORE hosting an event. Please review the [What The Hack Hosting Guide](https://aka.ms/wthhost) for information on how to host a hack event.

The guide covers the common preparation steps a coach needs to do before any What The Hack event, including how to properly configure Microsoft Teams.

### Student Resources

Before the hack, it is the Coach's responsibility to download and package up the contents of the `/Student/Resources` folder of this hack into a "Resources.zip" file. The coach should then provide a copy of the Resources.zip file to all students at the start of the hack.

Always refer students to the [What The Hack website](https://aka.ms/wth) for the student guide: [https://aka.ms/wth](https://aka.ms/wth)

**NOTE:** Students should **not** be given a link to the What The Hack repo before or during a hack. The student guide does **NOT** have any links to the Coach's guide or the What The Hack repo on GitHub.

## Azure Requirements

This hack requires students to have access to an Azure subscription where they can create and consume Azure resources. These Azure requirements should be shared with a stakeholder in the organization that will be providing the Azure subscription(s) that will be used by the students.

- Attendees should have the “Azure account administrator” (or "Owner") role on the Azure subscription in order to authenticate, create and configure the resource group and necessary resources including:
- Azure Cosmos DB for NoSQL API (with RBAC policies)
- Azure Container App with supporting services _or_ Azure Kubernetes Service (AKS)
- Azure OpenAI
- Azure Managed Identity

## Repository Contents

- `./Coach`
- Coach's Guide and related files
- `./Coach/Solutions`
- Solution files with completed example answers to a challenge
- `./Student`
- Student's Challenge Guide
- `./Student/Resources`
- Resource files, sample code, scripts, etc meant to be provided to students. (Must be packaged up by the coach and provided to students at start of event)
14 changes: 14 additions & 0 deletions 070-BuildYourOwnCopilot/Coach/Solution-00.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Challenge 00 - The Landing Before the Launch - Coach's Guide

**[Home](./README.md)** - [Next Solution >](./Solution-01.md)

## Notes & Guidance

Challenge-00 is all about helping the student deploy resources to Azure in preparation for the launch of the POC. The student will deploy services into the landing zone in preparation for the launch of the POC.

> [!TIP]
> If the student does not see data in the `product` and `customer` containers in Azure Cosmos DB, they should try re-running the `postdeployment` `azd` hook. To do this, they can execute the following command in the terminal: `azd hooks run postdeploy`.

### Coach solutions

In the Coach solution folders, each challenge has both a `solution` and `starter` folder. These folders contain snapshots of where the students should be starting out in that challenge (`starter` folder) and where they should end up at the end of the challenge (`solution` folder). If you want to run the fully completed hackathon, then you should run from the `solution` folder in the final challenge folder (`challenge-5`).
238 changes: 238 additions & 0 deletions 070-BuildYourOwnCopilot/Coach/Solution-01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
# Challenge 01 - Finding the kernel of truth - Coach's Guide

[< Previous Solution](./Solution-00.md) - **[Home](./README.md)** - [Next Solution >](./Solution-02.md)

## Notes & Guidance

View the completed code in the `solutions/challenge-1/code` folder.

### [Challenge 1][Exercise 1.1.1]

Exercise:

```csharp
//--------------------------------------------------------------------------------------------------------
// TODO: [Challenge 1][Exercise 1.1.1]
// Explore setting up a Semantic Kernel kernel.
// Explore the use of completion services in the kernel (see the lines above).
// Explore the setup for the Azure OpenAI-based chat completion service.
//--------------------------------------------------------------------------------------------------------
_semanticKernel = builder.Build();
```

---

Solution:

```csharp
_semanticKernel = builder.Build();
```

Trainer notes:

- The Kernel is the core component of the Semantic Kernel library. It is responsible for managing the context and plugins, and for providing the completion services.
- The Kernel builder is used to configure the Kernel and its dependencies.
- The Kernel builder supports dependency injection.
- Semantic Kernel provides a set of extension methods to configure the Kernel builder with the required services.
- The `AddAzureOpenAIChatCompletion` extension method is used to configure the Azure OpenAI-based chat completion service.
- Encourage the participants to identify the Azure OpenAI account they deployed, its endpoint, completion model deployment and API key.

Suggested reading:

- [Understanding the kernel](https://learn.microsoft.com/semantic-kernel/concepts/kernel?pivots=programming-language-csharp)


### [Challenge 1][Exercise 1.2.1]

Exercise:

```csharp
//--------------------------------------------------------------------------------------------------------
// TODO: [Challenge 1][Exercise 1.2.1]
// Explore importing plugins into a Semantic Kernel kernel.
// Explore the implementation of the KnowledgeManagementContextPlugin plugin.
//--------------------------------------------------------------------------------------------------------
_semanticKernel.ImportPluginFromObject(_kmContextPlugin);
```

---

Solution:

```csharp
_semanticKernel.ImportPluginFromObject(_kmContextPlugin);
```

Trainer notes:

- Plugins are a key component of Semantic Kernel. If you have already used plugins from ChatGPT or Copilot extensions in Microsoft 365, you’re already familiar with them. With plugins, you can encapsulate your existing APIs into a collection that can be used by an AI. This allows you to give your AI the ability to perform actions that it wouldn’t be able to do otherwise.
- Behind the scenes, Semantic Kernel leverages function calling, a native feature of most of the latest LLMs to allow LLMs, to perform planning and to invoke your APIs. With function calling, LLMs can request (i.e., call) a particular function. Semantic Kernel then marshals the request to the appropriate function in your code base and returns the results back to the LLM so the LLM can generate a final response.
- The RAG context is built dynamically using the plugins that are imported into the kernel. The plugins are used to provide the context for the LLM to generate responses.
- The main plugin used to generate the context is `KnowledgeManagementContextPlugin`. It uses a list of more atomic plugins, the `MemoryStoreContextPlugin` plugins which retrieve data from a vector memory store.
- Encourage the participants to explore the implementation of the `KnowledgeManagementContextPlugin` and `MemoryStoreContextPlugin` plugins.
- Encourage the participants to explore the chain of calls that leads to the call of the `SetContextPlugins` method in the `KnowledgeManagementContextPlugin` plugin.
- Note that vector memory stores are the focus of one of the following exercises.

Suggested reading:

- [What is a Plugin?](https://learn.microsoft.com/semantic-kernel/concepts/plugins/?pivots=programming-language-csharp)
- [How to use function calling with Azure OpenAI Service](https://learn.microsoft.com/azure/ai-services/openai/how-to/function-calling)

### [Challenge 1][Exercise 1.3.1]

Exercise:

```csharp
//--------------------------------------------------------------------------------------------------------
// TODO: [Challenge 1][Exercise 1.3.1]
// Explore importing plugins into a Semantic Kernel kernel.
// Explore the implementation of the ContextPluginsListPlugin plugin.
//--------------------------------------------------------------------------------------------------------
_semanticKernel.ImportPluginFromObject(_listPlugin);
```

---

Solution:

```csharp
_semanticKernel.ImportPluginFromObject(_listPlugin);
```

Trainer notes:

- One of the immediate questions raised by the previous exercise is how are the context plugins selected and used by the LLM. The `ContextPluginsListPlugin` plugin is responsible for managing the list of context plugins that are used by the LLM.
- Encourage the attendees to explore the implementation of the `ContextPluginsListPlugin` plugin.
- Note how the main role of the `ContextPluginsListPlugin` plugin is to create a list of plugin names and descriptions which are later used by the LLM to decide which plugins to use.
- Note the capability of an LLM to correlate the user question with the descriptions of plugins.

Suggested reading:

- [What is a Planner?](https://learn.microsoft.com/semantic-kernel/concepts/planning?pivots=programming-language-csharp)

### [Challenge 1][Exercise 1.4.1]

Exercise:

```csharp
//--------------------------------------------------------------------------------------------------------
// TODO: [Challenge 1][Exercise 1.4.1]
// Explore using vector stores with a Semantic Kernel kernel.
// Explore the implementation of the VectorMemoryStore class which enables us to use multiple memory store
// implementations provided by Semantic Kernel.
//--------------------------------------------------------------------------------------------------------
var memoryStore = new VectorMemoryStore(
joelhulen marked this conversation as resolved.
Show resolved Hide resolved
```

---

Solution:

```csharp
var memoryStore = new VectorMemoryStore(
joelhulen marked this conversation as resolved.
Show resolved Hide resolved
```

Trainer notes:

- The `VectorMemoryStore` is a key abstraction of the solution accelerator that allows the LLM to interact with multiple memory stores implemented by Semantic Kernel.
- The `VectorMemoryStore` class is a wrapper around the `IMemoryStore` interface that provides the fundamental operations for a memory store: add memory, remove memory, and get all the memories that are closes to a give chunk of text or a vector.
- Encourage the attendees to explore the implementation of the `VectorMemoryStore` class.

### [Challenge 1][Exercise 1.5.1]

Exercise:

```csharp
//--------------------------------------------------------------------------------------------------------
// TODO: [Challenge 1][Exercise 1.5.1]
// Explore the CosmosDB memory store implementation from Semantic Kernel.
//--------------------------------------------------------------------------------------------------------
new AzureCosmosDBNoSQLMemoryStore(
joelhulen marked this conversation as resolved.
Show resolved Hide resolved
```

---

Solution:

```csharp
new AzureCosmosDBNoSQLMemoryStore(
joelhulen marked this conversation as resolved.
Show resolved Hide resolved
```

Trainer notes:

- The `AzureCosmosDBNoSQLMemoryStore` class is an implementation of the `IMemoryStore` interface that provides the fundamental operations for a memory store using Azure Cosmos DB.
- Encourage the attendees to explore the implementation of the `AzureCosmosDBNoSQLMemoryStore` class.
- Encourage the attendees to take a close look at the `UpsertAsync` method that is used to add or update a memory in the memory store.
- Encourage the attendees to take a close look at the `MemoryRecord` class that is used by Semantic Kernel to represent a memory in the memory store.
- Encourage the attendees to take a close look at the `GetNearestMatchesAsync` method that is used to retrieve the memories that are closest to a given vector. Note the query used to retrieve the memories.
- Encourage the attendees to take a close look at the `CreateCollectionAsync` method that is used to create a vector store collection in the Cosmos DB database. Note the indexing policy and the vector embedding policy used to create the collection.
- Encourage the attendees to explore the Azure Cosmos DB account they deployed, the database, and the vector store collections created by the solution accelerator.

### [Challenge 1][Exercise 1.6.1]

Exercise:

```csharp
//--------------------------------------------------------------------------------------------------------
// TODO: [Challenge 1][Exercise 1.6.1]
// Explore the use of text embedding services in the kernel.
// Explore the setup for the Azure OpenAI-based text embedding service.
//--------------------------------------------------------------------------------------------------------
new AzureOpenAITextEmbeddingGenerationService(
```

---

Solution:

```csharp
new AzureOpenAITextEmbeddingGenerationService(
```

Trainer notes:

- The `AzureOpenAITextEmbeddingGenerationService` class is an implementation of the `ITextEmbeddingGenerationService` interface that provides the fundamental operations for a text embedding service using Azure OpenAI.
- Encourage the participants to identify the Azure OpenAI account they deployed, its endpoint, embedding model deployment and API key.
- Note how embeddings are core to implementing a RAG pattern.
- Encourage attendees to explore how items added to Cosmos DB are embedded using the Azure OpenAI text embedding service.
- Explain how the Cosmos DB change feed capability is used to update the embeddings of the memories in the memory store.
- Encourage attendees to explore the `CosmosDBService.StartChangeFeedProcessors` and `CosmosDBService.GenericChangeFeedHandler` methods.
- Encourage attendees to read again the [Key Concepts](https://github.com/Azure/BuildYourOwnCopilot/blob/main/docs/concepts.md) document from the solution accelerator repository to understand the role of embeddings in the solution accelerator.

Suggested reading:

- [Embeddings](https://platform.openai.com/docs/guides/embeddings/use-cases)
- [Build Your Own Copilot with Azure Cosmos DB - Key Concepts](https://github.com/Azure/BuildYourOwnCopilot/blob/main/docs/concepts.md)

### [Challenge 1][Exercise 1.7.1]

Exercise:

```csharp

//--------------------------------------------------------------------------------------------------------
// TODO: [Challenge 1][Exercise 1.7.1]
// Explore importing plugins into a Semantic Kernel kernel.
// Explore the implementation of the MemoryStoreContextPlugin plugin.
//--------------------------------------------------------------------------------------------------------
_contextPlugins.Add(new MemoryStoreContextPlugin(
joelhulen marked this conversation as resolved.
Show resolved Hide resolved
```

---

Solution:

```csharp
_contextPlugins.Add(new MemoryStoreContextPlugin(
joelhulen marked this conversation as resolved.
Show resolved Hide resolved
```

Trainer notes:

- Note how everything comes together in the `MemoryStoreContextPlugin` plugin. This plugin is responsible for retrieving the memories from the memory store and providing them to the LLM.
- Encourage the attendees to explore the implementation of the `MemoryStoreContextPlugin` plugin.
- The solution accelerator uses two types of memory stores: long-term memory stores (with persisted memories) and short-term memory stores (with memories that are kept in memory for a short period of time).
- Note how the list of context plugins contains several long-term ones and one short-term one.
- Note how the list of long-term memory context plugins is driven by the `ModelRegistryKnowledgeIndexing` application setting. Encourage attendees to explore the relevant sections of the `appsettings.json` file in the `ChatAPI` project.
- Semantic Kernel provides the `VolatileMemoryStore` class to implement short-term memory stores.
- Encourage the attendees to explore the initialization of the short-term memory store via the `EnsureShortTermMemory` method.
- Challenge the attendees to identify the sources of the short-term memories in the storage account deployed by the solution accelerator.
Loading