Skip to content

Commit

Permalink
Merge pull request #170 from microsoft/geearl/5903-model-to-ui
Browse files Browse the repository at this point in the history
Geearl/5903 model to UI
  • Loading branch information
georearl authored Aug 24, 2023
2 parents 0166dec + e53cfaf commit c7f8b27
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ARG USER_GID=$USER_UID

# Set up non-root user
COPY ./scripts/non-root-user.sh /tmp/
RUN bash /tmp/non-root-user.sh "${USERNAME}" "${USER_UID}" "${USER_GID}"
RUN bash "/tmp/non-root-user.sh" "${USERNAME}" "${USER_UID}" "${USER_GID}"

# Set env for tracking that we're running in a devcontainer
ENV DEVCONTAINER=true
Expand Down
5 changes: 2 additions & 3 deletions .devcontainer/scripts/non-root-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1
fi


# If in automatic mode, determine if a user already exists, if not use vscode
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
USERNAME=""
Expand All @@ -39,11 +38,11 @@ fi
# Create or update a non-root user to match UID/GID.
if id -u ${USERNAME} > /dev/null 2>&1; then
# User exists, update if needed
if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -G $USERNAME)" ]; then
if [ "${USER_GID}" != "automatic" ] && [ "${USER_GID}" != "999" ] && [ "$USER_GID" != "$(id -G $USERNAME)" ]; then
groupmod --gid $USER_GID $USERNAME
usermod --gid $USER_GID $USERNAME
fi
if [ "${USER_UID}" != "automatic" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then
if [ "${USER_UID}" != "automatic" ] && [ "${USER_GID}" != "999" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then
usermod --uid $USER_UID $USERNAME
fi
else
Expand Down
7 changes: 7 additions & 0 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,10 @@ def get_all_upload_status():
logging.exception("Exception in /getalluploadstatus")
return jsonify({"error": str(e)}), 500
return jsonify(results)


# Return AZURE_OPENAI_CHATGPT_DEPLOYMENT
@app.route("/getInfoData")
def get_info_data():
response = jsonify({"AZURE_OPENAI_CHATGPT_DEPLOYMENT": f"{AZURE_OPENAI_CHATGPT_DEPLOYMENT}"})
return response
18 changes: 17 additions & 1 deletion app/frontend/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { AskRequest, AskResponse, ChatRequest, BlobClientUrlResponse, AllFilesUploadStatus, GetUploadStatusRequest } from "./models";
import { AskRequest, AskResponse, ChatRequest, BlobClientUrlResponse, AllFilesUploadStatus, GetUploadStatusRequest, GetInfoResponse } from "./models";

export async function askApi(options: AskRequest): Promise<AskResponse> {
const response = await fetch("/ask", {
Expand Down Expand Up @@ -110,4 +110,20 @@ export async function getAllUploadStatus(options: GetUploadStatusRequest): Promi
}
const results: AllFilesUploadStatus = {statuses: parsedResponse};
return results;
}

export async function getInfoData(): Promise<GetInfoResponse> {
const response = await fetch("/getInfoData", {
method: "GET",
headers: {
"Content-Type": "application/json"
}
});
const parsedResponse: GetInfoResponse = await response.json();
if (response.status > 299 || !response.ok) {
console.log(response);
throw Error(parsedResponse.error || "Unknown error");
}
console.log(parsedResponse);
return parsedResponse;
}
7 changes: 7 additions & 0 deletions app/frontend/src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type GetUploadStatusRequest = {
state: FileState
}


// These keys need to match case with the defined Enum in the
// shared code (functions/shared_code/status_log.py)
export const enum FileState {
Expand All @@ -86,3 +87,9 @@ export const enum FileState {
Complete = "COMPLETE",
Error = "ERROR"
}


export type GetInfoResponse = {
AZURE_OPENAI_CHATGPT_DEPLOYMENT: string;
error?: string;
};
9 changes: 9 additions & 0 deletions app/frontend/src/components/InfoButton/InfoButton.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Copyright (c) Microsoft Corporation.
Licensed under the MIT license. */

.container {
display: flex;
align-items: center;
gap: 6px;
cursor: pointer;
}
20 changes: 20 additions & 0 deletions app/frontend/src/components/InfoButton/InfoButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Text } from "@fluentui/react";
import { Info24Regular } from "@fluentui/react-icons";
import styles from "./InfoButton.module.css";

interface Props {
className?: string;
onClick: () => void;
}

export const InfoButton = ({ className, onClick }: Props) => {
return (
<div className={`${styles.container} ${className ?? ""}`} onClick={onClick}>
<Info24Regular />
<Text>{"Info"}</Text>
</div>
);
};
4 changes: 4 additions & 0 deletions app/frontend/src/components/InfoButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export * from "./InfoButton";
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Props {
placeholder?: string;
clearOnSend?: boolean;
onAdjustClick?: () => void;
onInfoClick?: () => void;
showClearChat?: boolean;
onClearClick?: () => void;
}
Expand Down
20 changes: 19 additions & 1 deletion app/frontend/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ import { ExampleList } from "../../components/Example";
import { UserChatMessage } from "../../components/UserChatMessage";
import { AnalysisPanel, AnalysisPanelTabs } from "../../components/AnalysisPanel";
import { SettingsButton } from "../../components/SettingsButton";
import { InfoButton } from "../../components/InfoButton";
import { ClearChatButton } from "../../components/ClearChatButton";
import { ResponseLengthButtonGroup } from "../../components/ResponseLengthButtonGroup";
import { ResponseTempButtonGroup } from "../../components/ResponseTempButtonGroup";
import { InfoContent } from "./InfoContent";

const Chat = () => {
const [isConfigPanelOpen, setIsConfigPanelOpen] = useState(false);
const [isInfoPanelOpen, setIsInfoPanelOpen] = useState(false);
const [promptTemplate, setPromptTemplate] = useState<string>("");
const [retrieveCount, setRetrieveCount] = useState<number>(5);
const [useSemanticRanker, setUseSemanticRanker] = useState<boolean>(true);
Expand Down Expand Up @@ -226,6 +229,7 @@ const Chat = () => {
<div className={styles.commandsContainer}>
<ClearChatButton className={styles.commandButton} onClick={clearChat} disabled={!lastQuestionRef.current || isLoading} />
<SettingsButton className={styles.commandButton} onClick={() => setIsConfigPanelOpen(!isConfigPanelOpen)} />
<InfoButton className={styles.commandButton} onClick={() => setIsInfoPanelOpen(!isInfoPanelOpen)} />
</div>
<div className={styles.chatRoot}>
<div className={styles.chatContainer}>
Expand Down Expand Up @@ -268,7 +272,7 @@ const Chat = () => {
onSupportingContentClicked={() => onToggleTab(AnalysisPanelTabs.SupportingContentTab, index)}
onFollowupQuestionClicked={q => makeApiRequest(q)}
showFollowupQuestions={useSuggestFollowupQuestions && answers.length - 1 === index}
onAdjustClick={() => setIsConfigPanelOpen(!isConfigPanelOpen)}
onAdjustClick={() => setIsInfoPanelOpen(!isInfoPanelOpen)}
/>
</div>
</div>
Expand Down Expand Up @@ -300,6 +304,7 @@ const Chat = () => {
disabled={isLoading}
onSend={question => makeApiRequest(question)}
onAdjustClick={() => setIsConfigPanelOpen(!isConfigPanelOpen)}
onInfoClick={() => setIsInfoPanelOpen(!isInfoPanelOpen)}
showClearChat={true}
onClearClick={clearChat}
/>
Expand Down Expand Up @@ -347,6 +352,19 @@ const Chat = () => {
<ResponseLengthButtonGroup className={styles.chatSettingsSeparator} onClick={onResponseLengthChange} defaultValue={responseLength}/>
<ResponseTempButtonGroup className={styles.chatSettingsSeparator} onClick={onResponseTempChange} defaultValue={responseTemp}/>
</Panel>

<Panel
headerText="Information"
isOpen={isInfoPanelOpen}
isBlocking={false}
onDismiss={() => setIsInfoPanelOpen(false)}
closeButtonAriaLabel="Close"
onRenderFooterContent={() => <DefaultButton onClick={() => setIsInfoPanelOpen(false)}>Close</DefaultButton>}
isFooterAtBottom={true} >
<div className={styles.resultspanel}>
<InfoContent/>
</div>
</Panel>
</div>
</div>
);
Expand Down
38 changes: 38 additions & 0 deletions app/frontend/src/pages/chat/InfoContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import React, { useEffect, useState } from "react";
import { Text } from "@fluentui/react";
import { getInfoData, GetInfoResponse } from "../../api";

interface Props {
className?: string;
}

export const InfoContent = ({ className }: Props) => {
const [infoData, setInfoData] = useState<GetInfoResponse | null>(null);

async function fetchInfoData() {
console.log("InfoContent 1");
try {
const fetchedInfoData = await getInfoData();
setInfoData(fetchedInfoData);
} catch (error) {
// Handle the error here
console.log(error);
}
}

useEffect(() => {
fetchInfoData();
}, []);

return (
<div>
<Text>Azure OpenAI model used: {infoData?.AZURE_OPENAI_CHATGPT_DEPLOYMENT}</Text>
</div>
);
};
6 changes: 3 additions & 3 deletions infra/core/host/appservice.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ resource diagnosticLogs 'Microsoft.Insights/diagnosticSettings@2021-05-01-previe
category: 'AppServiceAppLogs'
enabled: true
retentionPolicy: {
days: 30
days: 0
enabled: true
}
}
{
category: 'AppServicePlatformLogs'
enabled: true
retentionPolicy: {
days: 30
days: 0
enabled: true
}
}
Expand All @@ -156,7 +156,7 @@ resource diagnosticLogs 'Microsoft.Insights/diagnosticSettings@2021-05-01-previe
category: 'AllMetrics'
enabled: true
retentionPolicy: {
days: 30
days: 0
enabled: true
}
}
Expand Down
4 changes: 0 additions & 4 deletions infra/core/storage/storage-account.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ resource storage 'Microsoft.Storage/storageAccounts@2022-05-01' = {
}


// resource queueServices 'queueServices' = [for queueName in queueNames: {
// name: queueName.name
// }]

resource queueServices 'queueServices' = {
name: 'default'
resource queue 'queues' = [for queueName in queueNames: {
Expand Down
2 changes: 1 addition & 1 deletion pipelines/templates/deploy-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ steps:
docker image tag info-asst-devcontainer:latest $(CONTAINER_REGISTRY_ADDRESS)/info-asst-devcontainer:latest
docker image push $(CONTAINER_REGISTRY_ADDRESS)/info-asst-devcontainer:latest
displayName: Push latest dev container image to container registry
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.SourceBranch'], 'refs/heads/0.2-Beta')))
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.SourceBranch'], 'refs/heads/vNext-Dev')))

- template: make-command.yml
parameters:
Expand Down

0 comments on commit c7f8b27

Please sign in to comment.