🔧 fix: Improve Assistants File Citation & Download Handling (#2248)

* fix(processMessages): properly handle assistant file citations and add sources list

* feat: improve file download UX by making any downloaded files accessible within the app post-download

* refactor(processOpenAIImageOutput): correctly handle two different outputs for images since OpenAI generates a file in their storage, shares filepath for image rendering

* refactor: create `addFileToCache` helper to use across frontend

* refactor: add ImageFile parts to cache on processing content stream
This commit is contained in:
Danny Avila 2024-03-29 19:09:16 -04:00 committed by GitHub
parent bc2a628902
commit 6a6b2e79b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 142 additions and 57 deletions

View file

@ -21,7 +21,7 @@ import type {
TEndpointsConfig,
TCheckUserKeyResponse,
} from 'librechat-data-provider';
import { findPageForConversation } from '~/utils';
import { findPageForConversation, addFileToCache } from '~/utils';
export const useGetFiles = <TData = TFile[] | boolean>(
config?: UseQueryOptions<TFile[], unknown, TData>,
@ -326,15 +326,29 @@ export const useGetAssistantDocsQuery = (
};
export const useFileDownload = (userId: string, filepath: string): QueryObserverResult<string> => {
const queryClient = useQueryClient();
return useQuery(
[QueryKeys.fileDownload, filepath],
async () => {
if (!userId) {
console.warn('No user ID provided for file download');
}
const blob = await dataService.getFileDownload(userId, filepath);
const downloadUrl = window.URL.createObjectURL(blob);
return downloadUrl;
const response = await dataService.getFileDownload(userId, filepath);
const blob = response.data;
const downloadURL = window.URL.createObjectURL(blob);
try {
const metadata: TFile | undefined = JSON.parse(response.headers['x-file-metadata']);
if (!metadata) {
console.warn('No metadata found for file download', response.headers);
return downloadURL;
}
addFileToCache(queryClient, metadata);
} catch (e) {
console.error('Error parsing file metadata, skipped updating file query cache', e);
}
return downloadURL;
},
{
enabled: false,