From 323f3c516c6a1bdeae787969bd8277b8fd3833fc Mon Sep 17 00:00:00 2001 From: Zan <37948383+zandko@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:06:33 +0800 Subject: [PATCH 1/7] perf: Optimize document filtering and sorting for performance --- src/agents/redditSearchAgent.ts | 6 +++--- src/agents/webSearchAgent.ts | 6 +++--- src/agents/youtubeSearchAgent.ts | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/agents/redditSearchAgent.ts b/src/agents/redditSearchAgent.ts index 3c60c68..578e2bb 100644 --- a/src/agents/redditSearchAgent.ts +++ b/src/agents/redditSearchAgent.ts @@ -52,8 +52,8 @@ const basicRedditSearchResponsePrompt = ` Place these citations at the end of that particular sentence. You can cite the same sentence multiple times if it is relevant to the user's query like [number1][number2]. However you do not need to cite it using the same number. You can use different numbers to cite the same sentence multiple times. The number refers to the number of the search result (passed in the context) used to generate that part of the answer. - Anything inside the following \`context\` HTML block provided below is for your knowledge returned by Reddit and is not shared by the user. You have to answer question on the basis of it and cite the relevant information from it but you do not have to - talk about the context in your response. + Anything inside the following \`context\` HTML block provided below is for your knowledge returned by Reddit and is not shared by the user. You have to answer question on the basis of it and cite the relevant information from it but you do not have to + talk about the context in your response. {context} @@ -177,9 +177,9 @@ const createBasicRedditSearchAnsweringChain = ( }); const sortedDocs = similarity + .filter((sim) => sim.similarity > 0.3) .sort((a, b) => b.similarity - a.similarity) .slice(0, 15) - .filter((sim) => sim.similarity > 0.3) .map((sim) => docsWithContent[sim.index]); return sortedDocs; diff --git a/src/agents/webSearchAgent.ts b/src/agents/webSearchAgent.ts index 04de148..9818d01 100644 --- a/src/agents/webSearchAgent.ts +++ b/src/agents/webSearchAgent.ts @@ -52,8 +52,8 @@ const basicWebSearchResponsePrompt = ` Place these citations at the end of that particular sentence. You can cite the same sentence multiple times if it is relevant to the user's query like [number1][number2]. However you do not need to cite it using the same number. You can use different numbers to cite the same sentence multiple times. The number refers to the number of the search result (passed in the context) used to generate that part of the answer. - Anything inside the following \`context\` HTML block provided below is for your knowledge returned by the search engine and is not shared by the user. You have to answer question on the basis of it and cite the relevant information from it but you do not have to - talk about the context in your response. + Anything inside the following \`context\` HTML block provided below is for your knowledge returned by the search engine and is not shared by the user. You have to answer question on the basis of it and cite the relevant information from it but you do not have to + talk about the context in your response. {context} @@ -175,8 +175,8 @@ const createBasicWebSearchAnsweringChain = ( }); const sortedDocs = similarity - .sort((a, b) => b.similarity - a.similarity) .filter((sim) => sim.similarity > 0.5) + .sort((a, b) => b.similarity - a.similarity) .slice(0, 15) .map((sim) => docsWithContent[sim.index]); diff --git a/src/agents/youtubeSearchAgent.ts b/src/agents/youtubeSearchAgent.ts index 334f67e..4133157 100644 --- a/src/agents/youtubeSearchAgent.ts +++ b/src/agents/youtubeSearchAgent.ts @@ -52,8 +52,8 @@ const basicYoutubeSearchResponsePrompt = ` Place these citations at the end of that particular sentence. You can cite the same sentence multiple times if it is relevant to the user's query like [number1][number2]. However you do not need to cite it using the same number. You can use different numbers to cite the same sentence multiple times. The number refers to the number of the search result (passed in the context) used to generate that part of the answer. - Anything inside the following \`context\` HTML block provided below is for your knowledge returned by Youtube and is not shared by the user. You have to answer question on the basis of it and cite the relevant information from it but you do not have to - talk about the context in your response. + Anything inside the following \`context\` HTML block provided below is for your knowledge returned by Youtube and is not shared by the user. You have to answer question on the basis of it and cite the relevant information from it but you do not have to + talk about the context in your response. {context} @@ -177,9 +177,9 @@ const createBasicYoutubeSearchAnsweringChain = ( }); const sortedDocs = similarity + .filter((sim) => sim.similarity > 0.3) .sort((a, b) => b.similarity - a.similarity) .slice(0, 15) - .filter((sim) => sim.similarity > 0.3) .map((sim) => docsWithContent[sim.index]); return sortedDocs; From 8143eca2c15318bbee08ee3e9763ea0f3632f46c Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:45:52 +0530 Subject: [PATCH 2/7] feat(readme): remove patreon --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 884fad6..3c87acc 100644 --- a/README.md +++ b/README.md @@ -146,9 +146,9 @@ If you find Perplexica useful, consider giving us a star on GitHub. This helps m We also accept donations to help sustain our project. If you would like to contribute, you can use the following options to donate. Thank you for your support! -| Cards | Ethereum | -| ----------------------------------- | ----------------------------------------------------- | -| https://www.patreon.com/itzcrazykns | Address: `0xB025a84b2F269570Eb8D4b05DEdaA41D8525B6DD` | +| Ethereum | +| ----------------------------------------------------- | +| Address: `0xB025a84b2F269570Eb8D4b05DEdaA41D8525B6DD` | ## Contribution From 00a52fc3b1605b88f709cef0d393bcc24a2b5dec Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:46:32 +0530 Subject: [PATCH 3/7] Delete .github/FUNDING.yml --- .github/FUNDING.yml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index faa9fa9..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -patreon: itzcrazykns From 8a76f92e23e7be1bc987e9973056c496d2baffd7 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns Date: Tue, 23 Jul 2024 20:49:17 +0530 Subject: [PATCH 4/7] feat(groq): add Llama 3.1 --- src/lib/providers/groq.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/lib/providers/groq.ts b/src/lib/providers/groq.ts index ac5dc3b..ffe8f6c 100644 --- a/src/lib/providers/groq.ts +++ b/src/lib/providers/groq.ts @@ -9,6 +9,26 @@ export const loadGroqChatModels = async () => { try { const chatModels = { + 'Llama 3.1 70B': new ChatOpenAI( + { + openAIApiKey: groqApiKey, + modelName: 'llama-3.1-70b-versatile', + temperature: 0.7, + }, + { + baseURL: 'https://api.groq.com/openai/v1', + }, + ), + 'Llama 3.1 8B': new ChatOpenAI( + { + openAIApiKey: groqApiKey, + modelName: 'llama-3.1-8b-instant', + temperature: 0.7, + }, + { + baseURL: 'https://api.groq.com/openai/v1', + }, + ), 'LLaMA3 8b': new ChatOpenAI( { openAIApiKey: groqApiKey, From 27f8cfd212ac1f0b3ee18a6b9737b7a7636bb03f Mon Sep 17 00:00:00 2001 From: ItzCrazyKns Date: Thu, 25 Jul 2024 20:33:56 +0530 Subject: [PATCH 5/7] feat(toast): fix theme colors --- docs/installation/UPDATING.md | 1 + ui/app/layout.tsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/installation/UPDATING.md b/docs/installation/UPDATING.md index fa89b41..df67775 100644 --- a/docs/installation/UPDATING.md +++ b/docs/installation/UPDATING.md @@ -17,6 +17,7 @@ To update Perplexica to the latest version, follow these steps: ```bash docker compose up -d --build ``` + 4. Once the command completes running go to http://localhost:3000 and verify the latest changes. ## For non Docker users diff --git a/ui/app/layout.tsx b/ui/app/layout.tsx index 2edbf94..684a99c 100644 --- a/ui/app/layout.tsx +++ b/ui/app/layout.tsx @@ -34,7 +34,7 @@ export default function RootLayout({ unstyled: true, classNames: { toast: - 'bg-light-primary dark:bg-dark-primary text-white rounded-lg p-4 flex flex-row items-center space-x-2', + 'bg-light-primary dark:bg-dark-secondary dark:text-white/70 text-black-70 rounded-lg p-4 flex flex-row items-center space-x-2', }, }} /> From cbce39a5ddb4cbca21ea75cba981b94187fbaef6 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns Date: Thu, 25 Jul 2024 20:34:49 +0530 Subject: [PATCH 6/7] feat(settings): fix `undefined` model for custom OpenAI --- ui/components/SettingsDialog.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/components/SettingsDialog.tsx b/ui/components/SettingsDialog.tsx index 788469b..171e812 100644 --- a/ui/components/SettingsDialog.tsx +++ b/ui/components/SettingsDialog.tsx @@ -225,9 +225,13 @@ const SettingsDialog = ({ value={selectedChatModelProvider ?? undefined} onChange={(e) => { setSelectedChatModelProvider(e.target.value); - setSelectedChatModel( - config.chatModelProviders[e.target.value][0], - ); + if (e.target.value === 'custom_openai') { + setSelectedChatModel(''); + } else { + setSelectedChatModel( + config.chatModelProviders[e.target.value][0], + ); + } }} options={Object.keys(config.chatModelProviders).map( (provider) => ({ From 08379fcad5a9cb40b66f48f3078aebb16c5fa6e5 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns Date: Thu, 25 Jul 2024 20:36:26 +0530 Subject: [PATCH 7/7] feat(ws-connector): fix `undefined` chat model --- ui/components/ChatWindow.tsx | 38 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index f2c89a3..ea9a93d 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -54,13 +54,26 @@ const useSocket = ( ).then(async (res) => await res.json()); const chatModelProviders = providers.chatModelProviders; - const embeddingModelProviders = providers.embeddingModelProviders; - if ( - !chatModelProviders || - Object.keys(chatModelProviders).length === 0 - ) - return toast.error('No chat models available'); + chatModelProvider = Object.keys(chatModelProviders)[0]; + + if (chatModelProvider === 'custom_openai') { + toast.error( + 'Seems like you are using the custom OpenAI provider, please open the settings and configure the API key and base URL', + ); + setError(true); + return; + } else { + chatModel = Object.keys(chatModelProviders[chatModelProvider])[0]; + + if ( + !chatModelProviders || + Object.keys(chatModelProviders).length === 0 + ) + return toast.error('No chat models available'); + } + + const embeddingModelProviders = providers.embeddingModelProviders; if ( !embeddingModelProviders || @@ -68,9 +81,6 @@ const useSocket = ( ) return toast.error('No embedding models available'); - chatModelProvider = Object.keys(chatModelProviders)[0]; - chatModel = Object.keys(chatModelProviders[chatModelProvider])[0]; - embeddingModelProvider = Object.keys(embeddingModelProviders)[0]; embeddingModel = Object.keys( embeddingModelProviders[embeddingModelProvider], @@ -88,7 +98,7 @@ const useSocket = ( `${process.env.NEXT_PUBLIC_API_URL}/models`, { headers: { - 'Content-Type': 'application/json', + 'Content-Type': 'app lication/json', }, }, ).then(async (res) => await res.json()); @@ -106,6 +116,7 @@ const useSocket = ( if ( chatModelProvider && + chatModelProvider != 'custom_openai' && !chatModelProviders[chatModelProvider][chatModel] ) { chatModel = Object.keys(chatModelProviders[chatModelProvider])[0]; @@ -187,6 +198,13 @@ const useSocket = ( console.log('[DEBUG] closed'); }; + ws.addEventListener('message', (e) => { + const data = JSON.parse(e.data); + if (data.type === 'error') { + toast.error(data.data); + } + }); + setWs(ws); };