🧪 feat: Experimental: Enable Switching Endpoints Mid-Conversation (#1483)

* fix: load all existing conversation settings on refresh

* refactor(buildDefaultConvo): use `lastConversationSetup.endpointType` before `conversation.endpointType`

* refactor(TMessage/messageSchema): add `endpoint` field to messages to differentiate generation origin

* feat(useNewConvo): `keepLatestMessage` param to prevent reseting the `latestMessage` mid-conversation

* style(Settings): adjust height styling to allow more space in dialog for additional settings

* feat: Modular Chat: experimental setting to Enable switching Endpoints mid-conversation

* fix(ChatRoute): fix potential parsing issue with tPresetSchema
This commit is contained in:
Danny Avila 2024-01-03 19:17:42 -05:00 committed by GitHub
parent 4befee829b
commit e1a529b5ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 129 additions and 26 deletions

View file

@ -1,11 +1,11 @@
import { QueryKeys, modularEndpoints } from 'librechat-data-provider';
import { useCreatePresetMutation } from 'librechat-data-provider/react-query';
import filenamify from 'filenamify';
import { useCallback, useEffect, useRef } from 'react';
import { useRecoilState, useSetRecoilState } from 'recoil';
import exportFromJSON from 'export-from-json';
import { useCallback, useEffect, useRef } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import type { TPreset } from 'librechat-data-provider';
import { QueryKeys, modularEndpoints } from 'librechat-data-provider';
import { useRecoilState, useSetRecoilState, useRecoilValue } from 'recoil';
import { useCreatePresetMutation } from 'librechat-data-provider/react-query';
import type { TPreset, TEndpointsConfig } from 'librechat-data-provider';
import {
useUpdatePresetMutation,
useDeletePresetMutation,
@ -27,6 +27,7 @@ export default function usePresets() {
const { showToast } = useToastContext();
const { user, isAuthenticated } = useAuthContext();
const modularChat = useRecoilValue(store.modularChat);
const [_defaultPreset, setDefaultPreset] = useRecoilState(store.defaultPreset);
const setPresetModalVisible = useSetRecoilState(store.presetModalVisible);
const { preset, conversation, newConversation, setPreset } = useChatContext();
@ -159,14 +160,20 @@ export default function usePresets() {
duration: 750,
});
const endpointsConfig = queryClient.getQueryData<TEndpointsConfig>([QueryKeys.endpoints]);
const currentEndpointType = endpointsConfig?.[endpoint ?? '']?.type ?? '';
const endpointType = endpointsConfig?.[newPreset?.endpoint ?? '']?.type;
if (
modularEndpoints.has(endpoint ?? '') &&
modularEndpoints.has(newPreset?.endpoint ?? '') &&
endpoint === newPreset?.endpoint
(modularEndpoints.has(endpoint ?? '') || modularEndpoints.has(currentEndpointType)) &&
(modularEndpoints.has(newPreset?.endpoint ?? '') || modularEndpoints.has(endpointType)) &&
(endpoint === newPreset?.endpoint || modularChat)
) {
const currentConvo = getDefaultConversation({
conversation: conversation ?? {},
preset: newPreset,
/* target endpointType is necessary to avoid endpoint mixing */
conversation: { ...(conversation ?? {}), endpointType },
preset: { ...newPreset, endpointType },
});
/* We don't reset the latest message, only when changing settings mid-converstion */