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();
}, []);
});
const saveConfig = async (key: string, value: any) => {
setSavingStates((prev) => ({ ...prev, [key]: true }));

View file

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

View file

@ -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 = {

View file

@ -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 <conversation> 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
- Current date & time in ISO format (UTC timezone) is: {date}
- Current date is: {date}
- Do not include any other text in your answer
<examples>
@ -99,7 +100,7 @@ const createImageSearchChain = (llm: BaseChatModel) => {
query: (input: ImageSearchChainInput) => {
return input.query;
},
date: () => new Date().toISOString(),
date: () => formatDateForLLM(),
}),
PromptTemplate.fromTemplate(imageSearchChainPrompt),
llm,

View file

@ -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 <conversation> 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
- Current date & time in ISO format (UTC timezone) is: {date}
- Current date is: {date}
- Do not include any other text in your answer
<examples>
@ -100,7 +101,7 @@ const createVideoSearchChain = (llm: BaseChatModel) => {
query: (input: VideoSearchChainInput) => {
return input.query;
},
date: () => new Date().toISOString(),
date: () => formatDateForLLM(),
}),
PromptTemplate.fromTemplate(VideoSearchChainPrompt),
llm,

View file

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

View file

@ -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(
{

View file

@ -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',
});
};