From 2c12b17dda1bb68cfb6cba0bfd253b296b9087bb Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sat, 23 Nov 2024 14:04:57 +0530 Subject: [PATCH] feat(vision): add vision chat mode - Add new "vision" chat mode to the application - Implement the `visionChatMode` function to handle vision-based chat interactions - Update the UI to include a new button to toggle the vision chat mode - Add new translations for the "vision" chat mode tooltip - Disable certain UI elements when the vision chat mode is active --- src/assets/locale/en/playground.json | 3 +- src/components/Sidepanel/Chat/form.tsx | 70 ++++-- src/hooks/useMessage.tsx | 292 ++++++++++++++++++++++--- src/libs/get-screenshot.ts | 46 ++++ src/store/index.tsx | 4 +- 5 files changed, 368 insertions(+), 47 deletions(-) create mode 100644 src/libs/get-screenshot.ts diff --git a/src/assets/locale/en/playground.json b/src/assets/locale/en/playground.json index 2fc5041..c4f5f5c 100644 --- a/src/assets/locale/en/playground.json +++ b/src/assets/locale/en/playground.json @@ -23,7 +23,8 @@ "speechToText": "Speech to Text", "uploadImage": "Upload Image", "stopStreaming": "Stop Streaming", - "knowledge": "Knowledge" + "knowledge": "Knowledge", + "vision": "[Experimental] Vision Chat" }, "sendWhenEnter": "Send when Enter pressed", "welcome": "Hello! How can I help you today?" diff --git a/src/components/Sidepanel/Chat/form.tsx b/src/components/Sidepanel/Chat/form.tsx index 618431d..a402680 100644 --- a/src/components/Sidepanel/Chat/form.tsx +++ b/src/components/Sidepanel/Chat/form.tsx @@ -7,7 +7,14 @@ import { toBase64 } from "~/libs/to-base64" import { Checkbox, Dropdown, Image, Switch, Tooltip } from "antd" import { useWebUI } from "~/store/webui" import { defaultEmbeddingModelForRag } from "~/services/ollama" -import { ImageIcon, MicIcon, StopCircleIcon, X } from "lucide-react" +import { + ImageIcon, + MicIcon, + StopCircleIcon, + X, + EyeIcon, + EyeOffIcon +} from "lucide-react" import { useTranslation } from "react-i18next" import { ModelSelect } from "@/components/Common/ModelSelect" import { useSpeechRecognition } from "@/hooks/useSpeechRecognition" @@ -36,7 +43,7 @@ export const SidepanelForm = ({ dropedFile }: Props) => { resetTranscript, start: startListening, stop: stopSpeechRecognition, - supported: browserSupportsSpeechRecognition, + supported: browserSupportsSpeechRecognition } = useSpeechRecognition() const stopListening = async () => { @@ -237,7 +244,10 @@ export const SidepanelForm = ({ dropedFile }: Props) => { } } await stopListening() - if (value.message.trim().length === 0 && value.image.length === 0) { + if ( + value.message.trim().length === 0 && + value.image.length === 0 + ) { return } form.reset() @@ -281,20 +291,22 @@ export const SidepanelForm = ({ dropedFile }: Props) => { {...form.getInputProps("message")} />
- - - + {chatMode !== "vision" && ( + + + + )} {browserSupportsSpeechRecognition && ( @@ -323,13 +335,35 @@ export const SidepanelForm = ({ dropedFile }: Props) => { )} + + +