diff --git a/src/app/api/chat/route.ts b/src/app/api/chat/route.ts index d48fbb6..e566edb 100644 --- a/src/app/api/chat/route.ts +++ b/src/app/api/chat/route.ts @@ -49,6 +49,7 @@ type Body = { files: Array; chatModel: ChatModel; embeddingModel: EmbeddingModel; + systemInstructions: string; }; const handleEmitterEvents = async ( @@ -278,6 +279,7 @@ export const POST = async (req: Request) => { embedding, body.optimizationMode, body.files, + body.systemInstructions, ); const responseStream = new TransformStream(); diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts index d3e98ca..59d84ff 100644 --- a/src/app/api/search/route.ts +++ b/src/app/api/search/route.ts @@ -125,6 +125,7 @@ export const POST = async (req: Request) => { embeddings, body.optimizationMode, [], + "", ); if (!body.stream) { diff --git a/src/lib/prompts/academicSearch.ts b/src/lib/prompts/academicSearch.ts index c2946ff..d015910 100644 --- a/src/lib/prompts/academicSearch.ts +++ b/src/lib/prompts/academicSearch.ts @@ -51,6 +51,10 @@ export const academicSearchResponsePrompt = ` - 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. + ### User instructions + These instructions are shared to you by the user and not by the system. You will have to follow them but give them less priority than the above instructions. If the user has provided specific instructions or preferences, incorporate them into your response while adhering to the overall guidelines. + {systemInstructions} + ### 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. diff --git a/src/lib/prompts/redditSearch.ts b/src/lib/prompts/redditSearch.ts index fc71957..577fa82 100644 --- a/src/lib/prompts/redditSearch.ts +++ b/src/lib/prompts/redditSearch.ts @@ -51,6 +51,10 @@ export const redditSearchResponsePrompt = ` - 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. + ### User instructions + These instructions are shared to you by the user and not by the system. You will have to follow them but give them less priority than the above instructions. If the user has provided specific instructions or preferences, incorporate them into your response while adhering to the overall guidelines. + {systemInstructions} + ### 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. diff --git a/src/lib/prompts/webSearch.ts b/src/lib/prompts/webSearch.ts index d8269c8..c1b458b 100644 --- a/src/lib/prompts/webSearch.ts +++ b/src/lib/prompts/webSearch.ts @@ -92,6 +92,10 @@ export const webSearchResponsePrompt = ` - 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. + ### User instructions + These instructions are shared to you by the user and not by the system. You will have to follow them but give them less priority than the above instructions. If the user has provided specific instructions or preferences, incorporate them into your response while adhering to the overall guidelines. + {systemInstructions} + ### 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. diff --git a/src/lib/prompts/wolframAlpha.ts b/src/lib/prompts/wolframAlpha.ts index 40410c1..63145dd 100644 --- a/src/lib/prompts/wolframAlpha.ts +++ b/src/lib/prompts/wolframAlpha.ts @@ -51,6 +51,10 @@ export const wolframAlphaSearchResponsePrompt = ` - 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. + ### User instructions + These instructions are shared to you by the user and not by the system. You will have to follow them but give them less priority than the above instructions. If the user has provided specific instructions or preferences, incorporate them into your response while adhering to the overall guidelines. + {systemInstructions} + ### 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. diff --git a/src/lib/prompts/writingAssistant.ts b/src/lib/prompts/writingAssistant.ts index f56bf47..565827a 100644 --- a/src/lib/prompts/writingAssistant.ts +++ b/src/lib/prompts/writingAssistant.ts @@ -7,6 +7,10 @@ You have to cite the answer using [number] notation. You must cite the sentences 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. +### User instructions +These instructions are shared to you by the user and not by the system. You will have to follow them but give them less priority than the above instructions. If the user has provided specific instructions or preferences, incorporate them into your response while adhering to the overall guidelines. +{systemInstructions} + {context} diff --git a/src/lib/prompts/youtubeSearch.ts b/src/lib/prompts/youtubeSearch.ts index 5805b54..9898016 100644 --- a/src/lib/prompts/youtubeSearch.ts +++ b/src/lib/prompts/youtubeSearch.ts @@ -51,6 +51,10 @@ export const youtubeSearchResponsePrompt = ` - 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 + ### User instructions + These instructions are shared to you by the user and not by the system. You will have to follow them but give them less priority than the above instructions. If the user has provided specific instructions or preferences, incorporate them into your response while adhering to the overall guidelines. + {systemInstructions} + ### 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. diff --git a/src/lib/search/metaSearchAgent.ts b/src/lib/search/metaSearchAgent.ts index 4a3d817..67b7c58 100644 --- a/src/lib/search/metaSearchAgent.ts +++ b/src/lib/search/metaSearchAgent.ts @@ -33,6 +33,7 @@ export interface MetaSearchAgentType { embeddings: Embeddings, optimizationMode: 'speed' | 'balanced' | 'quality', fileIds: string[], + systemInstructions: string, ) => Promise; } @@ -236,9 +237,11 @@ class MetaSearchAgent implements MetaSearchAgentType { fileIds: string[], embeddings: Embeddings, optimizationMode: 'speed' | 'balanced' | 'quality', + systemInstructions: string, ) { return RunnableSequence.from([ RunnableMap.from({ + systemInstructions: () => systemInstructions, query: (input: BasicChainInput) => input.query, chat_history: (input: BasicChainInput) => input.chat_history, date: () => new Date().toISOString(), @@ -468,6 +471,7 @@ class MetaSearchAgent implements MetaSearchAgentType { embeddings: Embeddings, optimizationMode: 'speed' | 'balanced' | 'quality', fileIds: string[], + systemInstructions: string, ) { const emitter = new eventEmitter(); @@ -476,6 +480,7 @@ class MetaSearchAgent implements MetaSearchAgentType { fileIds, embeddings, optimizationMode, + systemInstructions, ); const stream = answeringChain.streamEvents(