Skip to content

Commit 0119649

Browse files
authored
Merge pull request #44 from johnoliver/merge-ui
Sync UI with python
2 parents 0e728a8 + 17678c2 commit 0119649

File tree

24 files changed

+1030
-961
lines changed

24 files changed

+1030
-961
lines changed

app/frontend/.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore JSON
2+
**/*.json

app/frontend/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>GPT + Enterprise data | Java Sample</title>
8-
</head>
9-
<body>
10-
<div id="root"></div>
11-
<script type="module" src="/src/index.tsx"></script>
12-
</body>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/index.tsx"></script>
12+
</body>
1313
</html>

app/frontend/package-lock.json

Lines changed: 843 additions & 794 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/frontend/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,26 @@
99
"scripts": {
1010
"dev": "vite --port=8080",
1111
"build": "tsc && vite build",
12-
"watch": "tsc && vite build --watch"
12+
"preview": "vite preview"
1313
},
1414
"dependencies": {
1515
"@azure/msal-react": "^2.0.4",
1616
"@azure/msal-browser": "^3.1.0",
17-
"@fluentui/react": "^8.112.2",
18-
"@fluentui/react-components": "^9.34.2",
19-
"@fluentui/react-icons": "^2.0.219",
17+
"@fluentui/react": "^8.112.3",
18+
"@fluentui/react-components": "^9.35.0",
19+
"@fluentui/react-icons": "^2.0.220",
2020
"@react-spring/web": "^9.7.3",
2121
"dompurify": "^3.0.6",
2222
"react": "^18.2.0",
2323
"react-dom": "^18.2.0",
2424
"react-router-dom": "^6.16.0",
25-
"ndjson-readablestream": "^1.0.7"
25+
"ndjson-readablestream": "^1.0.7",
26+
"scheduler": "^0.20.2"
2627
},
2728
"devDependencies": {
2829
"@types/dompurify": "^3.0.3",
29-
"@types/react": "^18.2.27",
30-
"@types/react-dom": "^18.2.12",
30+
"@types/react": "^18.2.28",
31+
"@types/react-dom": "^18.2.13",
3132
"@vitejs/plugin-react": "^4.1.0",
3233
"prettier": "^3.0.3",
3334
"typescript": "^5.2.2",

app/frontend/src/api/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useLogin } from "../authConfig";
44
const BACKEND_URI = import.meta.env.VITE_BACKEND_URI ? import.meta.env.VITE_BACKEND_URI : "";
55

66
function getHeaders(idToken: string | undefined, stream:boolean): Record<string, string> {
7-
var headers : Record<string, string> = {
7+
var headers: Record<string, string> = {
88
"Content-Type": "application/json"
99
};
1010
// If using login, add the id token of the logged in account as the authorization

app/frontend/src/api/models.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ export type ChatAppRequestOverrides = {
3434
export type ResponseMessage = {
3535
content: string;
3636
role: string;
37-
}
37+
};
3838

3939
export type ResponseContext = {
4040
thoughts: string | null;
4141
data_points: string[];
42-
}
42+
};
4343

4444
export type ResponseChoice = {
4545
index: number;
4646
message: ResponseMessage;
4747
context: ResponseContext;
48+
session_state: any;
4849
};
4950

5051
export type ChatAppResponseOrError = {
@@ -58,11 +59,12 @@ export type ChatAppResponse = {
5859

5960
export type ChatAppRequestContext = {
6061
overrides?: ChatAppRequestOverrides;
61-
}
62+
};
6263

6364
export type ChatAppRequest = {
6465
messages: ResponseMessage[];
6566
approach: Approaches;
6667
context?: ChatAppRequestContext;
6768
stream?: boolean;
69+
session_state: any;
6870
};

app/frontend/src/authConfig.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Refactored from https://github.com/Azure-Samples/ms-identity-javascript-react-tutorial/blob/main/1-Authentication/1-sign-in/SPA/src/authConfig.js
2+
23
import { AuthenticationResult, IPublicClientApplication } from "@azure/msal-browser";
34

45
const BACKEND_URI = import.meta.env.VITE_BACKEND_URI ? import.meta.env.VITE_BACKEND_URI : "";
@@ -13,29 +14,29 @@ interface AuthSetup {
1314
*/
1415
msalConfig: {
1516
auth: {
16-
clientId: string, // Client app id used for login
17-
authority: string, // Directory to use for login https://learn.microsoft.com/azure/active-directory/develop/msal-client-application-configuration#authority
18-
redirectUri: string, // Points to window.location.origin. You must register this URI on Azure Portal/App Registration.
19-
postLogoutRedirectUri: string, // Indicates the page to navigate after logout.
20-
navigateToLoginRequestUrl: boolean // If "true", will navigate back to the original request location before processing the auth code response.
21-
},
17+
clientId: string; // Client app id used for login
18+
authority: string; // Directory to use for login https://learn.microsoft.com/azure/active-directory/develop/msal-client-application-configuration#authority
19+
redirectUri: string; // Points to window.location.origin. You must register this URI on Azure Portal/App Registration.
20+
postLogoutRedirectUri: string; // Indicates the page to navigate after logout.
21+
navigateToLoginRequestUrl: boolean; // If "true", will navigate back to the original request location before processing the auth code response.
22+
};
2223
cache: {
23-
cacheLocation: string, // Configures cache location. "sessionStorage" is more secure, but "localStorage" gives you SSO between tabs.
24-
storeAuthStateInCookie: boolean // Set this to "true" if you are having issues on IE11 or Edge
25-
}
26-
},
24+
cacheLocation: string; // Configures cache location. "sessionStorage" is more secure, but "localStorage" gives you SSO between tabs.
25+
storeAuthStateInCookie: boolean; // Set this to "true" if you are having issues on IE11 or Edge
26+
};
27+
};
2728
loginRequest: {
2829
/**
2930
* Scopes you add here will be prompted for user consent during sign-in.
3031
* By default, MSAL.js will add OIDC scopes (openid, profile, email) to any login request.
3132
* For more information about OIDC scopes, visit:
3233
* https://docs.microsoft.com/azure/active-directory/develop/v2-permissions-and-consent#openid-connect-scopes
3334
*/
34-
scopes: Array<string>
35-
},
35+
scopes: Array<string>;
36+
};
3637
tokenRequest: {
37-
scopes: Array<string>
38-
}
38+
scopes: Array<string>;
39+
};
3940
}
4041

4142
// Fetch the auth setup JSON data from the API if not already cached
@@ -68,15 +69,21 @@ export const loginRequest = authSetup.loginRequest;
6869

6970
const tokenRequest = authSetup.tokenRequest;
7071

72+
// Build an absolute redirect URI using the current window's location and the relative redirect URI from auth setup
73+
export const getRedirectUri = () => {
74+
return window.location.origin + authSetup.msalConfig.auth.redirectUri;
75+
};
76+
7177
// Get an access token for use with the API server.
7278
// ID token received when logging in may not be used for this purpose because it has the incorrect audience
7379
export const getToken = (client: IPublicClientApplication): Promise<AuthenticationResult | undefined> => {
74-
return client.acquireTokenSilent({
75-
...tokenRequest,
76-
redirectUri: authSetup.msalConfig.auth.redirectUri
77-
})
78-
.catch((error) => {
79-
console.log(error);
80-
return undefined;
81-
})
82-
}
80+
return client
81+
.acquireTokenSilent({
82+
...tokenRequest,
83+
redirectUri: getRedirectUri()
84+
})
85+
.catch(error => {
86+
console.log(error);
87+
return undefined;
88+
});
89+
};

app/frontend/src/components/Answer/Answer.module.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
padding: 20px;
33
background: rgb(249, 249, 249);
44
border-radius: 8px;
5-
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.14), 0px 0px 2px rgba(0, 0, 0, 0.12);
5+
box-shadow:
6+
0px 2px 4px rgba(0, 0, 0, 0.14),
7+
0px 0px 2px rgba(0, 0, 0, 0.12);
68
outline: transparent solid 1px;
79
}
810

app/frontend/src/components/Answer/Answer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const Answer = ({
3030
showFollowupQuestions
3131
}: Props) => {
3232
const messageContent = answer.choices[0].message.content;
33-
const parsedAnswer = useMemo(() => parseAnswerToHtml(messageContent, isStreaming, onCitationClicked ), [answer]);
33+
const parsedAnswer = useMemo(() => parseAnswerToHtml(messageContent, isStreaming, onCitationClicked), [answer]);
3434

3535
const sanitizedAnswerHtml = DOMPurify.sanitize(parsedAnswer.answerHtml);
3636

app/frontend/src/components/Answer/AnswerParser.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ export function parseAnswerToHtml(answer: string, isStreaming: boolean, onCitati
2121
parsedAnswer = parsedAnswer.trim();
2222

2323
// Omit a citation that is still being typed during streaming
24-
if (isStreaming){
24+
if (isStreaming) {
2525
let lastIndex = parsedAnswer.length;
2626
for (let i = parsedAnswer.length - 1; i >= 0; i--) {
27-
if (parsedAnswer[i] === ']') {
27+
if (parsedAnswer[i] === "]") {
2828
break;
29-
} else if (parsedAnswer[i] === '[') {
29+
} else if (parsedAnswer[i] === "[") {
3030
lastIndex = i;
3131
break;
3232
}
3333
}
3434
const truncatedAnswer = parsedAnswer.substring(0, lastIndex);
3535
parsedAnswer = truncatedAnswer;
36-
}
36+
}
3737

3838
const parts = parsedAnswer.split(/\[([^\]]+)\]/g);
3939

0 commit comments

Comments
 (0)