diff --git a/README.md b/README.md
index cf9e459..4df7aeb 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,6 @@
[](https://discord.gg/26aArMy8tT)
-

## Table of Contents
diff --git a/src/prompts/index.ts b/src/prompts/index.ts
index f479185..90bd738 100644
--- a/src/prompts/index.ts
+++ b/src/prompts/index.ts
@@ -6,7 +6,11 @@ import {
redditSearchResponsePrompt,
redditSearchRetrieverPrompt,
} from './redditSearch';
-import { webSearchResponsePrompt, webSearchRetrieverPrompt } from './webSearch';
+import {
+ webSearchResponsePrompt,
+ webSearchRetrieverPrompt,
+ preciseWebSearchResponsePrompt,
+} from './webSearch';
import {
wolframAlphaSearchResponsePrompt,
wolframAlphaSearchRetrieverPrompt,
@@ -20,6 +24,7 @@ import {
export default {
webSearchResponsePrompt,
webSearchRetrieverPrompt,
+ preciseWebSearchResponsePrompt,
academicSearchResponsePrompt,
academicSearchRetrieverPrompt,
redditSearchResponsePrompt,
diff --git a/src/prompts/webSearch.ts b/src/prompts/webSearch.ts
index d8269c8..d0123c0 100644
--- a/src/prompts/webSearch.ts
+++ b/src/prompts/webSearch.ts
@@ -104,3 +104,41 @@ export const webSearchResponsePrompt = `
Current date & time in ISO format (UTC timezone) is: {date}.
`;
+
+export const preciseWebSearchResponsePrompt = `
+ You are Perplexica, an AI model skilled in web search and crafting accurate, concise, and well-structured answers. You excel at breaking down long form content into brief summaries or specific answers.
+
+ Your task is to provide answers that are:
+ - **Informative and relevant**: Precisely 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.
+ - **Cited and credible**: Use inline citations with [number] notation to refer to the context source(s) for each fact or detail included.
+ - **Brief and Accurate**: If a direct answer is available, provide it succinctly without unnecessary elaboration.
+
+ ### Formatting Instructions
+ - **Structure**: Use a well-organized format with proper headings. Present information in paragraphs or concise bullet points where appropriate. You should never need more than one heading.
+ - **Tone and Style**: Maintain a matter-of-fact tone and focus on delivering accurate information. Avoid overly complex language or unnecessary jargon.
+ - **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**: Be brief. Provide concise answers. Avoid superficial responses and strive for accuracy without unnecessary repetition.
+ - **No main heading/title**: Start your response directly with the introduction unless asked to provide a specific title.
+ - **Conclusion or Summary**: Do not include a conclusion unless the context specifically requires it.
+
+ ### 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 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.
+ - Do not provide additional commentary or personal opinions unless specifically asked for in the context.
+ - Do not include plesantries or greetings in your response.
+
+
+ {context}
+
+
+ Current date & time in ISO format (UTC timezone) is: {date}.
+`;
diff --git a/src/search/metaSearchAgent.ts b/src/search/metaSearchAgent.ts
index ee82c10..2e414fe 100644
--- a/src/search/metaSearchAgent.ts
+++ b/src/search/metaSearchAgent.ts
@@ -34,6 +34,7 @@ export interface MetaSearchAgentType {
embeddings: Embeddings,
optimizationMode: 'speed' | 'balanced' | 'quality',
fileIds: string[],
+ isCompact?: boolean,
) => Promise;
}
@@ -44,6 +45,7 @@ interface Config {
rerankThreshold: number;
queryGeneratorPrompt: string;
responsePrompt: string;
+ preciseResponsePrompt: string;
activeEngines: string[];
}
@@ -235,6 +237,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
fileIds: string[],
embeddings: Embeddings,
optimizationMode: 'speed' | 'balanced' | 'quality',
+ isCompact?: boolean,
) {
return RunnableSequence.from([
RunnableMap.from({
@@ -278,7 +281,12 @@ class MetaSearchAgent implements MetaSearchAgentType {
.pipe(this.processDocs),
}),
ChatPromptTemplate.fromMessages([
- ['system', this.config.responsePrompt],
+ [
+ 'system',
+ isCompact
+ ? this.config.preciseResponsePrompt
+ : this.config.responsePrompt,
+ ],
new MessagesPlaceholder('chat_history'),
['user', '{query}'],
]),
@@ -465,6 +473,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
embeddings: Embeddings,
optimizationMode: 'speed' | 'balanced' | 'quality',
fileIds: string[],
+ isCompact?: boolean,
) {
const emitter = new eventEmitter();
@@ -473,6 +482,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
fileIds,
embeddings,
optimizationMode,
+ isCompact,
);
const stream = answeringChain.streamEvents(
diff --git a/src/websocket/messageHandler.ts b/src/websocket/messageHandler.ts
index 395c0de..99b3eaf 100644
--- a/src/websocket/messageHandler.ts
+++ b/src/websocket/messageHandler.ts
@@ -26,6 +26,7 @@ type WSMessage = {
focusMode: string;
history: Array<[string, string]>;
files: Array;
+ isCompact?: boolean;
};
export const searchHandlers = {
@@ -33,6 +34,7 @@ export const searchHandlers = {
activeEngines: [],
queryGeneratorPrompt: prompts.webSearchRetrieverPrompt,
responsePrompt: prompts.webSearchResponsePrompt,
+ preciseResponsePrompt: prompts.preciseWebSearchResponsePrompt,
rerank: true,
rerankThreshold: 0.3,
searchWeb: true,
@@ -42,6 +44,7 @@ export const searchHandlers = {
activeEngines: ['arxiv', 'google scholar', 'pubmed'],
queryGeneratorPrompt: prompts.academicSearchRetrieverPrompt,
responsePrompt: prompts.academicSearchResponsePrompt,
+ preciseResponsePrompt: prompts.preciseWebSearchResponsePrompt,
rerank: true,
rerankThreshold: 0,
searchWeb: true,
@@ -51,6 +54,7 @@ export const searchHandlers = {
activeEngines: [],
queryGeneratorPrompt: '',
responsePrompt: prompts.writingAssistantPrompt,
+ preciseResponsePrompt: prompts.preciseWebSearchResponsePrompt,
rerank: true,
rerankThreshold: 0,
searchWeb: false,
@@ -60,6 +64,7 @@ export const searchHandlers = {
activeEngines: ['wolframalpha'],
queryGeneratorPrompt: prompts.wolframAlphaSearchRetrieverPrompt,
responsePrompt: prompts.wolframAlphaSearchResponsePrompt,
+ preciseResponsePrompt: prompts.preciseWebSearchResponsePrompt,
rerank: false,
rerankThreshold: 0,
searchWeb: true,
@@ -69,6 +74,7 @@ export const searchHandlers = {
activeEngines: ['youtube'],
queryGeneratorPrompt: prompts.youtubeSearchRetrieverPrompt,
responsePrompt: prompts.youtubeSearchResponsePrompt,
+ preciseResponsePrompt: prompts.preciseWebSearchResponsePrompt,
rerank: true,
rerankThreshold: 0.3,
searchWeb: true,
@@ -78,6 +84,7 @@ export const searchHandlers = {
activeEngines: ['reddit'],
queryGeneratorPrompt: prompts.redditSearchRetrieverPrompt,
responsePrompt: prompts.redditSearchResponsePrompt,
+ preciseResponsePrompt: prompts.preciseWebSearchResponsePrompt,
rerank: true,
rerankThreshold: 0.3,
searchWeb: true,
@@ -116,6 +123,7 @@ const handleEmitterEvents = (
sources = parsedData.data;
}
});
+
emitter.on('end', () => {
ws.send(JSON.stringify({ type: 'messageEnd', messageId: messageId }));
@@ -132,6 +140,7 @@ const handleEmitterEvents = (
})
.execute();
});
+
emitter.on('error', (data) => {
const parsedData = JSON.parse(data);
ws.send(
@@ -197,6 +206,7 @@ export const handleMessage = async (
embeddings,
parsedWSMessage.optimizationMode,
parsedWSMessage.files,
+ parsedWSMessage.isCompact,
);
handleEmitterEvents(emitter, ws, aiMessageId, parsedMessage.chatId);
diff --git a/ui/components/Chat.tsx b/ui/components/Chat.tsx
index 81aa32f..3d4cf6b 100644
--- a/ui/components/Chat.tsx
+++ b/ui/components/Chat.tsx
@@ -16,9 +16,17 @@ const Chat = ({
setFileIds,
files,
setFiles,
+ isCompact,
+ setIsCompact,
+ optimizationMode,
+ setOptimizationMode,
}: {
messages: Message[];
- sendMessage: (message: string) => void;
+ sendMessage: (
+ message: string,
+ messageId?: string,
+ options?: { isCompact?: boolean },
+ ) => void;
loading: boolean;
messageAppeared: boolean;
rewrite: (messageId: string) => void;
@@ -26,6 +34,10 @@ const Chat = ({
setFileIds: (fileIds: string[]) => void;
files: File[];
setFiles: (files: File[]) => void;
+ isCompact: boolean;
+ setIsCompact: (isCompact: boolean) => void;
+ optimizationMode: string;
+ setOptimizationMode: (mode: string) => void;
}) => {
const [dividerWidth, setDividerWidth] = useState(0);
const dividerRef = useRef(null);
@@ -71,6 +83,7 @@ const Chat = ({
dividerRef={isLast ? dividerRef : undefined}
isLast={isLast}
rewrite={rewrite}
+ isCompact={isCompact}
sendMessage={sendMessage}
/>
{!isLast && msg.role === 'assistant' && (
@@ -83,7 +96,7 @@ const Chat = ({
{dividerWidth > 0 && (