Skip to content

Commit

Permalink
🔧 fix: Allow Azure Assistants Chats to be Deleted (#3893)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-diez authored Oct 29, 2024
1 parent 2b0654b commit f270455
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
16 changes: 11 additions & 5 deletions api/server/routes/convos.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const multer = require('multer');
const express = require('express');
const { CacheKeys } = require('librechat-data-provider');
const { initializeClient } = require('~/server/services/Endpoints/assistants');
const { CacheKeys, EModelEndpoint } = require('librechat-data-provider');
const { getConvosByPage, deleteConvos, getConvo, saveConvo } = require('~/models/Conversation');
const { storage, importFileFilter } = require('~/server/routes/files/multer');
const requireJwtAuth = require('~/server/middleware/requireJwtAuth');
Expand All @@ -11,6 +10,10 @@ const { createImportLimiters } = require('~/server/middleware');
const getLogStores = require('~/cache/getLogStores');
const { sleep } = require('~/server/utils');
const { logger } = require('~/config');
const assistantClients = {
[EModelEndpoint.azureAssistants]: require('~/server/services/Endpoints/azureAssistants'),
[EModelEndpoint.assistants]: require('~/server/services/Endpoints/assistants'),
};

const router = express.Router();
router.use(requireJwtAuth);
Expand Down Expand Up @@ -74,7 +77,7 @@ router.post('/gen_title', async (req, res) => {

router.post('/clear', async (req, res) => {
let filter = {};
const { conversationId, source, thread_id } = req.body.arg;
const { conversationId, source, thread_id, endpoint } = req.body.arg;
if (conversationId) {
filter = { conversationId };
}
Expand All @@ -83,9 +86,12 @@ router.post('/clear', async (req, res) => {
return res.status(200).send('No conversationId provided');
}

if (thread_id) {
if (
typeof endpoint != 'undefined' &&
Object.prototype.propertyIsEnumerable.call(assistantClients, endpoint)
) {
/** @type {{ openai: OpenAI}} */
const { openai } = await initializeClient({ req, res });
const { openai } = await assistantClients[endpoint].initializeClient({ req, res });
try {
const response = await openai.beta.threads.del(thread_id);
logger.debug('Deleted OpenAI thread:', response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ export function DeleteConversationDialog({
const confirmDelete = useCallback(() => {
const messages = queryClient.getQueryData<TMessage[]>([QueryKeys.messages, conversationId]);
const thread_id = messages?.[messages.length - 1]?.thread_id;
const endpoint = messages?.[messages.length - 1]?.endpoint;

deleteConvoMutation.mutate({ conversationId, thread_id, source: 'button' });
deleteConvoMutation.mutate({ conversationId, thread_id, endpoint, source: 'button' });
}, [conversationId, deleteConvoMutation, queryClient]);

return (
Expand Down
1 change: 1 addition & 0 deletions packages/data-provider/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export type TUpdateConversationResponse = TConversation;
export type TDeleteConversationRequest = {
conversationId?: string;
thread_id?: string;
endpoint?: string;
source?: string;
};

Expand Down

0 comments on commit f270455

Please sign in to comment.