Skip to content

Commit 33bc505

Browse files
authored
Get PDFs to jump to their pages again (#1283)
* Clarify that gpt-4-v cant be used with integrated vectorization * Fix page jumping, React error, Python logging error * Another missing key
1 parent fb95e53 commit 33bc505

File tree

5 files changed

+22
-23
lines changed

5 files changed

+22
-23
lines changed

app/backend/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ async def content_file(path: str):
9494
This is also slow and memory hungry.
9595
"""
9696
# Remove page number from path, filename-1.txt -> filename.txt
97+
# This shouldn't typically be necessary as browsers don't send hash fragments to servers
9798
if path.find("#page=") > 0:
9899
path_parts = path.rsplit("#page=", 1)
99100
path = path_parts[0]
100-
logging.info("Opening file %s at page %s", path)
101+
logging.info("Opening file %s", path)
101102
blob_container_client = current_app.config[CONFIG_BLOB_CONTAINER_CLIENT]
102103
try:
103104
blob = await blob_container_client.get_blob_client(path).download_blob()

app/backend/approaches/chatapproach.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ChatApproach(Approach, ABC):
3737
Make sure the last question ends with ">>".
3838
"""
3939

40-
query_prompt_template = """Below is a history of the conversation so far, and a new question asked by the user that needs to be answered by searching in a knowledge.
40+
query_prompt_template = """Below is a history of the conversation so far, and a new question asked by the user that needs to be answered by searching in a knowledge base.
4141
You have access to Azure AI Search index with 100's of documents.
4242
Generate a search query based on the conversation and the new question.
4343
Do not include cited source filenames and document names e.g info.txt or doc.pdf in the search query terms.

app/frontend/src/components/AnalysisPanel/AnalysisPanel.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,19 @@ export const AnalysisPanel = ({ answer, activeTab, activeCitation, citationHeigh
3434
const fetchCitation = async () => {
3535
const token = client ? await getToken(client) : undefined;
3636
if (activeCitation) {
37+
// Get hash from the URL as it may contain #page=N
38+
// which helps browser PDF renderer jump to correct page N
39+
const originalHash = activeCitation.indexOf("#") ? activeCitation.split("#")[1] : "";
3740
const response = await fetch(activeCitation, {
3841
method: "GET",
3942
headers: getHeaders(token)
4043
});
4144
const citationContent = await response.blob();
42-
const citationObjectUrl = URL.createObjectURL(citationContent);
45+
let citationObjectUrl = URL.createObjectURL(citationContent);
46+
// Add hash back to the new blob URL
47+
if (originalHash) {
48+
citationObjectUrl += "#" + originalHash;
49+
}
4350
setCitation(citationObjectUrl);
4451
}
4552
};

app/frontend/src/components/AnalysisPanel/ThoughtProcess.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ interface Props {
1212
export const ThoughtProcess = ({ thoughts }: Props) => {
1313
return (
1414
<ul className={styles.tList}>
15-
{thoughts.map(t => {
15+
{thoughts.map((t, ind) => {
1616
return (
17-
<li className={styles.tListItem}>
17+
<li className={styles.tListItem} key={ind}>
1818
<div className={styles.tStep}>{t.title}</div>
1919
{Array.isArray(t.description) ? (
2020
<SyntaxHighlighter language="json" wrapLongLines className={styles.tCodeBlock}>

app/frontend/src/components/SupportingContent/SupportingContent.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,23 @@ interface Props {
66
supportingContent: string[] | { text: string[]; images?: { url: string }[] };
77
}
88

9-
interface SupportingItemProps {
10-
title: string;
11-
content: string;
12-
}
13-
149
export const SupportingContent = ({ supportingContent }: Props) => {
1510
const textItems = Array.isArray(supportingContent) ? supportingContent : supportingContent.text;
1611
const imageItems = !Array.isArray(supportingContent) ? supportingContent?.images : [];
1712
return (
1813
<ul className={styles.supportingContentNavList}>
19-
{textItems.map(c => {
14+
{textItems.map((c, ind) => {
2015
const parsed = parseSupportingContentItem(c);
21-
return <TextSupportingContent {...parsed} />;
16+
return (
17+
<li className={styles.supportingContentItem} key={ind}>
18+
<h4 className={styles.supportingContentItemHeader}>{parsed.title}</h4>
19+
<p className={styles.supportingContentItemText} dangerouslySetInnerHTML={{ __html: parsed.content }} />
20+
</li>
21+
);
2222
})}
23-
{imageItems?.map(i => {
24-
return <img className={styles.supportingContentItemImage} src={i.url} />;
23+
{imageItems?.map((img, ind) => {
24+
return <img className={styles.supportingContentItemImage} src={img.url} key={ind} />;
2525
})}
2626
</ul>
2727
);
2828
};
29-
30-
export const TextSupportingContent = ({ title, content }: SupportingItemProps) => {
31-
return (
32-
<li className={styles.supportingContentItem}>
33-
<h4 className={styles.supportingContentItemHeader}>{title}</h4>
34-
<p className={styles.supportingContentItemText} dangerouslySetInnerHTML={{ __html: content }} />
35-
</li>
36-
);
37-
};

0 commit comments

Comments
 (0)