fix(balance/models): request only when authenticated, modelsQuery "optimistic" update (#1031)

* fix(balanceQuery/modelsQuery): request only when authenticated

* style: match new chat capitalization to official

* fix(modelsQuery): update selected model optimistically

* ci: update e2e changes, disable title in ci env

* fix(ci): get new chat button by data-testid and not text
This commit is contained in:
Danny Avila 2023-10-09 15:10:23 -04:00 committed by GitHub
parent 2dd545eaa4
commit b3aac97710
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 34 additions and 15 deletions

View file

@ -1,6 +1,12 @@
import { useCallback } from 'react';
import { useSetRecoilState, useResetRecoilState, useRecoilCallback, useRecoilValue } from 'recoil';
import { TConversation, TMessagesAtom, TSubmission, TPreset } from 'librechat-data-provider';
import type {
TConversation,
TMessagesAtom,
TSubmission,
TPreset,
TModelsConfig,
} from 'librechat-data-provider';
import { buildDefaultConvo, getDefaultEndpoint } from '~/utils';
import store from '~/store';
@ -17,8 +23,9 @@ const useConversation = () => {
conversation: TConversation,
messages: TMessagesAtom = null,
preset: TPreset | null = null,
modelsData?: TModelsConfig,
) => {
const modelsConfig = snapshot.getLoadable(store.modelsConfig).contents;
const modelsConfig = modelsData ?? snapshot.getLoadable(store.modelsConfig).contents;
const { endpoint = null } = conversation;
if (endpoint === null) {
@ -45,7 +52,7 @@ const useConversation = () => {
);
const newConversation = useCallback(
(template = {}, preset?: TPreset) => {
(template = {}, preset?: TPreset, modelsData?: TModelsConfig) => {
switchToConversation(
{
conversationId: 'new',
@ -57,6 +64,7 @@ const useConversation = () => {
},
[],
preset,
modelsData,
);
},
[switchToConversation],

View file

@ -29,11 +29,13 @@ export default function useServerStream(submission: TSubmission | null) {
const setIsSubmitting = useSetRecoilState(store.isSubmitting);
const setConversation = useSetRecoilState(store.conversation);
const resetLatestMessage = useResetRecoilState(store.latestMessage);
const { token } = useAuthContext();
const { token, isAuthenticated } = useAuthContext();
const { data: startupConfig } = useGetStartupConfig();
const { refreshConversations } = useConversations();
const balanceQuery = useGetUserBalance();
const balanceQuery = useGetUserBalance({
enabled: !!isAuthenticated && startupConfig?.checkBalance,
});
const messageHandler = (data: string, submission: TSubmission) => {
const {