lint and format
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
experimental: {
|
experimental: {
|
||||||
serverActions: {
|
serverActions: {
|
||||||
bodySizeLimit: '10mb',
|
bodySizeLimit: "10mb",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ import {
|
|||||||
import type { Base64ContentBlock } from "@/lib/pdf";
|
import type { Base64ContentBlock } from "@/lib/pdf";
|
||||||
|
|
||||||
type MessageContentType = Message["content"];
|
type MessageContentType = Message["content"];
|
||||||
|
interface UploadedBlock {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
block: Base64ContentBlock;
|
||||||
|
}
|
||||||
|
|
||||||
function StickyToBottomContent(props: {
|
function StickyToBottomContent(props: {
|
||||||
content: ReactNode;
|
content: ReactNode;
|
||||||
@@ -106,12 +111,6 @@ function OpenGitHubRepo() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UploadedBlock {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
block: Base64ContentBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Thread() {
|
export function Thread() {
|
||||||
const [threadId, setThreadId] = useQueryState("threadId");
|
const [threadId, setThreadId] = useQueryState("threadId");
|
||||||
const [chatHistoryOpen, setChatHistoryOpen] = useQueryState(
|
const [chatHistoryOpen, setChatHistoryOpen] = useQueryState(
|
||||||
@@ -193,7 +192,6 @@ export function Thread() {
|
|||||||
] as MessageContentType,
|
] as MessageContentType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const toolMessages = ensureToolCallsHaveResponses(stream.messages);
|
const toolMessages = ensureToolCallsHaveResponses(stream.messages);
|
||||||
stream.submit(
|
stream.submit(
|
||||||
{ messages: [...toolMessages, newHumanMessage] },
|
{ messages: [...toolMessages, newHumanMessage] },
|
||||||
@@ -240,14 +238,13 @@ export function Thread() {
|
|||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
});
|
});
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
setImageUrlList([...imageUrlList, ...imageFiles]);
|
setImageUrlList([...imageUrlList, ...imageFiles]);
|
||||||
}
|
}
|
||||||
e.target.value = "";
|
e.target.value = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handlePDFUpload = async (e: ChangeEvent<HTMLInputElement>) => {
|
const handlePDFUpload = async (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
const files = e.target.files;
|
const files = e.target.files;
|
||||||
if (files) {
|
if (files) {
|
||||||
@@ -274,7 +271,7 @@ export function Thread() {
|
|||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
});
|
});
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
console.log(pdfFiles[0]);
|
console.log(pdfFiles[0]);
|
||||||
setPdfUrlList([...pdfUrlList, ...pdfFiles]);
|
setPdfUrlList([...pdfUrlList, ...pdfFiles]);
|
||||||
@@ -282,9 +279,6 @@ export function Thread() {
|
|||||||
e.target.value = "";
|
e.target.value = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const handleRegenerate = (
|
const handleRegenerate = (
|
||||||
parentCheckpoint: Checkpoint | null | undefined,
|
parentCheckpoint: Checkpoint | null | undefined,
|
||||||
) => {
|
) => {
|
||||||
@@ -317,12 +311,17 @@ export function Thread() {
|
|||||||
if (!e.dataTransfer) return;
|
if (!e.dataTransfer) return;
|
||||||
|
|
||||||
const files = Array.from(e.dataTransfer.files);
|
const files = Array.from(e.dataTransfer.files);
|
||||||
const imageFiles = files.filter((file) =>
|
const imageFiles = files.filter((file) => file.type.startsWith("image/"));
|
||||||
file.type.startsWith("image/"),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (files.some(file => !file.type.startsWith("image/") || file.type !== "application/pdf")) {
|
if (
|
||||||
toast.error("You have uploaded invalid file type. Please upload an image or a PDF.");
|
files.some(
|
||||||
|
(file) =>
|
||||||
|
!file.type.startsWith("image/") || file.type !== "application/pdf",
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
toast.error(
|
||||||
|
"You have uploaded invalid file type. Please upload an image or a PDF.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -354,7 +353,7 @@ export function Thread() {
|
|||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
});
|
});
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
setImageUrlList([...imageUrlList, ...imageFilesData]);
|
setImageUrlList([...imageUrlList, ...imageFilesData]);
|
||||||
}
|
}
|
||||||
@@ -363,8 +362,10 @@ export function Thread() {
|
|||||||
* If there are any PDF files in the dropped files, this block previews the file name of each uploaded PDF
|
* If there are any PDF files in the dropped files, this block previews the file name of each uploaded PDF
|
||||||
* by rendering a list of file names above the input area, with a remove button for each.
|
* by rendering a list of file names above the input area, with a remove button for each.
|
||||||
*/
|
*/
|
||||||
if (files.some(file => file.type === "application/pdf")) {
|
if (files.some((file) => file.type === "application/pdf")) {
|
||||||
const pdfFiles = files.filter(file => file.type === "application/pdf");
|
const pdfFiles = files.filter(
|
||||||
|
(file) => file.type === "application/pdf",
|
||||||
|
);
|
||||||
const pdfFilesData: UploadedBlock[] = await Promise.all(
|
const pdfFilesData: UploadedBlock[] = await Promise.all(
|
||||||
pdfFiles.map((file) => {
|
pdfFiles.map((file) => {
|
||||||
return new Promise<UploadedBlock>((resolve) => {
|
return new Promise<UploadedBlock>((resolve) => {
|
||||||
@@ -373,7 +374,8 @@ export function Thread() {
|
|||||||
const result = reader.result as string;
|
const result = reader.result as string;
|
||||||
const base64 = result.split(",")[1];
|
const base64 = result.split(",")[1];
|
||||||
const match = result.match(/^data:(.*);base64/);
|
const match = result.match(/^data:(.*);base64/);
|
||||||
const mimeType = match && match[1] ? match[1] : "application/pdf";
|
const mimeType =
|
||||||
|
match && match[1] ? match[1] : "application/pdf";
|
||||||
resolve({
|
resolve({
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
name: file.name,
|
name: file.name,
|
||||||
@@ -388,7 +390,7 @@ export function Thread() {
|
|||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
});
|
});
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
setPdfUrlList([...pdfUrlList, ...pdfFilesData]);
|
setPdfUrlList([...pdfUrlList, ...pdfFilesData]);
|
||||||
}
|
}
|
||||||
@@ -418,7 +420,6 @@ export function Thread() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen w-full overflow-hidden">
|
<div className="flex h-screen w-full overflow-hidden">
|
||||||
<div className="relative hidden lg:flex">
|
<div className="relative hidden lg:flex">
|
||||||
@@ -642,11 +643,20 @@ export function Thread() {
|
|||||||
{pdfUrlList.length > 0 && (
|
{pdfUrlList.length > 0 && (
|
||||||
<div className="flex flex-wrap gap-2 p-3.5 pb-0">
|
<div className="flex flex-wrap gap-2 p-3.5 pb-0">
|
||||||
{pdfUrlList.map((pdf) => (
|
{pdfUrlList.map((pdf) => (
|
||||||
<div className="relative flex items-center gap-2 bg-gray-100 rounded px-2 py-1 border-1 border-teal-700 bg-teal-900 text-white rounded-md px-2 py-2" key={pdf.id}>
|
<div
|
||||||
<span className=" truncate max-w-xs text-sm">{pdf.name}</span>
|
className="relative flex items-center gap-2 rounded rounded-md border-1 border-teal-700 bg-gray-100 bg-teal-900 px-2 py-1 py-2 text-white"
|
||||||
|
key={pdf.id}
|
||||||
|
>
|
||||||
|
<span className="max-w-xs truncate text-sm">
|
||||||
|
{pdf.name}
|
||||||
|
</span>
|
||||||
<CircleX
|
<CircleX
|
||||||
className="size-4 cursor-pointer text-teal-600 hover:text-teal-500"
|
className="size-4 cursor-pointer text-teal-600 hover:text-teal-500"
|
||||||
onClick={() => setPdfUrlList(pdfUrlList.filter((p) => p.id !== pdf.id))}
|
onClick={() =>
|
||||||
|
setPdfUrlList(
|
||||||
|
pdfUrlList.filter((p) => p.id !== pdf.id),
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"use server"
|
"use server";
|
||||||
import { MessageContentText } from "@langchain/core/messages";
|
import { MessageContentText } from "@langchain/core/messages";
|
||||||
import { WebPDFLoader } from "@langchain/community/document_loaders/web/pdf";
|
import { WebPDFLoader } from "@langchain/community/document_loaders/web/pdf";
|
||||||
// import { Base64ContentBlock } from "@langchain/core/messages";
|
// import { Base64ContentBlock } from "@langchain/core/messages";
|
||||||
@@ -12,8 +12,9 @@ export interface Base64ContentBlock {
|
|||||||
type: "image" | "audio" | "file";
|
type: "image" | "audio" | "file";
|
||||||
}
|
}
|
||||||
|
|
||||||
export const extractPdfText = async (file: File): Promise<MessageContentText> => {
|
export const extractPdfText = async (
|
||||||
|
file: File,
|
||||||
|
): Promise<MessageContentText> => {
|
||||||
const loader = new WebPDFLoader(file, { splitPages: false });
|
const loader = new WebPDFLoader(file, { splitPages: false });
|
||||||
const docs = await loader.load();
|
const docs = await loader.load();
|
||||||
return {
|
return {
|
||||||
@@ -22,9 +23,6 @@ export const extractPdfText = async (file: File): Promise<MessageContentText> =>
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const cleanBase64 = (base64String: string): string => {
|
const cleanBase64 = (base64String: string): string => {
|
||||||
return base64String.replace(/^data:.*?;base64,/, "");
|
return base64String.replace(/^data:.*?;base64,/, "");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user