Skip to content

Commit 8385b56

Browse files
committed
prettier
1 parent 81a93a6 commit 8385b56

File tree

11 files changed

+47
-36
lines changed

11 files changed

+47
-36
lines changed

src/lib/buildPrompt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export async function buildPrompt({
5050
`,
5151
},
5252
];
53-
}else if (pdfSearch && pdfSearch.context) {
53+
} else if (pdfSearch && pdfSearch.context) {
5454
const lastMsg = messages.slice(-1)[0];
5555
const messagesWithoutLastUsrMsg = messages.slice(0, -1);
5656
const previousUserMessages = messages.filter((el) => el.from === "user").slice(0, -1);
@@ -61,7 +61,7 @@ export async function buildPrompt({
6161
.map(({ content }) => `- ${content}`)
6262
.join("\n")}`
6363
: "";
64-
64+
6565
messages = [
6666
...messagesWithoutLastUsrMsg,
6767
{

src/lib/components/UploadBtn.svelte

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<script lang="ts">
22
import { PdfUploadStatus } from "$lib/types/PdfChat";
3-
import {createEventDispatcher, onDestroy} from "svelte";
3+
import { createEventDispatcher, onDestroy } from "svelte";
44
import CarbonUpload from "~icons/carbon/upload";
55
66
export let classNames = "";
77
export let multimodal = false;
88
export let files: File[];
99
export let uploadPdfStatus: PdfUploadStatus;
10-
10+
1111
const accept = multimodal ? "image/*,.pdf" : ".pdf";
1212
const label = multimodal ? "Upload image or PDF" : "Upload PDF";
1313
let fileInput: HTMLInputElement;
1414
let interval: ReturnType<typeof setInterval>;
1515
1616
$: uploading = uploadPdfStatus === PdfUploadStatus.Uploading;
17-
$:{
18-
if(uploadPdfStatus === PdfUploadStatus.Uploaded){
17+
$: {
18+
if (uploadPdfStatus === PdfUploadStatus.Uploaded) {
1919
interval = setInterval(() => {
2020
uploadPdfStatus = PdfUploadStatus.Ready;
2121
}, 1500);
@@ -27,25 +27,25 @@
2727
}>();
2828
2929
function onChange() {
30-
if(!fileInput.files){
30+
if (!fileInput.files) {
3131
return;
3232
}
33-
33+
3434
const file = fileInput.files?.[0];
3535
if (file?.type === "application/pdf") {
3636
// pdf upload
3737
dispatch("uploadpdf", file);
38-
}else{
38+
} else {
3939
// image files for multimodal models
4040
files = Array.from(fileInput.files);
4141
}
4242
}
4343
4444
onDestroy(() => {
45-
if(interval){
45+
if (interval) {
4646
clearInterval(interval);
4747
}
48-
})
48+
});
4949
</script>
5050

5151
<button

src/lib/components/chat/ChatMessage.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@
109109
110110
let searchUpdates: WebSearchUpdate[] = [];
111111
112-
$: searchUpdates = ((RAGMessages.filter(({type}) => type === "webSearch").length > 0
113-
? RAGMessages.filter(({type}) => type === "webSearch")
112+
$: searchUpdates = ((RAGMessages.filter(({ type }) => type === "webSearch").length > 0
113+
? RAGMessages.filter(({ type }) => type === "webSearch")
114114
: message.updates?.filter(({ type }) => type === "webSearch")) ?? []) as WebSearchUpdate[];
115-
115+
116116
let pdfUpdates: PdfSearchUpdate[] = [];
117117
118-
$: pdfUpdates = ((RAGMessages.filter(({type}) => type === "pdfSearch").length > 0
119-
? RAGMessages.filter(({type}) => type === "pdfSearch")
118+
$: pdfUpdates = ((RAGMessages.filter(({ type }) => type === "pdfSearch").length > 0
119+
? RAGMessages.filter(({ type }) => type === "pdfSearch")
120120
: message.updates?.filter(({ type }) => type === "pdfSearch")) ?? []) as PdfSearchUpdate[];
121121
122122
$: downloadLink =

src/lib/components/chat/ChatWindow.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@
176176
})}
177177
/>
178178
{/if}
179-
<UploadBtn bind:files on:uploadpdf classNames="ml-auto" multimodal={currentModel.multimodal} {uploadPdfStatus} />
179+
<UploadBtn
180+
bind:files
181+
on:uploadpdf
182+
classNames="ml-auto"
183+
multimodal={currentModel.multimodal}
184+
{uploadPdfStatus}
185+
/>
180186
</div>
181187
<form
182188
on:dragover={onDragOver}

src/lib/server/embeddings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ export function findSimilarSentences(
4848

4949
// Return the indexes of the closest topK sentences
5050
return distancesFromQuery.slice(0, topK).map((item) => item.index);
51-
}
51+
}

src/lib/server/files/downloadFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function downloadPdfEmbeddings(
4040
) {
4141
const fileId = collections.bucket.find({ filename: `${convId.toString()}-pdf` });
4242
let textChunks: string[] = [];
43-
let dims: number[] = []
43+
let dims: number[] = [];
4444

4545
const content = await fileId.next().then(async (file) => {
4646
if (!file) {

src/lib/server/files/uploadFile.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export async function uploadImgFile(file: Blob, conv: Conversation): Promise<str
2121
});
2222
}
2323

24-
export async function uploadPdfEmbeddings(embeddings: Tensor, textChunks: string[], conv: Conversation): Promise<void> {
24+
export async function uploadPdfEmbeddings(
25+
embeddings: Tensor,
26+
textChunks: string[],
27+
conv: Conversation
28+
): Promise<void> {
2529
const filename = `${conv._id}-pdf`;
2630

2731
// Step 1: Check if the file exists

src/lib/server/pdfSearch.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { PdfSearch } from "$lib/types/PdfChat";
2-
import {
3-
createEmbeddings,
4-
findSimilarSentences,
5-
} from "$lib/server/embeddings";
2+
import { createEmbeddings, findSimilarSentences } from "$lib/server/embeddings";
63
import type { Conversation } from "$lib/types/Conversation";
74
import type { MessageUpdate } from "$lib/types/MessageUpdate";
85
import { downloadPdfEmbeddings } from "./files/downloadFile";
@@ -29,11 +26,15 @@ export async function runPdfSearch(
2926
const { content, textChunks, dims } = await downloadPdfEmbeddings(conv._id);
3027
// reconstruct pdfEmbeddings
3128
const buffer = Buffer.from(content);
32-
const data = new Float32Array(buffer.buffer, buffer.byteOffset, buffer.length / Float32Array.BYTES_PER_ELEMENT);
33-
const pdfEmbeddings = new Tensor('float32', data, dims);
29+
const data = new Float32Array(
30+
buffer.buffer,
31+
buffer.byteOffset,
32+
buffer.length / Float32Array.BYTES_PER_ELEMENT
33+
);
34+
const pdfEmbeddings = new Tensor("float32", data, dims);
3435
const promptEmbeddings = await createEmbeddings([prompt]);
3536

36-
const indices = findSimilarSentences(pdfEmbeddings, promptEmbeddings, {topK: 5});
37+
const indices = findSimilarSentences(pdfEmbeddings, promptEmbeddings, { topK: 5 });
3738
pdfSearch.context = indices.map((idx) => textChunks[idx]).join(" ");
3839

3940
appendUpdate("Done", [], "done");

src/routes/conversation/[id]/+page.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
uploadPdfStatus = PdfUploadStatus.Uploading;
279279
280280
const formData = new FormData();
281-
formData.append('pdf', file);
281+
formData.append("pdf", file);
282282
283283
const res = await fetch(`${base}/conversation/${$page.params.id}/upload-pdf`, {
284284
method: "POST",
@@ -297,10 +297,10 @@
297297
// only used in case of creating new conversations (from the parent POST endpoint)
298298
if ($pendingMessage) {
299299
files = $pendingMessage.files;
300-
if($pendingMessage.content){
300+
if ($pendingMessage.content) {
301301
await writeMessage($pendingMessage.content);
302302
}
303-
if($pendingMessage.pdfFile){
303+
if ($pendingMessage.pdfFile) {
304304
await uploadPdf($pendingMessage.pdfFile);
305305
}
306306
$pendingMessage = undefined;
@@ -353,7 +353,7 @@
353353
{messages}
354354
shared={data.shared}
355355
preprompt={data.preprompt}
356-
bind:RAGMessages={RAGMessages}
356+
bind:RAGMessages
357357
bind:files
358358
on:message={onMessage}
359359
on:retry={onRetry}

src/routes/conversation/[id]/+server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export async function POST({ request, locals, params, getClientAddress }) {
244244

245245
let pdfSearchResults: PdfSearch | undefined;
246246
const pdfSearch = await collections.files.findOne({ filename: `${convId.toString()}-pdf` });
247-
if(pdfSearch){
247+
if (pdfSearch) {
248248
pdfSearchResults = await runPdfSearch(conv, newPrompt, update);
249249
}
250250

0 commit comments

Comments
 (0)