feat(prompt): Use date, not time in prompts

This commit is contained in:
Willie Zutz 2025-05-26 11:05:11 -06:00
parent 4edd173207
commit 8e6934bb64
12 changed files with 34 additions and 18 deletions

View file

@ -244,7 +244,7 @@ const Page = () => {
}; };
fetchConfig(); fetchConfig();
}, []); });
const saveConfig = async (key: string, value: any) => { const saveConfig = async (key: string, value: any) => {
setSavingStates((prev) => ({ ...prev, [key]: true })); setSavingStates((prev) => ({ ...prev, [key]: true }));

View file

@ -304,7 +304,7 @@ const ChatWindow = ({ id }: { id?: string }) => {
} else { } else {
localStorage.setItem('optimizationMode', optimizationMode); localStorage.setItem('optimizationMode', optimizationMode);
} }
}, []); }, [optimizationMode]);
useEffect(() => { useEffect(() => {
if ( if (

View file

@ -17,7 +17,7 @@ import {
Volume2, Volume2,
} from 'lucide-react'; } from 'lucide-react';
import Markdown, { MarkdownToJSX } from 'markdown-to-jsx'; 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 { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { oneDark } from 'react-syntax-highlighter/dist/cjs/styles/prism'; import { oneDark } from 'react-syntax-highlighter/dist/cjs/styles/prism';
import { useSpeech } from 'react-text-to-speech'; import { useSpeech } from 'react-text-to-speech';
@ -145,7 +145,7 @@ const MessageTabs = ({
}; };
// Load suggestions handling // Load suggestions handling
const handleLoadSuggestions = async () => { const handleLoadSuggestions = useCallback(async () => {
if ( if (
loadingSuggestions || loadingSuggestions ||
(message?.suggestions && message.suggestions.length > 0) (message?.suggestions && message.suggestions.length > 0)
@ -162,7 +162,7 @@ const MessageTabs = ({
} finally { } finally {
setLoadingSuggestions(false); setLoadingSuggestions(false);
} }
}; }, [loadingSuggestions, message, chatHistory, sendMessage]);
// Process message content // Process message content
useEffect(() => { useEffect(() => {
@ -234,7 +234,7 @@ const MessageTabs = ({
) { ) {
handleLoadSuggestions(); handleLoadSuggestions();
} }
}, [isLast, loading, message.role]); }, [isLast, loading, message.role, handleLoadSuggestions]);
// Markdown formatting options // Markdown formatting options
const markdownOverrides: MarkdownToJSX.Options = { const markdownOverrides: MarkdownToJSX.Options = {

View file

@ -8,6 +8,7 @@ import formatChatHistoryAsString from '../utils/formatHistory';
import { BaseMessage } from '@langchain/core/messages'; import { BaseMessage } from '@langchain/core/messages';
import LineOutputParser from '../outputParsers/lineOutputParser'; import LineOutputParser from '../outputParsers/lineOutputParser';
import { searchSearxng } from '../searxng'; import { searchSearxng } from '../searxng';
import { formatDateForLLM } from '../utils';
import type { BaseChatModel } from '@langchain/core/language_models/chat_models'; import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
const imageSearchChainPrompt = ` const imageSearchChainPrompt = `
@ -23,7 +24,7 @@ const imageSearchChainPrompt = `
- The history is contained in the <conversation> tag after the <examples> below - The history is contained in the <conversation> tag after the <examples> below
- The user question is contained in the <question> tag after the <examples> below - The user question is contained in the <question> tag after the <examples> below
- Output your answer in an <answer> tag - Output your answer in an <answer> tag
- Current date & time in ISO format (UTC timezone) is: {date} - Current date is: {date}
- Do not include any other text in your answer - Do not include any other text in your answer
<examples> <examples>
@ -99,7 +100,7 @@ const createImageSearchChain = (llm: BaseChatModel) => {
query: (input: ImageSearchChainInput) => { query: (input: ImageSearchChainInput) => {
return input.query; return input.query;
}, },
date: () => new Date().toISOString(), date: () => formatDateForLLM(),
}), }),
PromptTemplate.fromTemplate(imageSearchChainPrompt), PromptTemplate.fromTemplate(imageSearchChainPrompt),
llm, llm,

View file

@ -8,6 +8,7 @@ import formatChatHistoryAsString from '../utils/formatHistory';
import { BaseMessage } from '@langchain/core/messages'; import { BaseMessage } from '@langchain/core/messages';
import LineOutputParser from '../outputParsers/lineOutputParser'; import LineOutputParser from '../outputParsers/lineOutputParser';
import { searchSearxng } from '../searxng'; import { searchSearxng } from '../searxng';
import { formatDateForLLM } from '../utils';
import type { BaseChatModel } from '@langchain/core/language_models/chat_models'; import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
const VideoSearchChainPrompt = ` const VideoSearchChainPrompt = `
@ -23,7 +24,7 @@ const VideoSearchChainPrompt = `
- The history is contained in the <conversation> tag after the <examples> below - The history is contained in the <conversation> tag after the <examples> below
- The user question is contained in the <question> tag after the <examples> below - The user question is contained in the <question> tag after the <examples> below
- Output your answer in an <answer> tag - Output your answer in an <answer> tag
- Current date & time in ISO format (UTC timezone) is: {date} - Current date is: {date}
- Do not include any other text in your answer - Do not include any other text in your answer
<examples> <examples>
@ -100,7 +101,7 @@ const createVideoSearchChain = (llm: BaseChatModel) => {
query: (input: VideoSearchChainInput) => { query: (input: VideoSearchChainInput) => {
return input.query; return input.query;
}, },
date: () => new Date().toISOString(), date: () => formatDateForLLM(),
}), }),
PromptTemplate.fromTemplate(VideoSearchChainPrompt), PromptTemplate.fromTemplate(VideoSearchChainPrompt),
llm, llm,

View file

@ -65,5 +65,5 @@ export const academicSearchResponsePrompt = `
{context} {context}
</context> </context>
Current date & time in ISO format (UTC timezone) is: {date}. Current date is: {date}.
`; `;

View file

@ -65,5 +65,5 @@ export const redditSearchResponsePrompt = `
{context} {context}
</context> </context>
Current date & time in ISO format (UTC timezone) is: {date}. Current date is: {date}.
`; `;

View file

@ -19,7 +19,7 @@ export const webSearchRetrieverPrompt = `
- The history is contained in the <conversation> tag after the <examples> below - The history is contained in the <conversation> tag after the <examples> below
- The user question is contained in the <question> tag after the <examples> below - The user question is contained in the <question> tag after the <examples> below
- You must always return the rephrased question inside an <answer> XML block, if there are no links in the follow-up question then don't insert a <links> XML block in your response - You must always return the rephrased question inside an <answer> XML block, if there are no links in the follow-up question then don't insert a <links> 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 - Do not include any other text in your answer
There are several examples attached for your reference inside the below examples XML block There are several examples attached for your reference inside the below examples XML block
@ -212,5 +212,5 @@ export const webSearchResponsePrompt = `
{context} {context}
</context> </context>
Current date & time in ISO format (UTC timezone) is: {date}. Current date is: {date}.
`; `;

View file

@ -65,5 +65,5 @@ export const wolframAlphaSearchResponsePrompt = `
{context} {context}
</context> </context>
Current date & time in ISO format (UTC timezone) is: {date}. Current date is: {date}.
`; `;

View file

@ -65,5 +65,5 @@ export const youtubeSearchResponsePrompt = `
{context} {context}
</context> </context>
Current date & time in ISO format (UTC timezone) is: {date}. Current date is: {date}.
`; `;

View file

@ -29,6 +29,7 @@ import {
} from '../utils/documents'; } from '../utils/documents';
import formatChatHistoryAsString from '../utils/formatHistory'; import formatChatHistoryAsString from '../utils/formatHistory';
import { getModelName } from '../utils/modelUtils'; import { getModelName } from '../utils/modelUtils';
import { formatDateForLLM } from '../utils';
export interface MetaSearchAgentType { export interface MetaSearchAgentType {
searchAndAnswer: ( searchAndAnswer: (
@ -309,7 +310,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
systemInstructions: () => systemInstructions, systemInstructions: () => systemInstructions,
query: (input: BasicChainInput) => input.query, query: (input: BasicChainInput) => input.query,
chat_history: (input: BasicChainInput) => input.chat_history, chat_history: (input: BasicChainInput) => input.chat_history,
date: () => new Date().toISOString(), date: () => formatDateForLLM(),
context: RunnableLambda.from( context: RunnableLambda.from(
async ( async (
input: BasicChainInput, input: BasicChainInput,
@ -331,7 +332,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
if (this.config.searchWeb) { if (this.config.searchWeb) {
const searchRetrieverChain = const searchRetrieverChain =
await this.createSearchRetrieverChain(llm, emitter); await this.createSearchRetrieverChain(llm, emitter);
var date = new Date().toISOString(); var date = formatDateForLLM();
const searchRetrieverResult = await searchRetrieverChain.invoke( const searchRetrieverResult = await searchRetrieverChain.invoke(
{ {

View file

@ -25,3 +25,16 @@ export const formatTimeDifference = (
else else
return `${Math.floor(diffInSeconds / 31536000)} year${Math.floor(diffInSeconds / 31536000) !== 1 ? 's' : ''}`; 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',
});
};