From 641968cf6aed77787b09f6e9c98c1274de2280ce Mon Sep 17 00:00:00 2001 From: Willie Zutz Date: Wed, 7 May 2025 22:12:06 -0600 Subject: [PATCH] feat(search): Implement OpenSearch support --- public/opensearch.xml | 9 +++++++++ src/app/api/chat/route.ts | 2 +- src/app/layout.tsx | 8 ++++++++ src/components/MessageBox.tsx | 8 ++++++-- src/components/MessageInput.tsx | 10 +++++++--- src/lib/search/metaSearchAgent.ts | 8 ++++---- 6 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 public/opensearch.xml diff --git a/public/opensearch.xml b/public/opensearch.xml new file mode 100644 index 0000000..7a9bc99 --- /dev/null +++ b/public/opensearch.xml @@ -0,0 +1,9 @@ + + + Perplexica + Search with Perplexica AI + UTF-8 + /favicon.ico + + + diff --git a/src/app/api/chat/route.ts b/src/app/api/chat/route.ts index 42582ed..00b720b 100644 --- a/src/app/api/chat/route.ts +++ b/src/app/api/chat/route.ts @@ -7,7 +7,7 @@ import db from '@/lib/db'; import { chats, messages as messagesSchema } from '@/lib/db/schema'; import { getAvailableChatModelProviders, - getAvailableEmbeddingModelProviders + getAvailableEmbeddingModelProviders, } from '@/lib/providers'; import { searchHandlers } from '@/lib/search'; import { getFileDetails } from '@/lib/utils/files'; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 684a99c..f90be8a 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -26,6 +26,14 @@ export default function RootLayout({ }>) { return ( + + + {children} diff --git a/src/components/MessageBox.tsx b/src/components/MessageBox.tsx index 0b08650..c657345 100644 --- a/src/components/MessageBox.tsx +++ b/src/components/MessageBox.tsx @@ -280,8 +280,12 @@ const MessageBox = ({ {message.searchQuery && (
- Search query:{' '} - {message.searchQuery} + + Search query: + {' '} + + {message.searchQuery} +
)} diff --git a/src/components/MessageInput.tsx b/src/components/MessageInput.tsx index 3303dea..2bd0dec 100644 --- a/src/components/MessageInput.tsx +++ b/src/components/MessageInput.tsx @@ -86,7 +86,7 @@ const MessageInput = ({ setMessage(''); }; - return ( + return (
{ e.preventDefault(); @@ -107,7 +107,7 @@ const MessageInput = ({ onChange={(e) => setMessage(e.target.value)} minRows={2} className="bg-transparent placeholder:text-black/50 dark:placeholder:text-white/50 text-sm text-black dark:text-white resize-none focus:outline-none w-full max-h-24 lg:max-h-36 xl:max-h-48" - placeholder={firstMessage ? "Ask anything..." :"Ask a follow-up"} + placeholder={firstMessage ? 'Ask anything...' : 'Ask a follow-up'} />
@@ -134,7 +134,11 @@ const MessageInput = ({ className="bg-[#24A0ED] text-white disabled:text-black/50 dark:disabled:text-white/50 disabled:bg-[#e0e0dc] dark:disabled:bg-[#ececec21] hover:bg-opacity-85 transition duration-100 rounded-full p-2" type="submit" > - {firstMessage ? : } + {firstMessage ? ( + + ) : ( + + )}
diff --git a/src/lib/search/metaSearchAgent.ts b/src/lib/search/metaSearchAgent.ts index a7cbdf1..f452739 100644 --- a/src/lib/search/metaSearchAgent.ts +++ b/src/lib/search/metaSearchAgent.ts @@ -265,7 +265,7 @@ class MetaSearchAgent implements MetaSearchAgentType { query = searchRetrieverResult.query; docs = searchRetrieverResult.docs; - + // Store the search query in the context for emitting to the client if (searchRetrieverResult.searchQuery) { this.searchQuery = searchRetrieverResult.searchQuery; @@ -453,10 +453,10 @@ class MetaSearchAgent implements MetaSearchAgentType { if (this.searchQuery) { emitter.emit( 'data', - JSON.stringify({ - type: 'sources', + JSON.stringify({ + type: 'sources', data: sourcesData, - searchQuery: this.searchQuery + searchQuery: this.searchQuery, }), ); } else {