mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-11 20:14:24 +01:00
💽 refactor(client): Optimize ModelsConfig Query Cache (#2330)
* refactor(client): remove double caching of models via recoil to rely exclusively on react-query * chore(useConversation): add modelsQuery.data dep to callback
This commit is contained in:
parent
fb80af05be
commit
f6a84887e1
11 changed files with 76 additions and 94 deletions
|
|
@ -3,6 +3,7 @@ import { z } from 'zod';
|
|||
import { EModelEndpoint, eModelEndpointSchema } from './schemas';
|
||||
import { fileConfigSchema } from './file-config';
|
||||
import { FileSources } from './types/files';
|
||||
import { TModelsConfig } from './types';
|
||||
|
||||
export const defaultSocialLogins = ['google', 'facebook', 'openid', 'github', 'discord'];
|
||||
|
||||
|
|
@ -332,6 +333,24 @@ export const defaultModels = {
|
|||
],
|
||||
};
|
||||
|
||||
const fitlerAssistantModels = (str: string) => {
|
||||
return /gpt-4|gpt-3\\.5/i.test(str) && !/vision|instruct/i.test(str);
|
||||
};
|
||||
|
||||
const openAIModels = defaultModels[EModelEndpoint.openAI];
|
||||
|
||||
export const initialModelsConfig: TModelsConfig = {
|
||||
initial: [],
|
||||
[EModelEndpoint.openAI]: openAIModels,
|
||||
[EModelEndpoint.assistants]: openAIModels.filter(fitlerAssistantModels),
|
||||
[EModelEndpoint.gptPlugins]: openAIModels,
|
||||
[EModelEndpoint.azureOpenAI]: openAIModels,
|
||||
[EModelEndpoint.bingAI]: ['BingAI', 'Sydney'],
|
||||
[EModelEndpoint.chatGPTBrowser]: ['text-davinci-002-render-sha'],
|
||||
[EModelEndpoint.google]: defaultModels[EModelEndpoint.google],
|
||||
[EModelEndpoint.anthropic]: defaultModels[EModelEndpoint.anthropic],
|
||||
};
|
||||
|
||||
export const EndpointURLs: { [key in EModelEndpoint]: string } = {
|
||||
[EModelEndpoint.openAI]: `/api/ask/${EModelEndpoint.openAI}`,
|
||||
[EModelEndpoint.bingAI]: `/api/ask/${EModelEndpoint.bingAI}`,
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ import {
|
|||
UseMutationResult,
|
||||
QueryObserverResult,
|
||||
} from '@tanstack/react-query';
|
||||
import * as t from '../types';
|
||||
import * as s from '../schemas';
|
||||
import * as m from '../types/mutations';
|
||||
import { defaultOrderQuery } from '../config';
|
||||
import { defaultOrderQuery, initialModelsConfig } from '../config';
|
||||
import * as dataService from '../data-service';
|
||||
import request from '../request';
|
||||
import * as m from '../types/mutations';
|
||||
import { QueryKeys } from '../keys';
|
||||
import request from '../request';
|
||||
import * as s from '../schemas';
|
||||
import * as t from '../types';
|
||||
|
||||
export const useAbortRequestWithMessage = (): UseMutationResult<
|
||||
void,
|
||||
|
|
@ -211,10 +211,11 @@ export const useGetModelsQuery = (
|
|||
config?: UseQueryOptions<t.TModelsConfig>,
|
||||
): QueryObserverResult<t.TModelsConfig> => {
|
||||
return useQuery<t.TModelsConfig>([QueryKeys.models], () => dataService.getModels(), {
|
||||
staleTime: Infinity,
|
||||
initialData: initialModelsConfig,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
staleTime: Infinity,
|
||||
...config,
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue