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

@ -19,8 +19,15 @@ const createAssistant = async (req, res) => {
try {
const { openai } = await getOpenAIClient({ req, res });
const { tools = [], endpoint, conversation_starters, ...assistantData } = req.body;
const {
tools = [],
endpoint,
conversation_starters,
append_current_datetime,
...assistantData
} = req.body;
delete assistantData.conversation_starters;
delete assistantData.append_current_datetime;
assistantData.tools = tools
.map((tool) => {
@ -49,6 +56,9 @@ const createAssistant = async (req, res) => {
if (conversation_starters) {
createData.conversation_starters = conversation_starters;
}
if (append_current_datetime !== undefined) {
createData.append_current_datetime = append_current_datetime;
}
const document = await updateAssistantDoc({ assistant_id: assistant.id }, createData);
@ -60,6 +70,10 @@ const createAssistant = async (req, res) => {
assistant.conversation_starters = document.conversation_starters;
}
if (append_current_datetime !== undefined) {
assistant.append_current_datetime = append_current_datetime;
}
logger.debug('/assistants/', assistant);
res.status(201).json(assistant);
} catch (error) {
@ -102,7 +116,12 @@ const patchAssistant = async (req, res) => {
await validateAuthor({ req, openai });
const assistant_id = req.params.id;
const { endpoint: _e, conversation_starters, ...updateData } = req.body;
const {
endpoint: _e,
conversation_starters,
append_current_datetime,
...updateData
} = req.body;
updateData.tools = (updateData.tools ?? [])
.map((tool) => {
if (typeof tool !== 'string') {
@ -127,6 +146,11 @@ const patchAssistant = async (req, res) => {
updatedAssistant.conversation_starters = conversationStartersUpdate.conversation_starters;
}
if (append_current_datetime !== undefined) {
await updateAssistantDoc({ assistant_id }, { append_current_datetime });
updatedAssistant.append_current_datetime = append_current_datetime;
}
res.json(updatedAssistant);
} catch (error) {
logger.error('[/assistants/:id] Error updating assistant', error);
@ -219,6 +243,7 @@ const getAssistantDocuments = async (req, res) => {
conversation_starters: 1,
createdAt: 1,
updatedAt: 1,
append_current_datetime: 1,
},
);