🔧 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

@ -6,6 +6,7 @@ import * as t from './types';
import * as s from './schemas';
import request from './request';
import * as endpoints from './api-endpoints';
import type { AxiosResponse } from 'axios';
export function abortRequestWithMessage(
endpoint: string,
@ -201,9 +202,9 @@ export const uploadAssistantAvatar = (data: m.AssistantAvatarVariables): Promise
);
};
export const getFileDownload = async (userId: string, filepath: string): Promise<Blob> => {
export const getFileDownload = async (userId: string, filepath: string): Promise<AxiosResponse> => {
const encodedFilePath = encodeURIComponent(filepath);
return request.get(`${endpoints.files()}/download/${userId}/${encodedFilePath}`, {
return request.getResponse(`${endpoints.files()}/download/${userId}/${encodedFilePath}`, {
responseType: 'blob',
});
};

View file

@ -8,6 +8,10 @@ async function _get<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
return response.data;
}
async function _getResponse<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
return await axios.get(url, { ...options });
}
async function _post(url: string, data?: any) {
const response = await axios.post(url, JSON.stringify(data), {
headers: { 'Content-Type': 'application/json' },
@ -114,6 +118,7 @@ axios.interceptors.response.use(
export default {
get: _get,
getResponse: _getResponse,
post: _post,
postMultiPart: _postMultiPart,
put: _put,

View file

@ -1,4 +1,5 @@
import type { OpenAPIV3 } from 'openapi-types';
import type { TFile } from './files';
export type Schema = OpenAPIV3.SchemaObject & { description?: string };
export type Reference = OpenAPIV3.ReferenceObject & { description?: string };
@ -131,7 +132,7 @@ export type ToolCallsStepDetails = {
type: 'tool_calls'; // Always 'tool_calls'.
};
export type ImageFile = {
export type ImageFile = TFile & {
/**
* The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
* in the message content.
@ -267,6 +268,8 @@ export type TContentData = StreamContentData & {
export const actionDelimiter = '_action_';
export const actionDomainSeparator = '---';
export const hostImageIdSuffix = '_host_copy';
export const hostImageNamePrefix = 'host_copy_';
export enum AuthTypeEnum {
ServiceHttp = 'service_http',