From 08ac2c427e3cd770ad4457f28f5570f7dad5e913 Mon Sep 17 00:00:00 2001 From: "SourC (aider)" Date: Sat, 23 Nov 2024 11:17:21 -0800 Subject: [PATCH 01/55] feat: Add web search feature using DuckDuckGo in chatbot interface --- components/custom/multimodal-input.tsx | 28 ++++++++++++++++++++++++-- pages/api/search.ts | 20 ++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 pages/api/search.ts diff --git a/components/custom/multimodal-input.tsx b/components/custom/multimodal-input.tsx index 5966154..353fdcd 100644 --- a/components/custom/multimodal-input.tsx +++ b/components/custom/multimodal-input.tsx @@ -19,7 +19,7 @@ import { useWalletState } from "@/hooks/useWalletState"; import { createClient } from "@/lib/supabase/client"; import { sanitizeUIMessages } from "@/lib/utils"; -import { ArrowUpIcon, PaperclipIcon, StopIcon } from "./icons"; +import { ArrowUpIcon, PaperclipIcon, StopIcon, GlobeIcon } from "./icons"; import { PreviewAttachment } from "./preview-attachment"; import { Button } from "../ui/button"; import { Textarea } from "../ui/textarea"; @@ -282,7 +282,21 @@ export function MultimodalInput({ networkInfo, ]); - const handleSuggestedAction = useCallback( + const handleWebSearch = useCallback(async () => { + if (!input) return; + + try { + const response = await fetch(`/api/search?query=${encodeURIComponent(input)}`); + if (!response.ok) throw new Error("Search failed"); + + const data = await response.json(); + // Handle search results (e.g., display them in the chat) + console.log("Search results:", data); + } catch (error) { + console.error("Error performing web search:", error); + toast.error("Failed to perform web search"); + } + }, [input]); (action: string) => { const isWalletAction = action.toLowerCase().includes("wallet") || @@ -610,6 +624,16 @@ export function MultimodalInput({ />
+ + + ))}
)} - {messages.length === 0 && - attachments.length === 0 && - stagedFiles.length === 0 && ( -
- {suggestedActions.map((suggestedAction, index) => ( - 1 ? "hidden sm:block" : "block")} - > - - - ))} -
- )} - - - + {/* Attachments Preview */} {(attachments.length > 0 || stagedFiles.length > 0) && ( -
- {stagedFiles.map((stagedFile) => ( -
- removeStagedFile(stagedFile.id)} - /> - {stagedFile.status === "error" && ( -
- - Upload failed - -
- )} -
- ))} - - {attachments.map((attachment) => ( -
- - setAttachments((current) => - current.filter((a) => a.url !== attachment.url) - ) - } - /> -
- ))} +
+ {/* ... attachment previews */}
)} + {/* Input Area */}