Skip to content

Commit

Permalink
Merge pull request microsoft#258 from microsoft/package-upgrade
Browse files Browse the repository at this point in the history
Package upgrade
  • Loading branch information
thivy authored Nov 15, 2023
2 parents 5272c88 + 808c840 commit 601086b
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 22 deletions.
7 changes: 5 additions & 2 deletions docs/3-run-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,17 @@ Clone this repository locally or fork to your Github account. Run all of the the

# Azure Speech to Text to convert audio to text

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

NEXT_PUBLIC_SPEECH_ENABLED=Y
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)
Expand Down
2 changes: 1 addition & 1 deletion docs/7-environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Below are the required environment variables, to be added to the Azure Portal or
| `AZURE_SEARCH_INDEX_NAME` | | The index name with [vector search](https://learn.microsoft.com/en-us/azure/search/vector-search-overview) enabled |
| `AZURE_SEARCH_API_VERSION` | `2023-07-01-Preview` | API version which supports vector search `2023-07-01-Preview` |
| `AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT` | `https://NAME.api.cognitive.microsoft.com/` | Endpoint url of the Azure document intelligence. The REGION is specific to your Azure resource location |
| `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. |
| `PUBLIC_SPEECH_ENABLED` | Y | Whether speech should be enabled (microphone button appears). Must be "true" 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 |
| |
7 changes: 4 additions & 3 deletions src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT="https://NAME.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
NEXT_PUBLIC_SPEECH_ENABLED=true
AZURE_SPEECH_REGION=
AZURE_SPEECH_KEY=
AZURE_SPEECH_KEY=

# Enabled must be set to "true" any other value will disable the feature
PUBLIC_SPEECH_ENABLED=true
4 changes: 2 additions & 2 deletions src/app/change-log/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Below are the updates for the Azure Chat Solution accelerator

## 🎙️ 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.
Ability to use Azure Speech in conversations. This feature is not enabled by default. To enable this feature, you must set the environment variable `PUBLIC_SPEECH_ENABLED=true` along with the Azure Speech subscription key and region.

```
NEXT_PUBLIC_SPEECH_ENABLED=true
PUBLIC_SPEECH_ENABLED=true
AZURE_SPEECH_REGION="REGION"
AZURE_SPEECH_KEY="1234...."
```
Expand Down
31 changes: 18 additions & 13 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ThemeProvider } from "@/components/theme-provider";
import { Toaster } from "@/components/ui/toaster";
import { GlobalConfigProvider } from "@/features/global-config/global-client-config-context";
import { Providers } from "@/features/providers";
import { AI_NAME } from "@/features/theme/customise";
import { cn } from "@/lib/utils";
Expand All @@ -23,20 +24,24 @@ export default function RootLayout({
return (
<html lang="en" className="h-full overflow-hidden">
<body className={cn(inter.className, "flex w-full h-full")}>
<Providers>
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
<div
className={cn(
inter.className,
"flex w-full p-2 h-full gap-2 bg-primary"
)}
>
{children}
</div>
<GlobalConfigProvider
config={{ speechEnabled: process.env.PUBLIC_SPEECH_ENABLED }}
>
<Providers>
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
<div
className={cn(
inter.className,
"flex w-full p-2 h-full gap-2 bg-primary"
)}
>
{children}
</div>

<Toaster />
</ThemeProvider>
</Providers>
<Toaster />
</ThemeProvider>
</Providers>
</GlobalConfigProvider>
</body>
</html>
);
Expand Down
3 changes: 2 additions & 1 deletion src/features/chat/chat-ui/chat-input/chat-input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button } from "@/components/ui/button";
import { Textarea } from "@/components/ui/textarea";
import { useChatContext } from "@/features/chat/chat-ui/chat-context";
import { useGlobalConfigContext } from "@/features/global-config/global-client-config-context";
import { Loader, Send } from "lucide-react";
import { FC, FormEvent, useRef } from "react";
import { ChatFileSlider } from "../chat-file/chat-file-slider";
Expand All @@ -13,7 +14,7 @@ const ChatInput: FC<Props> = (props) => {
const { setInput, handleSubmit, isLoading, input, chatBody } =
useChatContext();

const speechEnabled = process.env.NEXT_PUBLIC_SPEECH_ENABLED;
const { speechEnabled } = useGlobalConfigContext();

const buttonRef = useRef<HTMLButtonElement>(null);
const { rows, resetRows, onKeyDown, onKeyUp } = useChatInputDynamicHeight({
Expand Down
43 changes: 43 additions & 0 deletions src/features/global-config/global-client-config-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use client";
import { createContext, useContext } from "react";

interface GlobalConfigProps {
speechEnabled: boolean;
}

const GlobalConfigContext = createContext<GlobalConfigProps | null>(null);

interface IConfig {
speechEnabled?: string;
}

export const GlobalConfigProvider = ({
config,
children,
}: {
config: IConfig;
children: React.ReactNode;
}) => {
const speechEnabled = config.speechEnabled
? config.speechEnabled === "true"
: false;

return (
<GlobalConfigContext.Provider
value={{
speechEnabled,
}}
>
{children}
</GlobalConfigContext.Provider>
);
};

export const useGlobalConfigContext = () => {
const context = useContext(GlobalConfigContext);
if (!context) {
throw new Error("GlobalConfigContext is null");
}

return context;
};
1 change: 1 addition & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const azureEnvVars = [
"ADMIN_EMAIL_ADDRESS",
"AZURE_SPEECH_REGION",
"AZURE_SPEECH_KEY",
"PUBLIC_PUBLIC_SPEECH_ENABLED",
] as const;

type RequiredServerEnvKeys = (typeof azureEnvVars)[number];
Expand Down

0 comments on commit 601086b

Please sign in to comment.