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

Citations to Chat with file #246

Merged
merged 18 commits into from
Nov 2, 2023
2 changes: 0 additions & 2 deletions docs/1-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ _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

- [LangChain JS](https://www.langchain.com/): AI orchestration layer to build intelligent apps

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

- [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 Down
132 changes: 72 additions & 60 deletions docs/3-run-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,75 +12,87 @@ Clone this repository locally or fork to your Github account. Run all of the the

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

AZURE_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="you@email.com,you2@email.com"

# 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 "Y" any other value will disable the feature
NEXT_PUBLIC_SPEECH_ENABLED=Y
AZURE_SPEECH_REGION=<region, e.g. australiaeast>
AZURE_SPEECH_KEY=
```
</details>

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="you@email.com,you2@email.com"

# 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 "Y" any other value will disable the feature

NEXT_PUBLIC_SPEECH_ENABLED=Y
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)

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)
Expand Down
4 changes: 2 additions & 2 deletions docs/7-environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Below are the required environment variables, to be added to the Azure Portal or

| App Setting | Value | Note |
| ----------------------------------------------------------------------------------------- | ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `AZURE_OPENAI_API_KEY` | | API keys of your Azure OpenAI resource |
| `OPENAI_API_KEY` | | API keys of your Azure OpenAI resource |
| `AZURE_OPENAI_API_INSTANCE_NAME` | | the name of your Azure OpenAI resource |
| `AZURE_OPENAI_API_DEPLOYMENT_NAME` | | The name of your model deployment |
| `AZURE_OPENAI_API_VERSION` | `2023-03-15-preview` | API version when using gpt chat |
Expand All @@ -27,4 +27,4 @@ Below are the required environment variables, to be added to the Azure Portal or
| `NEXT_PUBLIC_SPEECH_ENABLED` | Y | Whether speech should be enabled (microphone button appears). Must be "Y" to enable, any other value (or blank) will disable. |
| `AZURE_SPEECH_REGION` | australiaeast | Region of your Azure Speech service |
| `AZURE_SPEECH_KEY` | | API Key of Azure Speech service |
| |
| |
8 changes: 3 additions & 5 deletions infra/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
"value": "[format('@Microsoft.KeyVault(VaultName={0};SecretName={1})', variables('keyVaultName'), 'AZURE-COSMOSDB-KEY')]"
},
{
"name": "AZURE_OPENAI_API_KEY",
"name": "OPENAI_API_KEY",
"value": "[format('@Microsoft.KeyVault(VaultName={0};SecretName={1})', variables('keyVaultName'), 'AZURE-OPENAI-API-KEY')]"
},
{
Expand Down Expand Up @@ -549,9 +549,7 @@
"resource": {
"id": "[variables('containerName')]",
"partitionKey": {
"paths": [
"/userId"
],
"paths": ["/userId"],
"kind": "Hash"
},
"defaultTtl": 86400
Expand Down Expand Up @@ -653,4 +651,4 @@
"value": "[tenant().tenantId]"
}
}
}
}
6 changes: 3 additions & 3 deletions infra/resources.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ resource webApp 'Microsoft.Web/sites@2020-06-01' = {
value: '@Microsoft.KeyVault(VaultName=${kv.name};SecretName=${kv::AZURE_COSMOSDB_KEY.name})'
}
{
name: 'AZURE_OPENAI_API_KEY'
value: '@Microsoft.KeyVault(VaultName=${kv.name};SecretName=${kv::AZURE_OPENAI_API_KEY.name})'
name: 'OPENAI_API_KEY'
value: '@Microsoft.KeyVault(VaultName=${kv.name};SecretName=${kv::OPENAI_API_KEY.name})'
}
{
name: 'AZURE_DOCUMENT_INTELLIGENCE_KEY'
Expand Down Expand Up @@ -230,7 +230,7 @@ resource kv 'Microsoft.KeyVault/vaults@2021-06-01-preview' = {
}
}

resource AZURE_OPENAI_API_KEY 'secrets' = {
resource OPENAI_API_KEY 'secrets' = {
name: 'AZURE-OPENAI-API-KEY'
properties: {
contentType: 'text/plain'
Expand Down
2 changes: 1 addition & 1 deletion src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# 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
AZURE_OPENAI_API_KEY=
OPENAI_API_KEY=
AZURE_OPENAI_API_INSTANCE_NAME=
AZURE_OPENAI_API_DEPLOYMENT_NAME=
AZURE_OPENAI_API_VERSION=2023-03-15-preview
Expand Down
2 changes: 1 addition & 1 deletion src/app-global.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const APP_VERSION = "1.1.0";
export const APP_VERSION = "1.2.0";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MainMenu } from "@/features/menu/menu";
import { MainMenu } from "@/features/main-menu/menu";
import { AI_NAME } from "@/features/theme/customise";

export const dynamic = "force-dynamic";
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions src/app/update/page.tsx → src/app/change-log/page.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { Markdown } from "@/components/chat/markdown";
import { Card } from "@/components/ui/card";
import { VersionDisplay } from "@/features/update/version-display";
import { VersionDisplay } from "@/features/change-log/version-display";
import { promises as fs } from "fs";
import { Suspense } from "react";
import ReactMarkdown from "react-markdown";

export const dynamic = "force-dynamic";

export default async function Home() {
// read local file from src/app/update/page.tsx
const file = await fs.readFile(
process.cwd() + "/app/update/update.md",
process.cwd() + "/app/change-log/update.md",
"utf8"
);

return (
<Card className="h-full flex justify-center flex-1">
<Card className="h-full flex justify-center flex-1 overflow-y-scroll">
<div className="flex flex-col gap-8 py-8">
<Suspense fallback={"Getting version"}>
<VersionDisplay />
</Suspense>
<ReactMarkdown className="prose prose-slate dark:prose-invert break-words prose-p:leading-relaxed prose-pre:p-0 max-w-4xl">
{file}
</ReactMarkdown>
<div className="prose prose-slate dark:prose-invert break-words prose-p:leading-relaxed prose-pre:p-0 max-w-4xl ">
<Markdown content={file} />
</div>
</div>
</Card>
);
Expand Down
25 changes: 25 additions & 0 deletions src/app/change-log/update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Azure Chat Updates

Below are the updates for the Azure Chat Solution accelerator

## 📂 Chat with file

- In the chat with file feature, you can now see citations within the responses. Simply click on the citation to access the related context.

- You can now upload files to existing chats, allowing you to chat with multiple files simultaneously.

## 🎙️ Speech

Ability to use Azure Speech in conversations. This feature is not enabled by default. To enable this feature, you must set the environment variable `NEXT_PUBLIC_SPEECH_ENABLED=true` along with the Azure Speech subscription key and region.

```
NEXT_PUBLIC_SPEECH_ENABLED=true
AZURE_SPEECH_REGION="REGION"
AZURE_SPEECH_KEY="1234...."
```

## 🔑 Environment variable change

Please note that the solution has been upgraded to utilise the most recent version of the OpenAI JavaScript SDK, necessitating the use of the `OPENAI_API_KEY` environment variable.

Ensure that you update the variable name in both your '.env' file and the configuration within Azure App Service or Key Vault, changing it from `AZURE_OPENAI_API_KEY` to `OPENAI_API_KEY`.
2 changes: 1 addition & 1 deletion src/app/chat/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChatMenu } from "@/features/chat/chat-menu/chat-menu";
import { ChatMenuContainer } from "@/features/chat/chat-menu/chat-menu-container";
import { MainMenu } from "@/features/menu/menu";
import { MainMenu } from "@/features/main-menu/menu";
import { AI_NAME } from "@/features/theme/customise";

export const dynamic = "force-dynamic";
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function RootLayout({
children: React.ReactNode;
}) {
return (
<html lang="en" className="h-full overflow-hidden">
<html lang="en" className="h-full overflow-hidden light">
<body className={cn(inter.className, "flex w-full h-full")}>
<Providers>
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
Expand Down
2 changes: 1 addition & 1 deletion src/app/reporting/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MainMenu } from "@/features/menu/menu";
import { MainMenu } from "@/features/main-menu/menu";
import { AI_NAME } from "@/features/theme/customise";

export const metadata = {
Expand Down
6 changes: 2 additions & 4 deletions src/app/unauthorized/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MainMenu } from "@/features/menu/menu";
import { MainMenu } from "@/features/main-menu/menu";
import { AI_NAME } from "@/features/theme/customise";

export const metadata = {
Expand All @@ -14,9 +14,7 @@ export default async function RootLayout({
return (
<>
<MainMenu />
<div className="flex-1">
{children}
</div>
<div className="flex-1">{children}</div>
</>
);
}
13 changes: 0 additions & 13 deletions src/app/update/update.md

This file was deleted.

Loading