🔧 refactor: Reduce Complexity of Initial Load Effect & Message Styling (#3213)

* move shared conditions and early bail to reduce cognitive complexity, improve readability

* refactor: make condition as close to the original as possible

* chore: adjust comment in chat route

* style: fix original styling of non-multi messages

* refactor: separate messagerender logic from 'Message'

---------

Co-authored-by: RehaS <beratson@gmail.com>
This commit is contained in:
Danny Avila 2024-06-27 10:48:41 -04:00 committed by GitHub
parent 791b0139bc
commit ed5ee1f86f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 179 additions and 181 deletions

View file

@ -38,14 +38,14 @@ export default function ChatRoute() {
const assistantListMap = useAssistantListMap();
useEffect(() => {
if (
startupConfig &&
conversationId === 'new' &&
endpointsQuery.data &&
modelsQuery.data &&
!modelsQuery.data?.initial &&
!hasSetConversation.current
) {
const shouldSetConvo =
startupConfig && !hasSetConversation.current && !modelsQuery.data?.initial;
/* Early exit if startupConfig is not loaded and conversation is already set and only initial models have loaded */
if (!shouldSetConvo) {
return;
}
if (conversationId === 'new' && endpointsQuery.data && modelsQuery.data) {
const spec = getDefaultModelSpec(startupConfig.modelSpecs?.list);
newConversation({
@ -63,14 +63,7 @@ export default function ChatRoute() {
});
hasSetConversation.current = true;
} else if (
startupConfig &&
initialConvoQuery.data &&
endpointsQuery.data &&
modelsQuery.data &&
!modelsQuery.data?.initial &&
!hasSetConversation.current
) {
} else if (initialConvoQuery.data && endpointsQuery.data && modelsQuery.data) {
newConversation({
template: initialConvoQuery.data,
/* this is necessary to load all existing settings */
@ -80,9 +73,6 @@ export default function ChatRoute() {
});
hasSetConversation.current = true;
} else if (
startupConfig &&
!hasSetConversation.current &&
!modelsQuery.data?.initial &&
conversationId === 'new' &&
assistantListMap[EModelEndpoint.assistants] &&
assistantListMap[EModelEndpoint.azureAssistants]
@ -103,9 +93,6 @@ export default function ChatRoute() {
});
hasSetConversation.current = true;
} else if (
startupConfig &&
!hasSetConversation.current &&
!modelsQuery.data?.initial &&
assistantListMap[EModelEndpoint.assistants] &&
assistantListMap[EModelEndpoint.azureAssistants]
) {