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

Feature/ocs/upstream #3

Merged
merged 67 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
0113351
upgrade
thivy Feb 4, 2024
add39d6
Merge pull request #2 from thivy/v2-upgrade
thivy Feb 4, 2024
3ad11c6
Update function to handle edge cases
thivy Feb 4, 2024
8ef0879
Update function to handle edge cases
thivy Feb 5, 2024
c03937a
Refactor data storage in Azure Cosmos DB***
thivy Feb 5, 2024
3fdb18d
Merge pull request #310 from thivy/main
thivy Feb 6, 2024
f948635
Update open-ai-app.yml
cmenzi Nov 2, 2023
1bb666d
Update open-ai-app.yml
cmenzi Nov 2, 2023
5c659c5
enable ci/cd for dev and prod
cmenzi Jan 24, 2024
1592139
Feature/ocs/ai logging (#1)
saoc90 Feb 6, 2024
82cef3b
set default values
cmenzi Nov 2, 2023
fae70fd
fix
cmenzi Nov 2, 2023
f5ba1d0
Update open-ai-app.yml
cmenzi Nov 2, 2023
fd05a3d
Add messages to chat home when null extensions or peronas
davidxw Feb 6, 2024
ae66319
fix
cmenzi Nov 2, 2023
2efd6ea
Update open-ai-app.yml
cmenzi Nov 2, 2023
d20e3cb
enable ci/cd for dev and prod
cmenzi Jan 24, 2024
3aee4d5
Update open-ai-app.yml
cmenzi Jan 24, 2024
4f5f5d3
Add migration instructions for new Azure services
davidxw Feb 6, 2024
b6b6663
Feature/ocs/ai logging (#1)
saoc90 Feb 6, 2024
2cdc777
Update open-ai-app.yml
cmenzi Nov 2, 2023
d20f0bf
Update open-ai-app.yml
cmenzi Nov 2, 2023
c30b810
enable ci/cd for dev and prod
cmenzi Jan 24, 2024
b818b7a
Feature/ocs/ai logging (#1)
saoc90 Feb 6, 2024
6ff8264
Merge pull request #311 from davidxw/main
thivy Feb 6, 2024
26065f0
Merge branch 'microsoft-main' into feature/ocs/upstream
saoc90 Feb 6, 2024
1435f23
Move metrics service
saoc90 Feb 6, 2024
a7e5425
Remove unused appInsights resource
saoc90 Feb 7, 2024
290363f
Update user authentication logic***
saoc90 Feb 7, 2024
14d8373
Delete package-lock.json
saoc90 Feb 7, 2024
42b217b
Delete chat-api-data.ts and chat-api-simple.ts
saoc90 Feb 7, 2024
fba9bd3
Refactor code to improve performance and readability
saoc90 Feb 7, 2024
67abcb0
Add chat token service and report token count
saoc90 Feb 7, 2024
621da65
Add reportUserChatMessage function call
saoc90 Feb 8, 2024
76911bb
Update colors and avatar styling
saoc90 Feb 8, 2024
57b79b2
Refactor chat API and token service
saoc90 Feb 9, 2024
693ed9c
Add @azure/monitor-opentelemetry and @radix-ui/react-accordion depend…
saoc90 Feb 9, 2024
cfc61bd
Refactor instrumentation code to use OpenTelemetry metrics
saoc90 Feb 9, 2024
5bcc358
Add console log for Application Insights Connection String
saoc90 Feb 9, 2024
fa6afcf
Add debug logging for OpenTelemetry diagnostics
saoc90 Feb 9, 2024
85f7241
Add console log to getChatMeter function
saoc90 Feb 9, 2024
74d3101
Refactor instrumentation code for Node.js runtime
saoc90 Feb 9, 2024
bb1a3df
Update dependencies and remove unused code
saoc90 Feb 9, 2024
dd37e6e
Add server-side imports and update Azure Monitor configuration
saoc90 Feb 9, 2024
67857b6
Update next.config.js and package.json
saoc90 Feb 9, 2024
fca3550
Update instrumentation and next.config.js
saoc90 Feb 9, 2024
3badcde
Refactor instrumentation code and add Azure Monitor metric exporter
saoc90 Feb 9, 2024
a551e4c
Comment out console.log statement in getChatMeter function
saoc90 Feb 9, 2024
6bfaba9
close stream on error and abort
thivy Feb 12, 2024
55dbe1e
Merge pull request #322 from thivy/main
thivy Feb 12, 2024
33f533c
fix doc id being exposed to client
thivy Feb 13, 2024
ba17a8d
Merge pull request #323 from thivy/fix_docId_issue
thivy Feb 13, 2024
d668fd4
Added ARIA roles and labels
Feb 15, 2024
239f783
alt-text for avatar icons
Feb 15, 2024
ef08321
increase contrast on Chat list group titles
Feb 15, 2024
c95f050
Add aria-labels to menu links
Feb 15, 2024
e60bc4c
Update light mode accent colour for better contrast
Feb 15, 2024
14feee0
more ARIA labelling for dropdowns and sheets across the app
Feb 15, 2024
076b049
Change avatar image alt text to none to indicate decorative
Feb 15, 2024
0da89b7
Merge pull request #339 from microsoft/accessibility
thivy Feb 28, 2024
7839ffd
Fix link in main menu
thivy Feb 29, 2024
0d19294
Merge pull request #345 from microsoft/fix_aria_label
davidxw Feb 29, 2024
896424a
Merge remote-tracking branch 'upstream/main' into feature/ocs/upstream
saoc90 Mar 1, 2024
a90283d
Add log message for blob upload
saoc90 Mar 1, 2024
22797a6
Fix return statement
saoc90 Mar 1, 2024
2cc54cb
Fix experimental flags
saoc90 Mar 1, 2024
ae5df93
feat: Add news articles to ChatHome component
saoc90 Jun 12, 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
  •  
  •  
  •  
12 changes: 8 additions & 4 deletions .github/workflows/open-ai-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
- name: 📦 Package Next application
run: |
cd ./site-deploy
zip Nextjs-site.zip ./* .next -qr
zip Nextjs-site.zip ./* .next -qr

- name: 🔍 Diagnostics
run: |
ls ./src
Expand All @@ -61,6 +61,11 @@ jobs:
environment:
name: "Development"
steps:
- name: 🍏 Set up Node.js version
uses: actions/setup-node@v4
with:
node-version: "20.x"

- name: ⬇️ Download artifact from build job
uses: actions/download-artifact@v4
with:
Expand All @@ -71,7 +76,7 @@ jobs:
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

# Set the build during deployment setting to false. This setting was added in the templates to all azd to work, but breaks deployment via webapps-deploy
# Set the build during deployment setting to false. This setting was added in the templates to all azd to work, but breaks deployment via webapps-deploy
- name: Azure CLI script
uses: azure/CLI@v1
with:
Expand Down Expand Up @@ -127,5 +132,4 @@ jobs:
resource-group-name: ${{ secrets.AZURE_APP_SERVICE_RG_NAME_PROD }}
app-name: ${{ secrets.AZURE_APP_SERVICE_NAME_PROD }}
package: ${{ github.workspace }}/Nextjs-site.zip


1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ next-env.d.ts

.azure/
infra/aad_setup.sh
.vscode
31 changes: 0 additions & 31 deletions .vscode/launch.json

This file was deleted.

23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
1. [Deploy to Azure with GitHub Actions](/docs/4-deploy-to-azure.md)
1. [Add identity provider](/docs/5-add-identity.md)
1. [Chatting with your file](/docs/6-chat-over-file.md)
1. [Environment variables](/docs/7-environment-variables.md)
1. [Persona](/docs/6-persona.md)
1. [Extensions](/docs/8-extensions.md)
1. [Environment variables](/docs/9-environment-variables.md)
1. [Migration considerations](/docs/migration.md)

# Introduction

_Azure Chat Solution Accelerator powered by Azure Open AI Service_

![](/images/intro.png)
![](/docs/images/intro.png)

_Azure Chat Solution Accelerator powered by Azure Open AI Service_ is a solution accelerator that allows organisations to deploy a private chat tenant in their Azure Subscription, with a familiar user experience and the added capabilities of chatting over your data and files.

Expand All @@ -38,25 +41,31 @@ You can deploy the application using one of the following options:

### 1. Azure Developer CLI

> **Important**
> [!IMPORTANT]
> This section will create Azure resources and deploy the solution from your local environment using the Azure Developer CLI. Note that you do not need to clone this repo to complete these steps.

1. Download the [Azure Developer CLI](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/overview)
1. If you have not cloned this repo, run `azd init -t microsoft/azurechat`. If you have cloned this repo, just run 'azd init' from the repo root directory.
1. Run `azd up` to provision and deploy the application

```pwsh
azd init -t microsoft/azurechat
azd up

# if you are wanting to see logs run with debug flag
azd up --debug
```

### 2. Azure Portal Deployment

> **Warning**
> [!WARNING]
> This button will only create Azure resources. You will still need to deploy the application by following the [deploy to Azure section](/docs/4-deploy-to-azure.md) to build and deploy the application using GitHub actions.

Click on the Deploy to Azure button to deploy the Azure resources for the application.

[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://aka.ms/anzappazurechatgpt)

## Setup Authentication

> **Important**
> [!IMPORTANT]
> The application is protected by an identity provider and follow the steps in [Add an identity provider](/docs/5-add-identity.md) section for adding authentication to your app.

[Next](./docs/1-introduction.md)
Expand Down
4 changes: 2 additions & 2 deletions azure.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json

name: azurechat
name: azure-chat
metadata:
template: azurechat@0.0.1
template: azure-chat@0.0.1
services:
frontend:
project: ./src
Expand Down
16 changes: 8 additions & 8 deletions docs/1-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Please make sure the following prerequisites are in place prior to deploying thi
2. Setup GitHub or Azure AD for Authentication:
The [add an identity provider](./5-add-identity.md) section below shows how to configure authentication providers.

> **Note**
> You can configure the authentication provider to your identity solution using [NextAuth providers](https://next-auth.js.org/providers/)
> [!NOTE]
> You can configure the authentication provider to your identity solution using [NextAuth providers](https://next-auth.js.org/providers/)

## 👋🏻 Introduction

Expand All @@ -20,7 +20,7 @@ _Azure Chat Solution Accelerator powered by Azure Open AI Service_ solution acce

- [NextAuth.js](https://next-auth.js.org/): configurable authentication framework for Next.js 13

- [ai sdk](https://sdk.vercel.ai/docs) Open-source library that simplifies building conversational UI on top Next.js and JavaScript
- [OpenAI sdk](https://github.com/openai/openai-node) NodeJS library that simplifies building conversational UI

- [Tailwind CSS](https://tailwindcss.com/): is a utility-first CSS framework that provides a series of predefined classes that can be used to style each element by mixing and matching

Expand All @@ -38,7 +38,7 @@ The following Azure services can be deployed to expand the feature set of your s

- [Azure Document Intelligence](https://learn.microsoft.com/en-GB/azure/ai-services/document-intelligence/) Microsoft Azure Form Recognizer is an automated data processing system that uses AI and OCR to quickly extract text and structure from documents. We use this service for extracting information from documents.

- [Azure Cognitive Search](https://learn.microsoft.com/en-GB/azure/search/) Azure Cognitive Search is an AI-powered platform as a service (PaaS) that helps developers build rich search experiences for applications. We use this service for indexing and retrieving information.
- [Azure AI Search ](https://learn.microsoft.com/en-GB/azure/search/) Azure AI Search is an AI-powered platform as a service (PaaS) that helps developers build rich search experiences for applications. We use this service for indexing and retrieving information.

- [Azure OpenAI Embeddings](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/embeddings?tabs=console) for embed content extracted from files.

Expand All @@ -48,7 +48,7 @@ The following Azure services can be deployed to expand the feature set of your s

The following high-level diagram depicts the architecture of the solution accelerator:

![Architecture diagram](/images/architecture.png)
![Architecture diagram](/docs/images/architecture.png)

# Azure Deployment Costs

Expand All @@ -58,13 +58,13 @@ However, you can try the [Azure pricing calculator - Sample Estimate](https://az
- Azure App Service: Premium V3 Tier 1 CPU core, 4 GB RAM, 250 GB Storage. Pricing per hour. [Pricing](https://azure.microsoft.com/pricing/details/app-service/linux/)
- Azure Open AI: Standard tier, ChatGPT and Embedding models. Pricing per 1K tokens used, and at least 1K tokens are used per question. [Pricing](https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/)
- Form Recognizer: SO (Standard) tier using pre-built layout. Pricing per document page, sample documents have 261 pages total. [Pricing](https://azure.microsoft.com/pricing/details/form-recognizer/)
- Azure Cognitive Search: Standard tier, 1 replica, free level of semantic search. Pricing per hour.[Pricing](https://azure.microsoft.com/pricing/details/search/)
- Azure AI Search : Standard tier, 1 replica, free level of semantic search. Pricing per hour.[Pricing](https://azure.microsoft.com/pricing/details/search/)
- Azure Cosmos DB: Standard provisioned throughput with ZRS (Zone-redundant storage). Pricing per storage and read operations. [Pricing](https://azure.microsoft.com/en-us/pricing/details/cosmos-db/autoscale-provisioned/)
- Azure Monitor: Pay-as-you-go tier. Costs based on data ingested. [Pricing](https://azure.microsoft.com/pricing/details/monitor/)

To reduce costs, you can switch to free SKUs for Azure App Service, Azure Cognitive Search, and Form Recognizer by changing the parameters file under the `./infra` folder. There are some limits to consider; for example, you can have up to 1 free Cognitive Search resource per subscription, and the free Form Recognizer resource only analyzes the first 2 pages of each document. You can also reduce costs associated with the Form Recognizer by reducing the number of documents you upload.
To reduce costs, you can switch to free SKUs for Azure App Service, Azure AI Search , and Form Recognizer by changing the parameters file under the `./infra` folder. There are some limits to consider; for example, you can have up to 1 free Cognitive Search resource per subscription, and the free Form Recognizer resource only analyzes the first 2 pages of each document. You can also reduce costs associated with the Form Recognizer by reducing the number of documents you upload.

> **Warning**
> [!WARNING]
> To avoid unnecessary costs, remember to destroy your provisioned resources by deleting the resource group.

[Next](/docs/2-provision-azure-resources.md)
92 changes: 6 additions & 86 deletions docs/3-run-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,94 +11,14 @@ Clone this repository locally or fork to your Github account. Run all of the the
## Steps

1. Change directory to the `src` folder
2. Copy the file `.env.example` and rename it to `.env.local`.
3. Populate the environment variables in this file.
<details><summary>Environment Variables (ref src/.env.example)</summary>

```bash
# NOTES:
# - Do not use double-quotes and do not delete any of the variables.
# - Make sure that NEXTAUTH_URL=http://localhost:3000 has no comments in the same line.

# Update your Azure OpenAI details

# AZURE_OPENAI_API_INSTANCE_NAME should be just the name of azure openai resource and not the full url;

# AZURE_OPENAI_API_DEPLOYMENT_NAME should be deployment name from your azure openai studio and not the model name.

# AZURE_OPENAI_API_VERSION should be Supported versions checkout docs https://learn.microsoft.com/en-us/azure/ai-services/openai/reference

OPENAI_API_KEY=
AZURE_OPENAI_API_INSTANCE_NAME=
AZURE_OPENAI_API_DEPLOYMENT_NAME=
AZURE_OPENAI_API_VERSION=2023-03-15-preview
AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME=

# Update your admin email address

ADMIN_EMAIL_ADDRESS="[email protected],[email protected]"

# You must have atleast one of the following auth providers configured

AUTH_GITHUB_ID=
AUTH_GITHUB_SECRET=
AZURE_AD_CLIENT_ID=
AZURE_AD_CLIENT_SECRET=
AZURE_AD_TENANT_ID=

# Update your production URL in NEXTAUTH_URL

NEXTAUTH_SECRET=AZURE-OPENIAI-NEXTAUTH-OWNKEY@1
NEXTAUTH_URL=http://localhost:3000

# Update your Cosmos Environment details here

AZURE_COSMOSDB_URI=https://<cosmoresourcename>.documents.azure.com:443/
AZURE_COSMOSDB_KEY=

# Update your Cosmos DB_NAME and CONTAINER_NAME if you want to overwrite the default values

AZURE_COSMOSDB_DB_NAME=chat
AZURE_COSMOSDB_CONTAINER_NAME=history

# Azure cognitive search is used for chat over your data

AZURE_SEARCH_API_KEY=
AZURE_SEARCH_NAME=
AZURE_SEARCH_INDEX_NAME=
AZURE_SEARCH_API_VERSION="2023-07-01-Preview"

# Azure AI Document Intelligence to extract content from your data

AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT="https://REGION.api.cognitive.microsoft.com/"
AZURE_DOCUMENT_INTELLIGENCE_KEY=

# Azure Speech to Text to convert audio to text

# Enabled must be set to "true" any other value will disable the feature

PUBLIC_SPEECH_ENABLED=true
AZURE_SPEECH_REGION=<region, e.g. australiaeast>
AZURE_SPEECH_KEY=

```
</details>

```

4. Install npm packages by running `npm install`
5. Start the app by running `npm run dev`
6. Access the app on [http://localhost:3000](http://localhost:3000)
2. Rename the file `.env.example` to `.env.local` and populate the environment variables based on the deployed resources in Azure.
3. Install npm packages by running `npm install`
4. Start the app by running `npm run dev`
5. Access the app on [http://localhost:3000](http://localhost:3000)

You should now be prompted to login with your chosen OAuth provider.

> NOTE: If using Basic Auth (DEV ONLY) any username you enter will create a new user id (hash of username@localhost). You can use this to simulate multiple users.

![Chat Login (DEV)](/images/chat-login-dev.png)

Once successfully logged in, you can start creating new conversations.

![Chat Home](/images/chat-home.png)
![Chat history](/images/chat-history.png)
> [!NOTE]
> If using Basic Auth (DEV ONLY) any username you enter will create a new user id (hash of username@localhost). You can use this to simulate multiple users. Once successfully logged in, you can start creating new conversations.

[Next](/docs/4-deploy-to-azure.md)
2 changes: 1 addition & 1 deletion docs/4-deploy-to-azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ Under the same repository secrets add a new variable `AZURE_APP_SERVICE_NAME` to

Once the secrets are configured, the GitHub Actions will be triggered for every code push to the repository. Alternatively, you can manually run the workflow by clicking on the "Run Workflow" button in the Actions tab in GitHub.

![Workflow screenshot](/images/runworkflow.png)
![Workflow screenshot](/docs/images/runworkflow.png)

[Next](/docs/5-add-identity.md)
11 changes: 5 additions & 6 deletions docs/5-add-identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

Once the deployment is complete, you will need to add an identity provider to authenticate your app. You will also need to configure an admin user.

> **Note**
> [!NOTE]
> Only one of the identity providers is required to be configured below.

> **Important**
> [!IMPORTANT]
> We **strongly** recommend that you store client secrets in Azure Key Vault and use Kev Vault references in your App config settings. If you have created your environment using the templates in this repo you will already have a Key Vault that is being used to store a range of other secrets, and you will have Key Vault references in your app config. Details on how to configure App Service settings to use Key Vault are [here](https://learn.microsoft.com/en-us/azure/app-service/app-service-key-vault-references?tabs=azure-cli#source-app-settings-from-key-vault). Note that you will also need to give yourself appropriate permissions to create secrets in the Key Vault.


## GitHub Authentication Provider

We'll create two GitHub apps: one for testing locally and another for production.
Expand Down Expand Up @@ -37,7 +36,7 @@ We'll create two GitHub apps: one for testing locally and another for production
Authorization callback URL: https://YOUR-WEBSITE-NAME.azurewebsites.net/api/auth/callback/github
```

> **Note**
> [!NOTE]
> After completing app setup, ensure that both your local environment variables as well as Azure Web App environment variables are up to date.

```bash
Expand Down Expand Up @@ -74,7 +73,7 @@ We'll create two GitHub apps: one for testing locally and another for production
Redirect URI: https://YOUR-WEBSITE-NAME.azurewebsites.net/api/auth/callback/azure-ad
```

> **Note**
> [!NOTE]
> After completing app setup, ensure your environment variables locally and on Azure App Service are up to date.

```bash
Expand All @@ -87,6 +86,6 @@ AZURE_AD_TENANT_ID=

## Configure an admin user

The reporting pages in the application are only available to an admin user. To configure the admin user create or update the "ADMIN_EMAIL_ADDRESS" config setting locally and on Azure App Service with the email address of the user who will use reports.
The reporting pages in the application are only available to an admin user. To configure the admin user create or update the `ADMIN_EMAIL_ADDRESS` config setting locally and on Azure App Service with the email address of the user who will use reports.

[Next](/docs/6-chat-over-file.md)
Loading
Loading