mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-26 13:18:51 +01:00
🔧 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:
parent
bc2a628902
commit
6a6b2e79b0
11 changed files with 142 additions and 57 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue