Skip to content

Commit

Permalink
fix: general fixes after rebasing due to file changes from danny-avil…
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila committed Jan 30, 2024
1 parent 9b7d66e commit c4b62fc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/server/services/AssistantService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
RunStatus,
ToolCallTypes,
} = require('librechat-data-provider');
const { imageRegex, retrieveAndProcessFile } = require('~/server/services/Files');
const { imageRegex, retrieveAndProcessFile } = require('~/server/services/Files/process');
const { RunManager, waitForRun } = require('~/server/services/Runs');
const { processActions } = require('~/server/services/ToolService');
const { createOnProgress, sendMessage } = require('~/server/utils');
Expand Down
2 changes: 1 addition & 1 deletion api/server/services/Files/images/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function convertToWebP(req, file, resolution = 'high', basename = '') {
} = await resizeImageBuffer(inputBuffer, resolution);

const extension = path.extname(file.path ?? basename); // Default extension if input is a buffer
const { imageOutput } = req.app.locals.config;
const { imageOutput } = req.app.locals.paths;
const userPath = path.join(imageOutput, req.user.id);

if (!fs.existsSync(userPath)) {
Expand Down
2 changes: 2 additions & 0 deletions api/server/services/Files/images/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const avatar = require('./avatar');
const convert = require('./convert');
const encode = require('./encode');
const parse = require('./parse');
const resize = require('./resize');
const validate = require('./validate');

module.exports = {
...convert,
...encode,
...parse,
...resize,
Expand Down
9 changes: 6 additions & 3 deletions api/server/services/Files/process.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const path = require('path');
const mime = require('mime/lite');
const { isEnabled } = require('~/server/utils');
const { createFile, updateFileUsage } = require('~/models');
const { FileSources } = require('librechat-data-provider');
const { convertToWebP } = require('~/server/services/Files/images');
const { createFile, updateFileUsage } = require('~/models/File');
const { isEnabled } = require('~/server/utils');

const imageRegex = /\.(jpg|jpeg|png|gif|webp)$/i;

Expand Down Expand Up @@ -90,7 +91,7 @@ const processImageUpload = async ({ req, res, file, metadata }) => {
};

/**
* Retrieves and processes a file based on its type.
* Retrieves and processes an OpenAI file based on its type.
*
* @param {Object} params - The params passed to the function.
* @param {OpenAIClient} params.openai - The params passed to the function.
Expand All @@ -116,6 +117,7 @@ async function retrieveAndProcessFile({ openai, file_id, basename: _basename, un
filepath,
usage: 1,
file_id,
source: FileSources.openai,
};

if (save) {
Expand Down Expand Up @@ -153,6 +155,7 @@ async function retrieveAndProcessFile({ openai, file_id, basename: _basename, un
type: 'image/webp',
usage: 1,
file_id,
source: FileSources.openai,
};
createFile(file, true);
return file;
Expand Down
12 changes: 9 additions & 3 deletions client/src/components/Chat/AssistantsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { useParams } from 'react-router-dom';
import { useGetMessagesByConvoId } from 'librechat-data-provider/react-query';
import { useChatHelpers, useSSE } from '~/hooks';
import MessagesView from './Messages/MessagesView';
import { useGetFiles } from '~/data-provider';
import { buildTree, mapFiles } from '~/utils';
import CreationPanel from './CreationPanel';
import { ChatContext } from '~/Providers';
import Presentation from './Presentation';
import ChatForm from './Input/ChatForm';
import { Spinner } from '~/components';
import { buildTree } from '~/utils';
import Landing from './Landing';
import Header from './Header';
import Footer from './Footer';
Expand All @@ -20,11 +21,16 @@ function ChatView({ index = 0 }: { index?: number }) {
const submissionAtIndex = useRecoilValue(store.submissionByIndex(0));
useSSE(submissionAtIndex);

const { data: fileMap } = useGetFiles({
select: mapFiles,
});

const { data: messagesTree = null, isLoading } = useGetMessagesByConvoId(conversationId ?? '', {
select: (data) => {
const dataTree = buildTree(data, false);
const dataTree = buildTree({ messages: data, fileMap });
return dataTree?.length === 0 ? null : dataTree ?? null;
},
enabled: !!fileMap,
});

const chatHelpers = useChatHelpers(index, conversationId);
Expand All @@ -41,7 +47,7 @@ function ChatView({ index = 0 }: { index?: number }) {
) : (
<Landing Header={<Header />} />
)}
<div className="w-full border-t-0 pl-0 pt-2 dark:border-white/20 md:w-[calc(100%-.5rem)] md:border-t-0 md:border-transparent md:pl-0 md:pt-0 md:dark:border-transparent">
<div className="w-full border-t-0 pl-0 pt-2 md:w-[calc(100%-.5rem)] md:border-t-0 md:border-transparent md:pl-0 md:pt-0 dark:border-white/20 md:dark:border-transparent">
<ChatForm index={index} />
<Footer />
</div>
Expand Down
41 changes: 34 additions & 7 deletions client/src/routes/AssistantsRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,64 @@
import { useRecoilValue } from 'recoil';
import { useEffect, useRef } from 'react';
import { useParams } from 'react-router-dom';
import { useGetConvoIdQuery, useGetModelsQuery } from 'librechat-data-provider/react-query';
import {
useGetConvoIdQuery,
useGetModelsQuery,
useGetEndpointsQuery,
} from 'librechat-data-provider/react-query';
import type { TPreset } from 'librechat-data-provider';
import { useNewConvo, useConfigOverride } from '~/hooks';
import AssistantsView from '~/components/Chat/AssistantsView';
import useAuthRedirect from './useAuthRedirect';
import { useNewConvo } from '~/hooks';
import { Spinner } from '~/components/svg';
import store from '~/store';

export default function AssistantsRoute() {
export default function ChatRoute() {
const index = 0;

useConfigOverride();
const { conversationId } = useParams();
const { conversation } = store.useCreateConversationAtom(index);
const modelsQueryEnabled = useRecoilValue(store.modelsQueryEnabled);
const { isAuthenticated } = useAuthRedirect();
const { newConversation } = useNewConvo();
const hasSetConversation = useRef(false);

const modelsQuery = useGetModelsQuery({ enabled: isAuthenticated });
const modelsQuery = useGetModelsQuery({ enabled: isAuthenticated && modelsQueryEnabled });
const initialConvoQuery = useGetConvoIdQuery(conversationId ?? '', {
enabled: isAuthenticated && conversationId !== 'new',
});
const endpointsQuery = useGetEndpointsQuery({ enabled: isAuthenticated && modelsQueryEnabled });

useEffect(() => {
if (conversationId === 'new' && modelsQuery.data && !hasSetConversation.current) {
if (
conversationId === 'new' &&
endpointsQuery.data &&
modelsQuery.data &&
!hasSetConversation.current
) {
newConversation({ modelsData: modelsQuery.data });
hasSetConversation.current = true;
} else if (initialConvoQuery.data && modelsQuery.data && !hasSetConversation.current) {
} else if (
initialConvoQuery.data &&
endpointsQuery.data &&
modelsQuery.data &&
!hasSetConversation.current
) {
newConversation({
template: initialConvoQuery.data,
/* this is necessary to load all existing settings */
preset: initialConvoQuery.data as TPreset,
modelsData: modelsQuery.data,
});
hasSetConversation.current = true;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [initialConvoQuery.data, modelsQuery.data]);
}, [initialConvoQuery.data, modelsQuery.data, endpointsQuery.data]);

if (endpointsQuery.isLoading || modelsQuery.isLoading) {
return <Spinner className="m-auto dark:text-white" />;
}

if (!isAuthenticated) {
return null;
Expand Down

0 comments on commit c4b62fc

Please sign in to comment.