Skip to content

Commit 99cc9b7

Browse files
authored
Merge branch 'main' into feature/add-include-category
2 parents 9285b9b + fa85034 commit 99cc9b7

File tree

7 files changed

+49
-16
lines changed

7 files changed

+49
-16
lines changed

app/backend/prepdocslib/filestrategy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async def parse_file(
1717
category: Optional[str] = None,
1818
image_embeddings: Optional[ImageEmbeddings] = None,
1919
) -> List[Section]:
20-
key = file.file_extension()
20+
key = file.file_extension().lower()
2121
processor = file_processors.get(key)
2222
if processor is None:
2323
logger.info("Skipping '%s', no parser found.", file.filename())

app/frontend/package-lock.json

Lines changed: 4 additions & 3 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@types/react-dom": "^18.3.0",
4343
"@types/react-syntax-highlighter": "^15.5.13",
4444
"@vitejs/plugin-react": "^4.3.2",
45-
"prettier": "^3.0.3",
45+
"prettier": "^3.3.3",
4646
"typescript": "^5.6.3",
4747
"vite": "^5.4.8",
4848
"rollup-plugin-visualizer": "^5.12.0"

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ export const Answer = ({
4343
showSpeechOutputBrowser
4444
}: Props) => {
4545
const followupQuestions = answer.context?.followup_questions;
46-
const messageContent = answer.message.content;
47-
const parsedAnswer = useMemo(() => parseAnswerToHtml(messageContent, isStreaming, onCitationClicked), [answer]);
46+
const parsedAnswer = useMemo(() => parseAnswerToHtml(answer, isStreaming, onCitationClicked), [answer]);
4847
const { t } = useTranslation();
4948
const sanitizedAnswerHtml = DOMPurify.sanitize(parsedAnswer.answerHtml);
5049

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
11
import { renderToStaticMarkup } from "react-dom/server";
2-
import { getCitationFilePath } from "../../api";
2+
import { ChatAppResponse, getCitationFilePath } from "../../api";
33

44
type HtmlParsedAnswer = {
55
answerHtml: string;
66
citations: string[];
77
};
88

9-
export function parseAnswerToHtml(answer: string, isStreaming: boolean, onCitationClicked: (citationFilePath: string) => void): HtmlParsedAnswer {
9+
// Function to validate citation format and check if dataPoint starts with possible citation
10+
function isCitationValid(contextDataPoints: any, citationCandidate: string): boolean {
11+
const regex = /^[^\s]+\.[a-zA-Z0-9]+/;
12+
if (!regex.test(citationCandidate)) {
13+
return false;
14+
}
15+
16+
// Check if contextDataPoints is an object with a text property that is an array
17+
let dataPointsArray: string[];
18+
if (Array.isArray(contextDataPoints)) {
19+
dataPointsArray = contextDataPoints;
20+
} else if (contextDataPoints && Array.isArray(contextDataPoints.text)) {
21+
dataPointsArray = contextDataPoints.text;
22+
} else {
23+
return false;
24+
}
25+
26+
const isValidCitation = dataPointsArray.some(dataPoint => dataPoint.startsWith(citationCandidate));
27+
28+
if (!isValidCitation) {
29+
return false;
30+
}
31+
32+
return true;
33+
}
34+
35+
export function parseAnswerToHtml(answer: ChatAppResponse, isStreaming: boolean, onCitationClicked: (citationFilePath: string) => void): HtmlParsedAnswer {
36+
const contextDataPoints = answer.context.data_points;
1037
const citations: string[] = [];
1138

12-
// trim any whitespace from the end of the answer after removing follow-up questions
13-
let parsedAnswer = answer.trim();
39+
// Trim any whitespace from the end of the answer after removing follow-up questions
40+
let parsedAnswer = answer.message.content.trim();
1441

1542
// Omit a citation that is still being typed during streaming
1643
if (isStreaming) {
@@ -34,6 +61,11 @@ export function parseAnswerToHtml(answer: string, isStreaming: boolean, onCitati
3461
return part;
3562
} else {
3663
let citationIndex: number;
64+
65+
if (!isCitationValid(contextDataPoints, part)) {
66+
return `[${part}]`;
67+
}
68+
3769
if (citations.indexOf(part) !== -1) {
3870
citationIndex = citations.indexOf(part) + 1;
3971
} else {

app/frontend/src/pages/chat/Chat.module.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
flex-direction: column;
1717
align-items: center;
1818
width: 100%;
19+
max-height: calc(100vh - 10rem);
1920
}
2021

2122
.chatEmptyState {
@@ -43,13 +44,13 @@
4344
.chatMessageStream {
4445
flex-grow: 1;
4546
max-height: 64rem;
46-
max-width: 64.25rem;
4747
width: 100%;
4848
overflow-y: auto;
49-
padding-left: 1rem;
50-
padding-right: 1rem;
49+
padding: 0 2rem;
5150
display: flex;
5251
flex-direction: column;
52+
resize: horizontal;
53+
min-width: 50vw;
5354
}
5455

5556
.chatMessageGpt {
@@ -76,7 +77,7 @@
7677
.chatAnalysisPanel {
7778
flex: 1;
7879
overflow-y: auto;
79-
max-height: 89vh;
80+
max-height: 85vh;
8081
margin-left: 1.25rem;
8182
margin-right: 1.25rem;
8283
}

infra/main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ module containerApps 'core/host/container-apps.bicep' = if (deploymentTarget ==
424424
workloadProfile: azureContainerAppsWorkloadProfile
425425
containerAppsEnvironmentName: acaManagedEnvironmentName
426426
containerRegistryName: '${containerRegistryName}${resourceToken}'
427-
logAnalyticsWorkspaceResourceId: monitoring.outputs.logAnalyticsWorkspaceId
427+
logAnalyticsWorkspaceResourceId: useApplicationInsights ? monitoring.outputs.logAnalyticsWorkspaceId : ''
428428
}
429429
}
430430

0 commit comments

Comments
 (0)