From f3e918c3e39debf7310a052799d6f1ae41f7b5f0 Mon Sep 17 00:00:00 2001 From: Damien Laureaux Date: Fri, 15 Nov 2024 07:04:45 +0100 Subject: [PATCH 01/26] chore(docs): fix Markdown lint issues in the docs --- docs/API/SEARCH.md | 34 ++++++------- docs/architecture/README.md | 2 +- docs/architecture/WORKING.md | 6 +-- docs/installation/NETWORKING.md | 90 ++++++++++++++++----------------- docs/installation/UPDATING.md | 24 ++++----- 5 files changed, 78 insertions(+), 78 deletions(-) diff --git a/docs/API/SEARCH.md b/docs/API/SEARCH.md index f87e788..9405bc5 100644 --- a/docs/API/SEARCH.md +++ b/docs/API/SEARCH.md @@ -79,24 +79,24 @@ The response from the API includes both the final message and the sources used t ```json { - "message": "Perplexica is an innovative, open-source AI-powered search engine designed to enhance the way users search for information online. Here are some key features and characteristics of Perplexica:\n\n- **AI-Powered Technology**: It utilizes advanced machine learning algorithms to not only retrieve information but also to understand the context and intent behind user queries, providing more relevant results [1][5].\n\n- **Open-Source**: Being open-source, Perplexica offers flexibility and transparency, allowing users to explore its functionalities without the constraints of proprietary software [3][10].", - "sources": [ - { - "pageContent": "Perplexica is an innovative, open-source AI-powered search engine designed to enhance the way users search for information online.", - "metadata": { - "title": "What is Perplexica, and how does it function as an AI-powered search ...", - "url": "https://askai.glarity.app/search/What-is-Perplexica--and-how-does-it-function-as-an-AI-powered-search-engine" - } - }, - { - "pageContent": "Perplexica is an open-source AI-powered search tool that dives deep into the internet to find precise answers.", - "metadata": { - "title": "Sahar Mor's Post", - "url": "https://www.linkedin.com/posts/sahar-mor_a-new-open-source-project-called-perplexica-activity-7204489745668694016-ncja" - } - } + "message": "Perplexica is an innovative, open-source AI-powered search engine designed to enhance the way users search for information online. Here are some key features and characteristics of Perplexica:\n\n- **AI-Powered Technology**: It utilizes advanced machine learning algorithms to not only retrieve information but also to understand the context and intent behind user queries, providing more relevant results [1][5].\n\n- **Open-Source**: Being open-source, Perplexica offers flexibility and transparency, allowing users to explore its functionalities without the constraints of proprietary software [3][10].", + "sources": [ + { + "pageContent": "Perplexica is an innovative, open-source AI-powered search engine designed to enhance the way users search for information online.", + "metadata": { + "title": "What is Perplexica, and how does it function as an AI-powered search ...", + "url": "https://askai.glarity.app/search/What-is-Perplexica--and-how-does-it-function-as-an-AI-powered-search-engine" + } + }, + { + "pageContent": "Perplexica is an open-source AI-powered search tool that dives deep into the internet to find precise answers.", + "metadata": { + "title": "Sahar Mor's Post", + "url": "https://www.linkedin.com/posts/sahar-mor_a-new-open-source-project-called-perplexica-activity-7204489745668694016-ncja" + } + } .... - ] + ] } ``` diff --git a/docs/architecture/README.md b/docs/architecture/README.md index b1fcfcb..5732471 100644 --- a/docs/architecture/README.md +++ b/docs/architecture/README.md @@ -1,4 +1,4 @@ -## Perplexica's Architecture +# Perplexica's Architecture Perplexica's architecture consists of the following key components: diff --git a/docs/architecture/WORKING.md b/docs/architecture/WORKING.md index e39de7a..75b20fd 100644 --- a/docs/architecture/WORKING.md +++ b/docs/architecture/WORKING.md @@ -1,4 +1,4 @@ -## How does Perplexica work? +# How does Perplexica work? Curious about how Perplexica works? Don't worry, we'll cover it here. Before we begin, make sure you've read about the architecture of Perplexica to ensure you understand what it's made up of. Haven't read it? You can read it [here](https://github.com/ItzCrazyKns/Perplexica/tree/master/docs/architecture/README.md). @@ -10,10 +10,10 @@ We'll understand how Perplexica works by taking an example of a scenario where a 4. After the information is retrieved, it is based on keyword-based search. We then convert the information into embeddings and the query as well, then we perform a similarity search to find the most relevant sources to answer the query. 5. After all this is done, the sources are passed to the response generator. This chain takes all the chat history, the query, and the sources. It generates a response that is streamed to the UI. -### How are the answers cited? +## How are the answers cited? The LLMs are prompted to do so. We've prompted them so well that they cite the answers themselves, and using some UI magic, we display it to the user. -### Image and Video Search +## Image and Video Search Image and video searches are conducted in a similar manner. A query is always generated first, then we search the web for images and videos that match the query. These results are then returned to the user. diff --git a/docs/installation/NETWORKING.md b/docs/installation/NETWORKING.md index baad296..6cb9bfe 100644 --- a/docs/installation/NETWORKING.md +++ b/docs/installation/NETWORKING.md @@ -10,27 +10,27 @@ This guide will show you how to make Perplexica available over a network. Follow 3. Stop and remove the existing Perplexica containers and images: -``` -docker compose down --rmi all -``` + ```bash + docker compose down --rmi all + ``` 4. Open the `docker-compose.yaml` file in a text editor like Notepad++ 5. Replace `127.0.0.1` with the IP address of the server Perplexica is running on in these two lines: -``` -args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 -``` + ```bash + args: + - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api + - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 + ``` 6. Save and close the `docker-compose.yaml` file 7. Rebuild and restart the Perplexica container: -``` -docker compose up -d --build -``` + ```bash + docker compose up -d --build + ``` ## macOS @@ -38,37 +38,37 @@ docker compose up -d --build 2. Navigate to the directory with the `docker-compose.yaml` file: -``` -cd /path/to/docker-compose.yaml -``` + ```bash + cd /path/to/docker-compose.yaml + ``` 3. Stop and remove existing containers and images: -``` -docker compose down --rmi all -``` + ```bash + docker compose down --rmi all + ``` 4. Open `docker-compose.yaml` in a text editor like Sublime Text: -``` -nano docker-compose.yaml -``` + ```bash + nano docker-compose.yaml + ``` 5. Replace `127.0.0.1` with the server IP in these lines: -``` -args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 -``` + ```bash + args: + - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api + - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 + ``` 6. Save and exit the editor 7. Rebuild and restart Perplexica: -``` -docker compose up -d --build -``` + ```bash + docker compose up -d --build + ``` ## Linux @@ -76,34 +76,34 @@ docker compose up -d --build 2. Navigate to the `docker-compose.yaml` directory: -``` -cd /path/to/docker-compose.yaml -``` + ```bash + cd /path/to/docker-compose.yaml + ``` 3. Stop and remove containers and images: -``` -docker compose down --rmi all -``` + ```bash + docker compose down --rmi all + ``` 4. Edit `docker-compose.yaml`: -``` -nano docker-compose.yaml -``` + ```bash + nano docker-compose.yaml + ``` 5. Replace `127.0.0.1` with the server IP: -``` -args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 -``` + ```bash + args: + - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api + - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 + ``` 6. Save and exit the editor 7. Rebuild and restart Perplexica: -``` -docker compose up -d --build -``` + ```bash + docker compose up -d --build + ``` diff --git a/docs/installation/UPDATING.md b/docs/installation/UPDATING.md index 031a3e8..b41b05a 100644 --- a/docs/installation/UPDATING.md +++ b/docs/installation/UPDATING.md @@ -6,23 +6,23 @@ To update Perplexica to the latest version, follow these steps: 1. Clone the latest version of Perplexica from GitHub: -```bash - git clone https://github.com/ItzCrazyKns/Perplexica.git -``` + ```bash + git clone https://github.com/ItzCrazyKns/Perplexica.git + ``` 2. Navigate to the Project Directory. 3. Pull latest images from registry. -```bash -docker compose pull -``` + ```bash + docker compose pull + ``` 4. Update and Recreate containers. -```bash -docker compose up -d -``` + ```bash + docker compose up -d + ``` 5. Once the command completes running go to http://localhost:3000 and verify the latest changes. @@ -30,9 +30,9 @@ docker compose up -d 1. Clone the latest version of Perplexica from GitHub: -```bash - git clone https://github.com/ItzCrazyKns/Perplexica.git -``` + ```bash + git clone https://github.com/ItzCrazyKns/Perplexica.git + ``` 2. Navigate to the Project Directory 3. Execute `npm i` in both the `ui` folder and the root directory. From e08d86444565a1976c4888037a615070360487eb Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Sat, 30 Nov 2024 20:58:11 +0530 Subject: [PATCH 02/26] feat(focus): only icon on small devices --- ui/components/MessageInputActions/Focus.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/components/MessageInputActions/Focus.tsx b/ui/components/MessageInputActions/Focus.tsx index c95be5a..613078b 100644 --- a/ui/components/MessageInputActions/Focus.tsx +++ b/ui/components/MessageInputActions/Focus.tsx @@ -83,7 +83,7 @@ const Focus = ({ {focusMode !== 'webSearch' ? (
{focusModes.find((mode) => mode.key === focusMode)?.icon} -

+

{focusModes.find((mode) => mode.key === focusMode)?.title}

@@ -91,7 +91,7 @@ const Focus = ({ ) : (
-

Focus

+

Focus

)} From 8cb74f1964f3867e46fb431b1585f408b1f44dec Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:07:59 +0530 Subject: [PATCH 03/26] feat(contribution): update guidelines --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 73256bd..b16eccf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,6 +8,7 @@ Perplexica's design consists of two main domains: - **Frontend (`ui` directory)**: This is a Next.js application holding all user interface components. It's a self-contained environment that manages everything the user interacts with. - **Backend (root and `src` directory)**: The backend logic is situated in the `src` folder, but the root directory holds the main `package.json` for backend dependency management. + - All of the focus modes are created using the Meta Search Agent class present in `src/search/metaSearchAgent.ts`. The main logic behind Perplexica lies there. ## Setting Up Your Environment From 5b3e8a321472fb712d66ea38caa839a650ed8a2e Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Thu, 5 Dec 2024 20:19:22 +0530 Subject: [PATCH 04/26] feat(prompts): implement new prompt --- src/prompts/academicSearch.ts | 47 +++++++++++++++++++++++++--------- src/prompts/redditSearch.ts | 47 +++++++++++++++++++++++++--------- src/prompts/webSearch.ts | 48 +++++++++++++++++++++++++---------- src/prompts/wolframAlpha.ts | 47 +++++++++++++++++++++++++--------- src/prompts/youtubeSearch.ts | 47 +++++++++++++++++++++++++--------- src/search/metaSearchAgent.ts | 1 + 6 files changed, 175 insertions(+), 62 deletions(-) diff --git a/src/prompts/academicSearch.ts b/src/prompts/academicSearch.ts index 30495ee..c2946ff 100644 --- a/src/prompts/academicSearch.ts +++ b/src/prompts/academicSearch.ts @@ -20,23 +20,46 @@ Rephrased question: `; export const academicSearchResponsePrompt = ` - You are Perplexica, an AI model who is expert at searching the web and answering user's queries. You are set on focus mode 'Academic', this means you will be searching for academic papers and articles on the web. + You are Perplexica, an AI model skilled in web search and crafting detailed, engaging, and well-structured answers. You excel at summarizing web pages and extracting relevant information to create professional, blog-style responses. - Generate a response that is informative and relevant to the user's query based on provided context (the context consits of search results containing a brief description of the content of that page). - You must use this context to answer the user's query in the best way possible. Use an unbaised and journalistic tone in your response. Do not repeat the text. - You must not tell the user to open any link or visit any website to get the answer. You must provide the answer in the response itself. If the user asks for links you can provide them. - Your responses should be medium to long in length be informative and relevant to the user's query. You can use markdowns to format your response. You should use bullet points to list the information. Make sure the answer is not short and is informative. - You have to cite the answer using [number] notation. You must cite the sentences with their relevent context number. You must cite each and every part of the answer so the user can know where the information is coming from. - 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. + Your task is to provide answers that are: + - **Informative and relevant**: Thoroughly address the user's query using the given context. + - **Well-structured**: Include clear headings and subheadings, and use a professional tone to present information concisely and logically. + - **Engaging and detailed**: Write responses that read like a high-quality blog post, including extra details and relevant insights. + - **Cited and credible**: Use inline citations with [number] notation to refer to the context source(s) for each fact or detail included. + - **Explanatory and Comprehensive**: Strive to explain the topic in depth, offering detailed analysis, insights, and clarifications wherever applicable. - 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. + ### Formatting Instructions + - **Structure**: Use a well-organized format with proper headings (e.g., "## Example heading 1" or "## Example heading 2"). Present information in paragraphs or concise bullet points where appropriate. + - **Tone and Style**: Maintain a neutral, journalistic tone with engaging narrative flow. Write as though you're crafting an in-depth article for a professional audience. + - **Markdown Usage**: Format your response with Markdown for clarity. Use headings, subheadings, bold text, and italicized words as needed to enhance readability. + - **Length and Depth**: Provide comprehensive coverage of the topic. Avoid superficial responses and strive for depth without unnecessary repetition. Expand on technical or complex topics to make them easier to understand for a general audience. + - **No main heading/title**: Start your response directly with the introduction unless asked to provide a specific title. + - **Conclusion or Summary**: Include a concluding paragraph that synthesizes the provided information or suggests potential next steps, where appropriate. + + ### Citation Requirements + - Cite every single fact, statement, or sentence using [number] notation corresponding to the source from the provided \`context\`. + - Integrate citations naturally at the end of sentences or clauses as appropriate. For example, "The Eiffel Tower is one of the most visited landmarks in the world[1]." + - Ensure that **every sentence in your response includes at least one citation**, even when information is inferred or connected to general knowledge available in the provided context. + - Use multiple sources for a single detail if applicable, such as, "Paris is a cultural hub, attracting millions of visitors annually[1][2]." + - Always prioritize credibility and accuracy by linking all statements back to their respective context sources. + - Avoid citing unsupported assumptions or personal interpretations; if no source supports a statement, clearly indicate the limitation. + + ### Special Instructions + - If the query involves technical, historical, or complex topics, provide detailed background and explanatory sections to ensure clarity. + - If the user provides vague input or if relevant information is missing, explain what additional details might help refine the search. + - If no relevant information is found, say: "Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?" Be transparent about limitations and suggest alternatives or ways to reframe the query. + - You are set on focus mode 'Academic', this means you will be searching for academic papers and articles on the web. + + ### Example Output + - Begin with a brief introduction summarizing the event or query topic. + - Follow with detailed sections under clear headings, covering all aspects of the query if possible. + - Provide explanations or historical context as needed to enhance understanding. + - End with a conclusion or overall perspective if relevant. {context} - If you think there's nothing relevant in the search results, you can say that 'Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?'. - Anything between the \`context\` is retrieved from a search engine and is not a part of the conversation with the user. Today's date is ${new Date().toISOString()} + Current date & time in ISO format (UTC timezone) is: {date}. `; diff --git a/src/prompts/redditSearch.ts b/src/prompts/redditSearch.ts index 1418eac..fc71957 100644 --- a/src/prompts/redditSearch.ts +++ b/src/prompts/redditSearch.ts @@ -20,23 +20,46 @@ Rephrased question: `; export const redditSearchResponsePrompt = ` - You are Perplexica, an AI model who is expert at searching the web and answering user's queries. You are set on focus mode 'Reddit', this means you will be searching for information, opinions and discussions on the web using Reddit. + You are Perplexica, an AI model skilled in web search and crafting detailed, engaging, and well-structured answers. You excel at summarizing web pages and extracting relevant information to create professional, blog-style responses. - Generate a response that is informative and relevant to the user's query based on provided context (the context consits of search results containing a brief description of the content of that page). - You must use this context to answer the user's query in the best way possible. Use an unbaised and journalistic tone in your response. Do not repeat the text. - You must not tell the user to open any link or visit any website to get the answer. You must provide the answer in the response itself. If the user asks for links you can provide them. - Your responses should be medium to long in length be informative and relevant to the user's query. You can use markdowns to format your response. You should use bullet points to list the information. Make sure the answer is not short and is informative. - You have to cite the answer using [number] notation. You must cite the sentences with their relevent context number. You must cite each and every part of the answer so the user can know where the information is coming from. - 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. + Your task is to provide answers that are: + - **Informative and relevant**: Thoroughly address the user's query using the given context. + - **Well-structured**: Include clear headings and subheadings, and use a professional tone to present information concisely and logically. + - **Engaging and detailed**: Write responses that read like a high-quality blog post, including extra details and relevant insights. + - **Cited and credible**: Use inline citations with [number] notation to refer to the context source(s) for each fact or detail included. + - **Explanatory and Comprehensive**: Strive to explain the topic in depth, offering detailed analysis, insights, and clarifications wherever applicable. - 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. + ### Formatting Instructions + - **Structure**: Use a well-organized format with proper headings (e.g., "## Example heading 1" or "## Example heading 2"). Present information in paragraphs or concise bullet points where appropriate. + - **Tone and Style**: Maintain a neutral, journalistic tone with engaging narrative flow. Write as though you're crafting an in-depth article for a professional audience. + - **Markdown Usage**: Format your response with Markdown for clarity. Use headings, subheadings, bold text, and italicized words as needed to enhance readability. + - **Length and Depth**: Provide comprehensive coverage of the topic. Avoid superficial responses and strive for depth without unnecessary repetition. Expand on technical or complex topics to make them easier to understand for a general audience. + - **No main heading/title**: Start your response directly with the introduction unless asked to provide a specific title. + - **Conclusion or Summary**: Include a concluding paragraph that synthesizes the provided information or suggests potential next steps, where appropriate. + + ### Citation Requirements + - Cite every single fact, statement, or sentence using [number] notation corresponding to the source from the provided \`context\`. + - Integrate citations naturally at the end of sentences or clauses as appropriate. For example, "The Eiffel Tower is one of the most visited landmarks in the world[1]." + - Ensure that **every sentence in your response includes at least one citation**, even when information is inferred or connected to general knowledge available in the provided context. + - Use multiple sources for a single detail if applicable, such as, "Paris is a cultural hub, attracting millions of visitors annually[1][2]." + - Always prioritize credibility and accuracy by linking all statements back to their respective context sources. + - Avoid citing unsupported assumptions or personal interpretations; if no source supports a statement, clearly indicate the limitation. + + ### Special Instructions + - If the query involves technical, historical, or complex topics, provide detailed background and explanatory sections to ensure clarity. + - If the user provides vague input or if relevant information is missing, explain what additional details might help refine the search. + - If no relevant information is found, say: "Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?" Be transparent about limitations and suggest alternatives or ways to reframe the query. + - You are set on focus mode 'Reddit', this means you will be searching for information, opinions and discussions on the web using Reddit. + + ### Example Output + - Begin with a brief introduction summarizing the event or query topic. + - Follow with detailed sections under clear headings, covering all aspects of the query if possible. + - Provide explanations or historical context as needed to enhance understanding. + - End with a conclusion or overall perspective if relevant. {context} - If you think there's nothing relevant in the search results, you can say that 'Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?'. - Anything between the \`context\` is retrieved from Reddit and is not a part of the conversation with the user. Today's date is ${new Date().toISOString()} + Current date & time in ISO format (UTC timezone) is: {date}. `; diff --git a/src/prompts/webSearch.ts b/src/prompts/webSearch.ts index 834bbfe..d8269c8 100644 --- a/src/prompts/webSearch.ts +++ b/src/prompts/webSearch.ts @@ -62,25 +62,45 @@ Rephrased question: `; export const webSearchResponsePrompt = ` - You are Perplexica, an AI model who is expert at searching the web and answering user's queries. You are also an expert at summarizing web pages or documents and searching for content in them. + You are Perplexica, an AI model skilled in web search and crafting detailed, engaging, and well-structured answers. You excel at summarizing web pages and extracting relevant information to create professional, blog-style responses. - Generate a response that is informative and relevant to the user's query based on provided context (the context consits of search results containing a brief description of the content of that page). - You must use this context to answer the user's query in the best way possible. Use an unbaised and journalistic tone in your response. Do not repeat the text. - You must not tell the user to open any link or visit any website to get the answer. You must provide the answer in the response itself. If the user asks for links you can provide them. - If the query contains some links and the user asks to answer from those links you will be provided the entire content of the page inside the \`context\` XML block. You can then use this content to answer the user's query. - If the user asks to summarize content from some links, you will be provided the entire content of the page inside the \`context\` XML block. You can then use this content to summarize the text. The content provided inside the \`context\` block will be already summarized by another model so you just need to use that content to answer the user's query. - Your responses should be medium to long in length be informative and relevant to the user's query. You can use markdowns to format your response. You should use bullet points to list the information. Make sure the answer is not short and is informative. - You have to cite the answer using [number] notation. You must cite the sentences with their relevent context number. You must cite each and every part of the answer so the user can know where the information is coming from. - 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. + Your task is to provide answers that are: + - **Informative and relevant**: Thoroughly address the user's query using the given context. + - **Well-structured**: Include clear headings and subheadings, and use a professional tone to present information concisely and logically. + - **Engaging and detailed**: Write responses that read like a high-quality blog post, including extra details and relevant insights. + - **Cited and credible**: Use inline citations with [number] notation to refer to the context source(s) for each fact or detail included. + - **Explanatory and Comprehensive**: Strive to explain the topic in depth, offering detailed analysis, insights, and clarifications wherever applicable. - 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. + ### Formatting Instructions + - **Structure**: Use a well-organized format with proper headings (e.g., "## Example heading 1" or "## Example heading 2"). Present information in paragraphs or concise bullet points where appropriate. + - **Tone and Style**: Maintain a neutral, journalistic tone with engaging narrative flow. Write as though you're crafting an in-depth article for a professional audience. + - **Markdown Usage**: Format your response with Markdown for clarity. Use headings, subheadings, bold text, and italicized words as needed to enhance readability. + - **Length and Depth**: Provide comprehensive coverage of the topic. Avoid superficial responses and strive for depth without unnecessary repetition. Expand on technical or complex topics to make them easier to understand for a general audience. + - **No main heading/title**: Start your response directly with the introduction unless asked to provide a specific title. + - **Conclusion or Summary**: Include a concluding paragraph that synthesizes the provided information or suggests potential next steps, where appropriate. + + ### Citation Requirements + - Cite every single fact, statement, or sentence using [number] notation corresponding to the source from the provided \`context\`. + - Integrate citations naturally at the end of sentences or clauses as appropriate. For example, "The Eiffel Tower is one of the most visited landmarks in the world[1]." + - Ensure that **every sentence in your response includes at least one citation**, even when information is inferred or connected to general knowledge available in the provided context. + - Use multiple sources for a single detail if applicable, such as, "Paris is a cultural hub, attracting millions of visitors annually[1][2]." + - Always prioritize credibility and accuracy by linking all statements back to their respective context sources. + - Avoid citing unsupported assumptions or personal interpretations; if no source supports a statement, clearly indicate the limitation. + + ### Special Instructions + - If the query involves technical, historical, or complex topics, provide detailed background and explanatory sections to ensure clarity. + - If the user provides vague input or if relevant information is missing, explain what additional details might help refine the search. + - If no relevant information is found, say: "Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?" Be transparent about limitations and suggest alternatives or ways to reframe the query. + + ### Example Output + - Begin with a brief introduction summarizing the event or query topic. + - Follow with detailed sections under clear headings, covering all aspects of the query if possible. + - Provide explanations or historical context as needed to enhance understanding. + - End with a conclusion or overall perspective if relevant. {context} - If you think there's nothing relevant in the search results, you can say that 'Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?'. You do not need to do this for summarization tasks. - Anything between the \`context\` is retrieved from a search engine and is not a part of the conversation with the user. Today's date is ${new Date().toISOString()} + Current date & time in ISO format (UTC timezone) is: {date}. `; diff --git a/src/prompts/wolframAlpha.ts b/src/prompts/wolframAlpha.ts index 2e9c022..40410c1 100644 --- a/src/prompts/wolframAlpha.ts +++ b/src/prompts/wolframAlpha.ts @@ -20,23 +20,46 @@ Rephrased question: `; export const wolframAlphaSearchResponsePrompt = ` - You are Perplexica, an AI model who is expert at searching the web and answering user's queries. You are set on focus mode 'Wolfram Alpha', this means you will be searching for information on the web using Wolfram Alpha. It is a computational knowledge engine that can answer factual queries and perform computations. + You are Perplexica, an AI model skilled in web search and crafting detailed, engaging, and well-structured answers. You excel at summarizing web pages and extracting relevant information to create professional, blog-style responses. - Generate a response that is informative and relevant to the user's query based on provided context (the context consits of search results containing a brief description of the content of that page). - You must use this context to answer the user's query in the best way possible. Use an unbaised and journalistic tone in your response. Do not repeat the text. - You must not tell the user to open any link or visit any website to get the answer. You must provide the answer in the response itself. If the user asks for links you can provide them. - Your responses should be medium to long in length be informative and relevant to the user's query. You can use markdowns to format your response. You should use bullet points to list the information. Make sure the answer is not short and is informative. - You have to cite the answer using [number] notation. You must cite the sentences with their relevent context number. You must cite each and every part of the answer so the user can know where the information is coming from. - 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. + Your task is to provide answers that are: + - **Informative and relevant**: Thoroughly address the user's query using the given context. + - **Well-structured**: Include clear headings and subheadings, and use a professional tone to present information concisely and logically. + - **Engaging and detailed**: Write responses that read like a high-quality blog post, including extra details and relevant insights. + - **Cited and credible**: Use inline citations with [number] notation to refer to the context source(s) for each fact or detail included. + - **Explanatory and Comprehensive**: Strive to explain the topic in depth, offering detailed analysis, insights, and clarifications wherever applicable. - Anything inside the following \`context\` HTML block provided below is for your knowledge returned by Wolfram Alpha 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. + ### Formatting Instructions + - **Structure**: Use a well-organized format with proper headings (e.g., "## Example heading 1" or "## Example heading 2"). Present information in paragraphs or concise bullet points where appropriate. + - **Tone and Style**: Maintain a neutral, journalistic tone with engaging narrative flow. Write as though you're crafting an in-depth article for a professional audience. + - **Markdown Usage**: Format your response with Markdown for clarity. Use headings, subheadings, bold text, and italicized words as needed to enhance readability. + - **Length and Depth**: Provide comprehensive coverage of the topic. Avoid superficial responses and strive for depth without unnecessary repetition. Expand on technical or complex topics to make them easier to understand for a general audience. + - **No main heading/title**: Start your response directly with the introduction unless asked to provide a specific title. + - **Conclusion or Summary**: Include a concluding paragraph that synthesizes the provided information or suggests potential next steps, where appropriate. + + ### Citation Requirements + - Cite every single fact, statement, or sentence using [number] notation corresponding to the source from the provided \`context\`. + - Integrate citations naturally at the end of sentences or clauses as appropriate. For example, "The Eiffel Tower is one of the most visited landmarks in the world[1]." + - Ensure that **every sentence in your response includes at least one citation**, even when information is inferred or connected to general knowledge available in the provided context. + - Use multiple sources for a single detail if applicable, such as, "Paris is a cultural hub, attracting millions of visitors annually[1][2]." + - Always prioritize credibility and accuracy by linking all statements back to their respective context sources. + - Avoid citing unsupported assumptions or personal interpretations; if no source supports a statement, clearly indicate the limitation. + + ### Special Instructions + - If the query involves technical, historical, or complex topics, provide detailed background and explanatory sections to ensure clarity. + - If the user provides vague input or if relevant information is missing, explain what additional details might help refine the search. + - If no relevant information is found, say: "Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?" Be transparent about limitations and suggest alternatives or ways to reframe the query. + - You are set on focus mode 'Wolfram Alpha', this means you will be searching for information on the web using Wolfram Alpha. It is a computational knowledge engine that can answer factual queries and perform computations. + + ### Example Output + - Begin with a brief introduction summarizing the event or query topic. + - Follow with detailed sections under clear headings, covering all aspects of the query if possible. + - Provide explanations or historical context as needed to enhance understanding. + - End with a conclusion or overall perspective if relevant. {context} - If you think there's nothing relevant in the search results, you can say that 'Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?'. - Anything between the \`context\` is retrieved from Wolfram Alpha and is not a part of the conversation with the user. Today's date is ${new Date().toISOString()} + Current date & time in ISO format (UTC timezone) is: {date}. `; diff --git a/src/prompts/youtubeSearch.ts b/src/prompts/youtubeSearch.ts index 5c729cb..5805b54 100644 --- a/src/prompts/youtubeSearch.ts +++ b/src/prompts/youtubeSearch.ts @@ -20,23 +20,46 @@ Rephrased question: `; export const youtubeSearchResponsePrompt = ` - You are Perplexica, an AI model who is expert at searching the web and answering user's queries. You are set on focus mode 'Youtube', this means you will be searching for videos on the web using Youtube and providing information based on the video's transcript. + You are Perplexica, an AI model skilled in web search and crafting detailed, engaging, and well-structured answers. You excel at summarizing web pages and extracting relevant information to create professional, blog-style responses. - Generate a response that is informative and relevant to the user's query based on provided context (the context consits of search results containing a brief description of the content of that page). - You must use this context to answer the user's query in the best way possible. Use an unbaised and journalistic tone in your response. Do not repeat the text. - You must not tell the user to open any link or visit any website to get the answer. You must provide the answer in the response itself. If the user asks for links you can provide them. - Your responses should be medium to long in length be informative and relevant to the user's query. You can use markdowns to format your response. You should use bullet points to list the information. Make sure the answer is not short and is informative. - You have to cite the answer using [number] notation. You must cite the sentences with their relevent context number. You must cite each and every part of the answer so the user can know where the information is coming from. - 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. + Your task is to provide answers that are: + - **Informative and relevant**: Thoroughly address the user's query using the given context. + - **Well-structured**: Include clear headings and subheadings, and use a professional tone to present information concisely and logically. + - **Engaging and detailed**: Write responses that read like a high-quality blog post, including extra details and relevant insights. + - **Cited and credible**: Use inline citations with [number] notation to refer to the context source(s) for each fact or detail included. + - **Explanatory and Comprehensive**: Strive to explain the topic in depth, offering detailed analysis, insights, and clarifications wherever applicable. - 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. + ### Formatting Instructions + - **Structure**: Use a well-organized format with proper headings (e.g., "## Example heading 1" or "## Example heading 2"). Present information in paragraphs or concise bullet points where appropriate. + - **Tone and Style**: Maintain a neutral, journalistic tone with engaging narrative flow. Write as though you're crafting an in-depth article for a professional audience. + - **Markdown Usage**: Format your response with Markdown for clarity. Use headings, subheadings, bold text, and italicized words as needed to enhance readability. + - **Length and Depth**: Provide comprehensive coverage of the topic. Avoid superficial responses and strive for depth without unnecessary repetition. Expand on technical or complex topics to make them easier to understand for a general audience. + - **No main heading/title**: Start your response directly with the introduction unless asked to provide a specific title. + - **Conclusion or Summary**: Include a concluding paragraph that synthesizes the provided information or suggests potential next steps, where appropriate. + + ### Citation Requirements + - Cite every single fact, statement, or sentence using [number] notation corresponding to the source from the provided \`context\`. + - Integrate citations naturally at the end of sentences or clauses as appropriate. For example, "The Eiffel Tower is one of the most visited landmarks in the world[1]." + - Ensure that **every sentence in your response includes at least one citation**, even when information is inferred or connected to general knowledge available in the provided context. + - Use multiple sources for a single detail if applicable, such as, "Paris is a cultural hub, attracting millions of visitors annually[1][2]." + - Always prioritize credibility and accuracy by linking all statements back to their respective context sources. + - Avoid citing unsupported assumptions or personal interpretations; if no source supports a statement, clearly indicate the limitation. + + ### Special Instructions + - If the query involves technical, historical, or complex topics, provide detailed background and explanatory sections to ensure clarity. + - If the user provides vague input or if relevant information is missing, explain what additional details might help refine the search. + - If no relevant information is found, say: "Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?" Be transparent about limitations and suggest alternatives or ways to reframe the query. + - You are set on focus mode 'Youtube', this means you will be searching for videos on the web using Youtube and providing information based on the video's transcrip + + ### Example Output + - Begin with a brief introduction summarizing the event or query topic. + - Follow with detailed sections under clear headings, covering all aspects of the query if possible. + - Provide explanations or historical context as needed to enhance understanding. + - End with a conclusion or overall perspective if relevant. {context} - If you think there's nothing relevant in the search results, you can say that 'Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?'. - Anything between the \`context\` is retrieved from Youtube and is not a part of the conversation with the user. Today's date is ${new Date().toISOString()} + Current date & time in ISO format (UTC timezone) is: {date}. `; diff --git a/src/search/metaSearchAgent.ts b/src/search/metaSearchAgent.ts index 0dde085..b1d8114 100644 --- a/src/search/metaSearchAgent.ts +++ b/src/search/metaSearchAgent.ts @@ -236,6 +236,7 @@ class MetaSearchAgent implements MetaSearchAgentType { RunnableMap.from({ query: (input: BasicChainInput) => input.query, chat_history: (input: BasicChainInput) => input.chat_history, + date: () => new Date().toISOString(), context: RunnableLambda.from(async (input: BasicChainInput) => { const processedHistory = formatChatHistoryAsString( input.chat_history, From db7407bfac20825333da330aaf9869be06722910 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Thu, 5 Dec 2024 20:19:41 +0530 Subject: [PATCH 05/26] feat(messageBox): style markdown --- ui/components/MessageBox.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/components/MessageBox.tsx b/ui/components/MessageBox.tsx index 5222c7c..f23127c 100644 --- a/ui/components/MessageBox.tsx +++ b/ui/components/MessageBox.tsx @@ -107,8 +107,8 @@ const MessageBox = ({
{parsedMessage} From 2c5ca94b3c7c5f1c7425fb0d7f7603d857690c30 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Thu, 5 Dec 2024 20:19:52 +0530 Subject: [PATCH 06/26] feat(app): lint and beautify --- docs/installation/NETWORKING.md | 90 ++++++++++++++++----------------- src/routes/config.ts | 2 +- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/docs/installation/NETWORKING.md b/docs/installation/NETWORKING.md index 6cb9bfe..ae39e3f 100644 --- a/docs/installation/NETWORKING.md +++ b/docs/installation/NETWORKING.md @@ -10,27 +10,27 @@ This guide will show you how to make Perplexica available over a network. Follow 3. Stop and remove the existing Perplexica containers and images: - ```bash - docker compose down --rmi all - ``` + ```bash + docker compose down --rmi all + ``` 4. Open the `docker-compose.yaml` file in a text editor like Notepad++ 5. Replace `127.0.0.1` with the IP address of the server Perplexica is running on in these two lines: - ```bash - args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 - ``` + ```bash + args: + - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api + - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 + ``` 6. Save and close the `docker-compose.yaml` file 7. Rebuild and restart the Perplexica container: - ```bash - docker compose up -d --build - ``` + ```bash + docker compose up -d --build + ``` ## macOS @@ -38,37 +38,37 @@ This guide will show you how to make Perplexica available over a network. Follow 2. Navigate to the directory with the `docker-compose.yaml` file: - ```bash - cd /path/to/docker-compose.yaml - ``` + ```bash + cd /path/to/docker-compose.yaml + ``` 3. Stop and remove existing containers and images: - ```bash - docker compose down --rmi all - ``` + ```bash + docker compose down --rmi all + ``` 4. Open `docker-compose.yaml` in a text editor like Sublime Text: - ```bash - nano docker-compose.yaml - ``` + ```bash + nano docker-compose.yaml + ``` 5. Replace `127.0.0.1` with the server IP in these lines: - ```bash - args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 - ``` + ```bash + args: + - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api + - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 + ``` 6. Save and exit the editor 7. Rebuild and restart Perplexica: - ```bash - docker compose up -d --build - ``` + ```bash + docker compose up -d --build + ``` ## Linux @@ -76,34 +76,34 @@ This guide will show you how to make Perplexica available over a network. Follow 2. Navigate to the `docker-compose.yaml` directory: - ```bash - cd /path/to/docker-compose.yaml - ``` + ```bash + cd /path/to/docker-compose.yaml + ``` 3. Stop and remove containers and images: - ```bash - docker compose down --rmi all - ``` + ```bash + docker compose down --rmi all + ``` 4. Edit `docker-compose.yaml`: - ```bash - nano docker-compose.yaml - ``` + ```bash + nano docker-compose.yaml + ``` 5. Replace `127.0.0.1` with the server IP: - ```bash - args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 - ``` + ```bash + args: + - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api + - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 + ``` 6. Save and exit the editor 7. Rebuild and restart Perplexica: - ```bash - docker compose up -d --build - ``` + ```bash + docker compose up -d --build + ``` diff --git a/src/routes/config.ts b/src/routes/config.ts index 38192b7..6ff80c6 100644 --- a/src/routes/config.ts +++ b/src/routes/config.ts @@ -54,7 +54,7 @@ router.get('/', async (_, res) => { config['anthropicApiKey'] = getAnthropicApiKey(); config['groqApiKey'] = getGroqApiKey(); config['geminiApiKey'] = getGeminiApiKey(); - + res.status(200).json(config); } catch (err: any) { res.status(500).json({ message: 'An error has occurred.' }); From 1c3c6890398efa6eabfab7e0fb1744494cb26fec Mon Sep 17 00:00:00 2001 From: Ying-Shan Lin Date: Fri, 13 Dec 2024 17:24:15 +0800 Subject: [PATCH 07/26] feat(anthropic): update chat models to include Claude 3.5 Haiku and new version for Sonnet --- src/lib/providers/anthropic.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/providers/anthropic.ts b/src/lib/providers/anthropic.ts index 90460c6..642a6cb 100644 --- a/src/lib/providers/anthropic.ts +++ b/src/lib/providers/anthropic.ts @@ -9,12 +9,20 @@ export const loadAnthropicChatModels = async () => { try { const chatModels = { - 'claude-3-5-sonnet-20240620': { + 'claude-3-5-sonnet-20241022': { displayName: 'Claude 3.5 Sonnet', model: new ChatAnthropic({ temperature: 0.7, anthropicApiKey: anthropicApiKey, - model: 'claude-3-5-sonnet-20240620', + model: 'claude-3-5-sonnet-20241022', + }), + }, + 'claude-3-5-haiku-20241022': { + displayName: 'Claude 3.5 Haiku', + model: new ChatAnthropic({ + temperature: 0.7, + anthropicApiKey: anthropicApiKey, + model: 'claude-3-5-haiku-20241022', }), }, 'claude-3-opus-20240229': { From f30a61c4aa9c0c1289b39aca6d9ac158fdee7efa Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:24:01 +0530 Subject: [PATCH 08/26] feat(metaSearchAgent): handle `undefined` content for YT. search --- src/search/metaSearchAgent.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/search/metaSearchAgent.ts b/src/search/metaSearchAgent.ts index b1d8114..1e85cf6 100644 --- a/src/search/metaSearchAgent.ts +++ b/src/search/metaSearchAgent.ts @@ -211,7 +211,11 @@ class MetaSearchAgent implements MetaSearchAgentType { const documents = res.results.map( (result) => new Document({ - pageContent: result.content, + pageContent: + result.content || + this.config.activeEngines.includes('youtube') + ? result.title + : '' /* Todo: Implement transcript grabbing using Youtubei (source: https://www.npmjs.com/package/youtubei) */, metadata: { title: result.title, url: result.url, @@ -414,7 +418,10 @@ class MetaSearchAgent implements MetaSearchAgentType { private processDocs(docs: Document[]) { return docs - .map((_, index) => `${index + 1}. ${docs[index].pageContent}`) + .map( + (_, index) => + `${index + 1}. ${docs[index].metadata.title} ${docs[index].pageContent}`, + ) .join('\n'); } From c3a231a528d969e72cd5d83a83ca4e3ddb9ee849 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:59:21 +0530 Subject: [PATCH 09/26] feat(readme): add discord server --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 721d41c..cf9e459 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # 🚀 Perplexica - An AI-powered search engine 🔎 +[![Discord](https://dcbadge.vercel.app/api/server/26aArMy8tT?style=flat&compact=true)](https://discord.gg/26aArMy8tT) + + ![preview](.assets/perplexica-screenshot.png?) ## Table of Contents From 4cb38148b31eb53db37a9447450847f6d0c8ac96 Mon Sep 17 00:00:00 2001 From: Bart Jaskulski Date: Thu, 19 Dec 2024 08:07:14 +0100 Subject: [PATCH 10/26] Remove deprecated Groq models Signed-off-by: Bart Jaskulski --- src/lib/providers/groq.ts | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/lib/providers/groq.ts b/src/lib/providers/groq.ts index 62ca2d7..16f251b 100644 --- a/src/lib/providers/groq.ts +++ b/src/lib/providers/groq.ts @@ -48,19 +48,6 @@ export const loadGroqChatModels = async () => { }, ), }, - 'llama-3.1-70b-versatile': { - displayName: 'Llama 3.1 70B', - model: new ChatOpenAI( - { - openAIApiKey: groqApiKey, - modelName: 'llama-3.1-70b-versatile', - temperature: 0.7, - }, - { - baseURL: 'https://api.groq.com/openai/v1', - }, - ), - }, 'llama-3.1-8b-instant': { displayName: 'Llama 3.1 8B', model: new ChatOpenAI( @@ -113,19 +100,6 @@ export const loadGroqChatModels = async () => { }, ), }, - 'gemma-7b-it': { - displayName: 'Gemma 7B', - model: new ChatOpenAI( - { - openAIApiKey: groqApiKey, - modelName: 'gemma-7b-it', - temperature: 0.7, - }, - { - baseURL: 'https://api.groq.com/openai/v1', - }, - ), - }, 'gemma2-9b-it': { displayName: 'Gemma2 9B', model: new ChatOpenAI( From 960e34aa3df48ea85777796f2aa5aa08812f79fb Mon Sep 17 00:00:00 2001 From: Bart Jaskulski Date: Thu, 19 Dec 2024 08:07:36 +0100 Subject: [PATCH 11/26] Add Llama 3.3 model from Groq Signed-off-by: Bart Jaskulski --- src/lib/providers/groq.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib/providers/groq.ts b/src/lib/providers/groq.ts index 16f251b..41004ec 100644 --- a/src/lib/providers/groq.ts +++ b/src/lib/providers/groq.ts @@ -9,6 +9,19 @@ export const loadGroqChatModels = async () => { try { const chatModels = { + 'llama-3.3-70b-versatile': { + displayName: 'Llama 3.3 70B', + model: new ChatOpenAI( + { + openAIApiKey: groqApiKey, + modelName: 'llama-3.3-70b-versatile', + temperature: 0.7, + }, + { + baseURL: 'https://api.groq.com/openai/v1', + }, + ), + }, 'llama-3.2-3b-preview': { displayName: 'Llama 3.2 3B', model: new ChatOpenAI( From d30f714930e39ddd6192317902b1134899de5dc3 Mon Sep 17 00:00:00 2001 From: hacking-racoon Date: Wed, 25 Dec 2024 15:19:23 +0900 Subject: [PATCH 12/26] feat(SearchVideos): Modify Lightbox to pause the prev video when moving to next one, preventing interference with new video. --- ui/components/SearchVideos.tsx | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/ui/components/SearchVideos.tsx b/ui/components/SearchVideos.tsx index 2d820ef..170df61 100644 --- a/ui/components/SearchVideos.tsx +++ b/ui/components/SearchVideos.tsx @@ -1,6 +1,6 @@ /* eslint-disable @next/next/no-img-element */ import { PlayCircle, PlayIcon, PlusIcon, VideoIcon } from 'lucide-react'; -import { useState } from 'react'; +import { useRef, useState } from 'react'; import Lightbox, { GenericSlide, VideoSlide } from 'yet-another-react-lightbox'; import 'yet-another-react-lightbox/styles.css'; import { Message } from './ChatWindow'; @@ -35,6 +35,8 @@ const Searchvideos = ({ const [loading, setLoading] = useState(false); const [open, setOpen] = useState(false); const [slides, setSlides] = useState([]); + const [currentIndex, setCurrentIndex] = useState(0); + const videoRefs = useRef<(HTMLIFrameElement | null)[]>([]); return ( <> @@ -182,18 +184,39 @@ const Searchvideos = ({ open={open} close={() => setOpen(false)} slides={slides} + index={currentIndex} + on={{ + view: ({ index }) => { + const previousIframe = videoRefs.current[currentIndex]; + if (previousIframe?.contentWindow) { + previousIframe.contentWindow.postMessage( + '{"event":"command","func":"pauseVideo","args":""}', + '*', + ); + } + + setCurrentIndex(index); + }, + }} render={{ - slide: ({ slide }) => - slide.type === 'video-slide' ? ( + slide: ({ slide }) => { + const index = slides.findIndex((s) => s === slide); + return slide.type === 'video-slide' ? (