Skip to content

Commit

Permalink
🔀 fix: Address Convo/Preset Switching Issues (danny-avila#2709)
Browse files Browse the repository at this point in the history
* fix(schemas): interchangeability between chatGptLabel <> modelLabel

* fix: display error message from enforceModelSpecs when conversation already existed

* fix(Mention): use activeIndex on mention tab/enter

* fix: correctly navigate to new conversation when deleting/archiving a new, active convo
  • Loading branch information
danny-avila authored May 14, 2024
1 parent 0049192 commit b8e184d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 51 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Chat/Input/Mention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function Mention({
} else if (e.key === 'ArrowUp') {
setActiveIndex((prevIndex) => (prevIndex - 1 + matches.length) % matches.length);
} else if (e.key === 'Enter' || e.key === 'Tab') {
const mentionOption = matches[0] as MentionOption | undefined;
const mentionOption = matches[activeIndex] as MentionOption | undefined;
if (mentionOption?.type === 'endpoint') {
e.preventDefault();
} else if (e.key === 'Enter') {
Expand Down
16 changes: 8 additions & 8 deletions client/src/components/Conversations/ArchiveButton.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '~/components/ui';
import { useParams, useNavigate } from 'react-router-dom';
import type { MouseEvent, FocusEvent, KeyboardEvent } from 'react';
import { useParams } from 'react-router-dom';

import { useArchiveConversationMutation } from '~/data-provider';

import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '~/components/ui';
import { useConversations, useLocalize, useNewConvo } from '~/hooks';
import { useToastContext } from '~/Providers';
import { useArchiveConversationMutation } from '~/data-provider';
import { NotificationSeverity } from '~/common';
import { useToastContext } from '~/Providers';

type ArchiveButtonProps = {
conversationId: string;
Expand All @@ -23,8 +21,9 @@ export default function ArchiveButton({
className = '',
}: ArchiveButtonProps) {
const localize = useLocalize();
const { newConversation } = useNewConvo();
const navigate = useNavigate();
const { showToast } = useToastContext();
const { newConversation } = useNewConvo();
const { refreshConversations } = useConversations();
const { conversationId: currentConvoId } = useParams();

Expand All @@ -42,8 +41,9 @@ export default function ArchiveButton({
{ conversationId, isArchived: shouldArchive },
{
onSuccess: () => {
if (currentConvoId === conversationId) {
if (currentConvoId === conversationId || currentConvoId === 'new') {
newConversation();
navigate('/c/new', { replace: true });
}
refreshConversations();
retainView();
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/Conversations/DeleteButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react';
import { useParams } from 'react-router-dom';
import { QueryKeys } from 'librechat-data-provider';
import { useQueryClient } from '@tanstack/react-query';
import { useParams, useNavigate } from 'react-router-dom';
import type { TMessage } from 'librechat-data-provider';
import { useDeleteConversationMutation } from '~/data-provider';
import {
Expand All @@ -26,13 +26,15 @@ export default function DeleteButton({
className = '',
}) {
const localize = useLocalize();
const navigate = useNavigate();
const queryClient = useQueryClient();
const { newConversation } = useNewConvo();
const { conversationId: currentConvoId } = useParams();
const deleteConvoMutation = useDeleteConversationMutation({
onSuccess: () => {
if (currentConvoId === conversationId) {
if (currentConvoId === conversationId || currentConvoId === 'new') {
newConversation();
navigate('/c/new', { replace: true });
}
retainView();
},
Expand Down
5 changes: 5 additions & 0 deletions client/src/hooks/SSE/useSSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
});
setIsSubmitting(false);
return;
} else if (!data.conversationId) {
const errorResponse = parseErrorResponse(data);
setMessages([...messages, message, errorResponse]);
setIsSubmitting(false);
return;
}

console.log('Error:', data);
Expand Down
96 changes: 56 additions & 40 deletions packages/data-provider/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,25 +400,33 @@ export const openAISchema = tConversationSchema
maxContextTokens: true,
max_tokens: true,
})
.transform((obj) => ({
...obj,
model: obj.model ?? openAISettings.model.default,
chatGptLabel: obj.modelLabel ?? obj.chatGptLabel ?? null,
promptPrefix: obj.promptPrefix ?? null,
temperature: obj.temperature ?? openAISettings.temperature.default,
top_p: obj.top_p ?? openAISettings.top_p.default,
presence_penalty: obj.presence_penalty ?? openAISettings.presence_penalty.default,
frequency_penalty: obj.frequency_penalty ?? openAISettings.frequency_penalty.default,
resendFiles:
typeof obj.resendFiles === 'boolean' ? obj.resendFiles : openAISettings.resendFiles.default,
imageDetail: obj.imageDetail ?? openAISettings.imageDetail.default,
stop: obj.stop ?? undefined,
iconURL: obj.iconURL ?? undefined,
greeting: obj.greeting ?? undefined,
spec: obj.spec ?? undefined,
maxContextTokens: obj.maxContextTokens ?? undefined,
max_tokens: obj.max_tokens ?? undefined,
}))
.transform((obj) => {
const result = {
...obj,
model: obj.model ?? openAISettings.model.default,
chatGptLabel: obj.chatGptLabel ?? obj.modelLabel ?? null,
promptPrefix: obj.promptPrefix ?? null,
temperature: obj.temperature ?? openAISettings.temperature.default,
top_p: obj.top_p ?? openAISettings.top_p.default,
presence_penalty: obj.presence_penalty ?? openAISettings.presence_penalty.default,
frequency_penalty: obj.frequency_penalty ?? openAISettings.frequency_penalty.default,
resendFiles:
typeof obj.resendFiles === 'boolean' ? obj.resendFiles : openAISettings.resendFiles.default,
imageDetail: obj.imageDetail ?? openAISettings.imageDetail.default,
stop: obj.stop ?? undefined,
iconURL: obj.iconURL ?? undefined,
greeting: obj.greeting ?? undefined,
spec: obj.spec ?? undefined,
maxContextTokens: obj.maxContextTokens ?? undefined,
max_tokens: obj.max_tokens ?? undefined,
};

if (obj.modelLabel) {
result.modelLabel = null;
}

return result;
})
.catch(() => ({
model: openAISettings.model.default,
chatGptLabel: null,
Expand Down Expand Up @@ -605,27 +613,35 @@ export const gptPluginsSchema = tConversationSchema
spec: true,
maxContextTokens: true,
})
.transform((obj) => ({
...obj,
model: obj.model ?? 'gpt-3.5-turbo',
chatGptLabel: obj.modelLabel ?? obj.chatGptLabel ?? null,
promptPrefix: obj.promptPrefix ?? null,
temperature: obj.temperature ?? 0.8,
top_p: obj.top_p ?? 1,
presence_penalty: obj.presence_penalty ?? 0,
frequency_penalty: obj.frequency_penalty ?? 0,
tools: obj.tools ?? [],
agentOptions: obj.agentOptions ?? {
agent: EAgent.functions,
skipCompletion: true,
model: 'gpt-3.5-turbo',
temperature: 0,
},
iconURL: obj.iconURL ?? undefined,
greeting: obj.greeting ?? undefined,
spec: obj.spec ?? undefined,
maxContextTokens: obj.maxContextTokens ?? undefined,
}))
.transform((obj) => {
const result = {
...obj,
model: obj.model ?? 'gpt-3.5-turbo',
chatGptLabel: obj.chatGptLabel ?? obj.modelLabel ?? null,
promptPrefix: obj.promptPrefix ?? null,
temperature: obj.temperature ?? 0.8,
top_p: obj.top_p ?? 1,
presence_penalty: obj.presence_penalty ?? 0,
frequency_penalty: obj.frequency_penalty ?? 0,
tools: obj.tools ?? [],
agentOptions: obj.agentOptions ?? {
agent: EAgent.functions,
skipCompletion: true,
model: 'gpt-3.5-turbo',
temperature: 0,
},
iconURL: obj.iconURL ?? undefined,
greeting: obj.greeting ?? undefined,
spec: obj.spec ?? undefined,
maxContextTokens: obj.maxContextTokens ?? undefined,
};

if (obj.modelLabel) {
result.modelLabel = null;
}

return result;
})
.catch(() => ({
model: 'gpt-3.5-turbo',
chatGptLabel: null,
Expand Down

0 comments on commit b8e184d

Please sign in to comment.