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:
Danny Avila 2024-12-11 15:26:18 -05:00 committed by GitHub
parent b5c9144127
commit 1dbe6ee75d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 378 additions and 67 deletions

View file

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