mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-23 20:00:15 +01:00
⌚ feat: Add Current Datetime to Assistants (v1/v2) (#4952)
* Feature: Added ability to send current date and time to v1 and v2 assistants * remove date_feature.patch * fix: rename append_today_date to append_current_datetime * feat: Refactor time handling in chatV1 and chatV2, add date and time utility functions * fix: Add warning log and response for missing run values in abortRun middleware --------- Co-authored-by: Max Sanna <max@maxsanna.com>
This commit is contained in:
parent
b5c9144127
commit
1dbe6ee75d
38 changed files with 378 additions and 67 deletions
|
|
@ -0,0 +1,76 @@
|
|||
import { Control, Controller, UseFormSetValue, UseFormGetValues } from 'react-hook-form';
|
||||
import { CircleHelpIcon } from '~/components/svg';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import {
|
||||
HoverCard,
|
||||
HoverCardContent,
|
||||
HoverCardPortal,
|
||||
HoverCardTrigger,
|
||||
Checkbox,
|
||||
} from '~/components/ui';
|
||||
import { ESide } from '~/common';
|
||||
import type { AssistantForm } from '~/common';
|
||||
|
||||
interface AppendDateCheckboxProps {
|
||||
control: Control<AssistantForm>;
|
||||
setValue: UseFormSetValue<AssistantForm>;
|
||||
getValues: UseFormGetValues<AssistantForm>;
|
||||
}
|
||||
|
||||
export default function AppendDateCheckbox({ control, setValue }: AppendDateCheckboxProps) {
|
||||
const localize = useLocalize();
|
||||
|
||||
const handleChange = (checked: boolean) => {
|
||||
setValue('append_current_datetime', checked, {
|
||||
shouldDirty: true,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mb-6">
|
||||
<HoverCard openDelay={50}>
|
||||
<div className="flex items-center">
|
||||
<Controller
|
||||
name="append_current_datetime"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Checkbox
|
||||
{...field}
|
||||
id="append_current_datetime"
|
||||
checked={field.value}
|
||||
onCheckedChange={handleChange}
|
||||
className="relative float-left mr-2 inline-flex h-4 w-4 cursor-pointer"
|
||||
value={field.value.toString()}
|
||||
aria-labelledby="append-date-label"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<div className="flex items-center space-x-2">
|
||||
<label
|
||||
id="append-date-label"
|
||||
htmlFor="append_current_datetime"
|
||||
className="form-check-label text-token-text-primary w-full cursor-pointer"
|
||||
>
|
||||
{localize('com_assistants_append_date')}
|
||||
</label>
|
||||
<HoverCardTrigger>
|
||||
<CircleHelpIcon
|
||||
className="h-5 w-5 text-gray-500"
|
||||
aria-label={localize('com_assistants_append_date_tooltip')}
|
||||
/>
|
||||
</HoverCardTrigger>
|
||||
</div>
|
||||
<HoverCardPortal>
|
||||
<HoverCardContent side={ESide.Top} className="w-80">
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm text-gray-600 dark:text-gray-300">
|
||||
{localize('com_assistants_append_date_tooltip')}
|
||||
</p>
|
||||
</div>
|
||||
</HoverCardContent>
|
||||
</HoverCardPortal>
|
||||
</div>
|
||||
</HoverCard>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ import { useAssistantsMapContext, useToastContext } from '~/Providers';
|
|||
import { useSelectAssistant, useLocalize } from '~/hooks';
|
||||
import { ToolSelectDialog } from '~/components/Tools';
|
||||
import CapabilitiesForm from './CapabilitiesForm';
|
||||
import AppendDateCheckbox from './AppendDateCheckbox';
|
||||
import { SelectDropDown } from '~/components/ui';
|
||||
import AssistantAvatar from './AssistantAvatar';
|
||||
import AssistantSelect from './AssistantSelect';
|
||||
|
|
@ -63,7 +64,7 @@ export default function AssistantPanel({
|
|||
|
||||
const [showToolDialog, setShowToolDialog] = useState(false);
|
||||
|
||||
const { control, handleSubmit, reset } = methods;
|
||||
const { control, handleSubmit, reset, setValue, getValues } = methods;
|
||||
const assistant = useWatch({ control, name: 'assistant' });
|
||||
const functions = useWatch({ control, name: 'functions' });
|
||||
const assistant_id = useWatch({ control, name: 'id' });
|
||||
|
|
@ -167,7 +168,7 @@ export default function AssistantPanel({
|
|||
instructions,
|
||||
conversation_starters: starters,
|
||||
model,
|
||||
// file_ids, // TODO: add file handling here
|
||||
append_current_datetime,
|
||||
} = data;
|
||||
|
||||
if (assistant_id) {
|
||||
|
|
@ -181,6 +182,7 @@ export default function AssistantPanel({
|
|||
model,
|
||||
tools,
|
||||
endpoint,
|
||||
append_current_datetime,
|
||||
},
|
||||
});
|
||||
return;
|
||||
|
|
@ -195,6 +197,7 @@ export default function AssistantPanel({
|
|||
tools,
|
||||
endpoint,
|
||||
version,
|
||||
append_current_datetime,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -325,6 +328,9 @@ export default function AssistantPanel({
|
|||
/>
|
||||
</div>
|
||||
|
||||
{/* Append Today's Date */}
|
||||
<AppendDateCheckbox control={control} setValue={setValue} getValues={getValues} />
|
||||
|
||||
{/* Conversation Starters */}
|
||||
<div className="relative mb-6">
|
||||
{/* the label of conversation starters is in the component */}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Plus } from 'lucide-react';
|
||||
import { useCallback, useEffect, useRef, useMemo } from 'react';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import {
|
||||
Tools,
|
||||
FileSources,
|
||||
|
|
@ -37,6 +37,7 @@ const keys = new Set([
|
|||
'instructions',
|
||||
'conversation_starters',
|
||||
'model',
|
||||
'append_current_datetime',
|
||||
]);
|
||||
|
||||
export default function AssistantSelect({
|
||||
|
|
@ -69,7 +70,7 @@ export default function AssistantSelect({
|
|||
res.data.map((_assistant) => {
|
||||
const source =
|
||||
endpoint === EModelEndpoint.assistants ? FileSources.openai : FileSources.azure;
|
||||
const assistant = {
|
||||
const assistant: TAssistantOption = {
|
||||
..._assistant,
|
||||
label: _assistant.name ?? '',
|
||||
value: _assistant.id,
|
||||
|
|
@ -125,8 +126,11 @@ export default function AssistantSelect({
|
|||
|
||||
const assistantDoc = documentsMap?.get(_assistant.id);
|
||||
/* If no user updates, use the latest assistant docs */
|
||||
if (assistantDoc && !assistant.conversation_starters) {
|
||||
assistant.conversation_starters = assistantDoc.conversation_starters;
|
||||
if (assistantDoc) {
|
||||
if (!assistant.conversation_starters) {
|
||||
assistant.conversation_starters = assistantDoc.conversation_starters;
|
||||
}
|
||||
assistant.append_current_datetime = assistantDoc.append_current_datetime ?? false;
|
||||
}
|
||||
|
||||
return assistant;
|
||||
|
|
@ -184,6 +188,11 @@ export default function AssistantSelect({
|
|||
return;
|
||||
}
|
||||
|
||||
if (name === 'append_current_datetime') {
|
||||
formValues[name] = !!value;
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
name === 'conversation_starters' &&
|
||||
Array.isArray(value) &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue