diff --git a/package.json b/package.json
index d216a8c..bc29c86 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,7 @@
"@headlessui/react": "^1.7.18",
"@heroicons/react": "^2.1.1",
"@langchain/community": "^0.0.21",
+ "@langchain/core": "^0.1.22",
"@mantine/form": "^7.5.0",
"@plasmohq/storage": "^1.9.0",
"@tailwindcss/forms": "^0.5.7",
diff --git a/src/chain/chat-with-website.ts b/src/chain/chat-with-website.ts
index 0d0acf0..9a2793a 100644
--- a/src/chain/chat-with-website.ts
+++ b/src/chain/chat-with-website.ts
@@ -1,5 +1,5 @@
import { BaseLanguageModel } from "langchain/base_language";
-import { Document } from "langchain/document";
+import { Document } from "@langchain/core/documents";
import {
ChatPromptTemplate,
MessagesPlaceholder,
diff --git a/src/components/Common/Playground/Message.tsx b/src/components/Common/Playground/Message.tsx
index 324635c..c75869a 100644
--- a/src/components/Common/Playground/Message.tsx
+++ b/src/components/Common/Playground/Message.tsx
@@ -1,7 +1,4 @@
-import {
- CheckIcon,
- ClipboardIcon,
-} from "@heroicons/react/24/outline"
+import { CheckIcon, ClipboardIcon } from "@heroicons/react/24/outline"
import Markdown from "../../Common/Markdown"
import React from "react"
@@ -12,6 +9,7 @@ type Props = {
userAvatar?: JSX.Element
isBot: boolean
name: string
+ images?: string[]
}
export const PlaygroundMessage = (props: Props) => {
@@ -48,13 +46,11 @@ export const PlaygroundMessage = (props: Props) => {
- {
- props.isBot && (
+ {props.isBot && (
{props.name}
- )
- }
+ )}
@@ -81,6 +77,19 @@ export const PlaygroundMessage = (props: Props) => {
)}
+ {props.images && (
+
+ {props.images.map((image, index) => (
+
+

+
+ ))}
+
+ )}
)
}
diff --git a/src/components/Sidepanel/Chat/body.tsx b/src/components/Sidepanel/Chat/body.tsx
index dffb389..6624b43 100644
--- a/src/components/Sidepanel/Chat/body.tsx
+++ b/src/components/Sidepanel/Chat/body.tsx
@@ -20,6 +20,7 @@ export const SidePanelBody = () => {
isBot={message.isBot}
message={message.message}
name={message.name}
+ images={message.images || []}
/>
))}
diff --git a/src/components/Sidepanel/Chat/form.tsx b/src/components/Sidepanel/Chat/form.tsx
index b5d9081..34982ec 100644
--- a/src/components/Sidepanel/Chat/form.tsx
+++ b/src/components/Sidepanel/Chat/form.tsx
@@ -3,9 +3,17 @@ import { useMutation } from "@tanstack/react-query"
import React from "react"
import useDynamicTextareaSize from "~hooks/useDynamicTextareaSize"
import { useMessage } from "~hooks/useMessage"
+import PhotoIcon from "@heroicons/react/24/outline/PhotoIcon"
+import XMarkIcon from "@heroicons/react/24/outline/XMarkIcon"
+import { toBase64 } from "~libs/to-base64"
-export const SidepanelForm = () => {
+type Props = {
+ dropedFile: File | undefined
+}
+
+export const SidepanelForm = ({ dropedFile }: Props) => {
const textareaRef = React.useRef(null)
+ const inputRef = React.useRef(null)
const resetHeight = () => {
const textarea = textareaRef.current
@@ -15,16 +23,34 @@ export const SidepanelForm = () => {
}
const form = useForm({
initialValues: {
- message: ""
+ message: "",
+ image: ""
}
})
- useDynamicTextareaSize(
- textareaRef,
- form.values.message,
- )
+ const onInputChange = async (
+ e: React.ChangeEvent | File
+ ) => {
+ if (e instanceof File) {
+ const base64 = await toBase64(e)
+ form.setFieldValue("image", base64)
+ } else {
+ if (e.target.files) {
+ const base64 = await toBase64(e.target.files[0])
+ form.setFieldValue("image", base64)
+ }
+ }
+ }
- const { onSubmit, selectedModel } = useMessage()
+ React.useEffect(() => {
+ if (dropedFile) {
+ onInputChange(dropedFile)
+ }
+ }, [dropedFile])
+
+ useDynamicTextareaSize(textareaRef, form.values.message, 120)
+
+ const { onSubmit, selectedModel, chatMode } = useMessage()
const { mutateAsync: sendMessage, isPending: isSending } = useMutation({
mutationFn: onSubmit
@@ -33,6 +59,24 @@ export const SidepanelForm = () => {
return (
+ {chatMode === "normal" && form.values.image && (
+
+
+

+
+
+
+ )}