diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx index f4fdbdb..9bee38f 100644 --- a/src/app/settings/page.tsx +++ b/src/app/settings/page.tsx @@ -244,7 +244,7 @@ const Page = () => { }; fetchConfig(); - }, []); + }); const saveConfig = async (key: string, value: any) => { setSavingStates((prev) => ({ ...prev, [key]: true })); diff --git a/src/components/ChatWindow.tsx b/src/components/ChatWindow.tsx index a1f6077..98d5d7a 100644 --- a/src/components/ChatWindow.tsx +++ b/src/components/ChatWindow.tsx @@ -304,7 +304,7 @@ const ChatWindow = ({ id }: { id?: string }) => { } else { localStorage.setItem('optimizationMode', optimizationMode); } - }, []); + }, [optimizationMode]); useEffect(() => { if ( diff --git a/src/components/MessageTabs.tsx b/src/components/MessageTabs.tsx index c07a6f4..0fe32be 100644 --- a/src/components/MessageTabs.tsx +++ b/src/components/MessageTabs.tsx @@ -17,7 +17,7 @@ import { Volume2, } from 'lucide-react'; import Markdown, { MarkdownToJSX } from 'markdown-to-jsx'; -import { useEffect, useState } from 'react'; +import { useCallback, useEffect, useState } from 'react'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { oneDark } from 'react-syntax-highlighter/dist/cjs/styles/prism'; import { useSpeech } from 'react-text-to-speech'; @@ -145,7 +145,7 @@ const MessageTabs = ({ }; // Load suggestions handling - const handleLoadSuggestions = async () => { + const handleLoadSuggestions = useCallback(async () => { if ( loadingSuggestions || (message?.suggestions && message.suggestions.length > 0) @@ -162,7 +162,7 @@ const MessageTabs = ({ } finally { setLoadingSuggestions(false); } - }; + }, [loadingSuggestions, message, chatHistory, sendMessage]); // Process message content useEffect(() => { @@ -234,7 +234,7 @@ const MessageTabs = ({ ) { handleLoadSuggestions(); } - }, [isLast, loading, message.role]); + }, [isLast, loading, message.role, handleLoadSuggestions]); // Markdown formatting options const markdownOverrides: MarkdownToJSX.Options = { diff --git a/src/lib/chains/imageSearchAgent.ts b/src/lib/chains/imageSearchAgent.ts index b1dd8af..f84c591 100644 --- a/src/lib/chains/imageSearchAgent.ts +++ b/src/lib/chains/imageSearchAgent.ts @@ -8,6 +8,7 @@ import formatChatHistoryAsString from '../utils/formatHistory'; import { BaseMessage } from '@langchain/core/messages'; import LineOutputParser from '../outputParsers/lineOutputParser'; import { searchSearxng } from '../searxng'; +import { formatDateForLLM } from '../utils'; import type { BaseChatModel } from '@langchain/core/language_models/chat_models'; const imageSearchChainPrompt = ` @@ -23,7 +24,7 @@ const imageSearchChainPrompt = ` - The history is contained in the tag after the below - The user question is contained in the tag after the below - Output your answer in an tag -- Current date & time in ISO format (UTC timezone) is: {date} +- Current date is: {date} - Do not include any other text in your answer @@ -99,7 +100,7 @@ const createImageSearchChain = (llm: BaseChatModel) => { query: (input: ImageSearchChainInput) => { return input.query; }, - date: () => new Date().toISOString(), + date: () => formatDateForLLM(), }), PromptTemplate.fromTemplate(imageSearchChainPrompt), llm, diff --git a/src/lib/chains/videoSearchAgent.ts b/src/lib/chains/videoSearchAgent.ts index 5e63ad6..3e794b1 100644 --- a/src/lib/chains/videoSearchAgent.ts +++ b/src/lib/chains/videoSearchAgent.ts @@ -8,6 +8,7 @@ import formatChatHistoryAsString from '../utils/formatHistory'; import { BaseMessage } from '@langchain/core/messages'; import LineOutputParser from '../outputParsers/lineOutputParser'; import { searchSearxng } from '../searxng'; +import { formatDateForLLM } from '../utils'; import type { BaseChatModel } from '@langchain/core/language_models/chat_models'; const VideoSearchChainPrompt = ` @@ -23,7 +24,7 @@ const VideoSearchChainPrompt = ` - The history is contained in the tag after the below - The user question is contained in the tag after the below - Output your answer in an tag -- Current date & time in ISO format (UTC timezone) is: {date} +- Current date is: {date} - Do not include any other text in your answer @@ -100,7 +101,7 @@ const createVideoSearchChain = (llm: BaseChatModel) => { query: (input: VideoSearchChainInput) => { return input.query; }, - date: () => new Date().toISOString(), + date: () => formatDateForLLM(), }), PromptTemplate.fromTemplate(VideoSearchChainPrompt), llm, diff --git a/src/lib/prompts/academicSearch.ts b/src/lib/prompts/academicSearch.ts index d015910..691dae3 100644 --- a/src/lib/prompts/academicSearch.ts +++ b/src/lib/prompts/academicSearch.ts @@ -65,5 +65,5 @@ export const academicSearchResponsePrompt = ` {context} - Current date & time in ISO format (UTC timezone) is: {date}. + Current date is: {date}. `; diff --git a/src/lib/prompts/redditSearch.ts b/src/lib/prompts/redditSearch.ts index 577fa82..0967022 100644 --- a/src/lib/prompts/redditSearch.ts +++ b/src/lib/prompts/redditSearch.ts @@ -65,5 +65,5 @@ export const redditSearchResponsePrompt = ` {context} - Current date & time in ISO format (UTC timezone) is: {date}. + Current date is: {date}. `; diff --git a/src/lib/prompts/webSearch.ts b/src/lib/prompts/webSearch.ts index 3eb44f5..298a7bf 100644 --- a/src/lib/prompts/webSearch.ts +++ b/src/lib/prompts/webSearch.ts @@ -19,7 +19,7 @@ export const webSearchRetrieverPrompt = ` - The history is contained in the tag after the below - The user question is contained in the tag after the below - You must always return the rephrased question inside an XML block, if there are no links in the follow-up question then don't insert a XML block in your response -- Current date & time in ISO format (UTC timezone) is: {date} +- Current date is: {date} - Do not include any other text in your answer There are several examples attached for your reference inside the below examples XML block @@ -212,5 +212,5 @@ export const webSearchResponsePrompt = ` {context} - Current date & time in ISO format (UTC timezone) is: {date}. + Current date is: {date}. `; diff --git a/src/lib/prompts/wolframAlpha.ts b/src/lib/prompts/wolframAlpha.ts index 63145dd..eaa3367 100644 --- a/src/lib/prompts/wolframAlpha.ts +++ b/src/lib/prompts/wolframAlpha.ts @@ -65,5 +65,5 @@ export const wolframAlphaSearchResponsePrompt = ` {context} - Current date & time in ISO format (UTC timezone) is: {date}. + Current date is: {date}. `; diff --git a/src/lib/prompts/youtubeSearch.ts b/src/lib/prompts/youtubeSearch.ts index 9898016..9856d39 100644 --- a/src/lib/prompts/youtubeSearch.ts +++ b/src/lib/prompts/youtubeSearch.ts @@ -65,5 +65,5 @@ export const youtubeSearchResponsePrompt = ` {context} - Current date & time in ISO format (UTC timezone) is: {date}. + Current date is: {date}. `; diff --git a/src/lib/search/metaSearchAgent.ts b/src/lib/search/metaSearchAgent.ts index 318415d..79356b6 100644 --- a/src/lib/search/metaSearchAgent.ts +++ b/src/lib/search/metaSearchAgent.ts @@ -29,6 +29,7 @@ import { } from '../utils/documents'; import formatChatHistoryAsString from '../utils/formatHistory'; import { getModelName } from '../utils/modelUtils'; +import { formatDateForLLM } from '../utils'; export interface MetaSearchAgentType { searchAndAnswer: ( @@ -309,7 +310,7 @@ class MetaSearchAgent implements MetaSearchAgentType { systemInstructions: () => systemInstructions, query: (input: BasicChainInput) => input.query, chat_history: (input: BasicChainInput) => input.chat_history, - date: () => new Date().toISOString(), + date: () => formatDateForLLM(), context: RunnableLambda.from( async ( input: BasicChainInput, @@ -331,7 +332,7 @@ class MetaSearchAgent implements MetaSearchAgentType { if (this.config.searchWeb) { const searchRetrieverChain = await this.createSearchRetrieverChain(llm, emitter); - var date = new Date().toISOString(); + var date = formatDateForLLM(); const searchRetrieverResult = await searchRetrieverChain.invoke( { diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 30d6da5..0b18188 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -25,3 +25,16 @@ export const formatTimeDifference = ( else return `${Math.floor(diffInSeconds / 31536000)} year${Math.floor(diffInSeconds / 31536000) !== 1 ? 's' : ''}`; }; + +/** + * Format a date for LLM prompts to only include month, day, and year + * @param date - The date to format (defaults to current date) + * @returns Formatted date string in "Month DD, YYYY" format + */ +export const formatDateForLLM = (date: Date = new Date()): string => { + return date.toLocaleDateString('en-US', { + year: 'numeric', + month: 'long', + day: 'numeric', + }); +};