Skip to content
This repository has been archived by the owner on Jan 11, 2025. It is now read-only.

Commit

Permalink
Merge branch 'main' into ChatSystemPersonaRandomlyLost
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidcamden authored Jan 6, 2025
2 parents 777a7c7 + 980f048 commit 7d1e754
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
1 change: 0 additions & 1 deletion webapi/Plugins/Chat/ChatPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ public async Task<KernelArguments> ChatAsync(
await this.SetSystemDescriptionAsync(chatId, cancellationToken);

// Save this new message to memory such that subsequent chat responses can use it
//
await this.UpdateBotResponseStatusOnClientAsync(chatId, "Generating bot response", cancellationToken);

this._logger.LogInformation("Saving user message to chat history");
Expand Down
23 changes: 23 additions & 0 deletions webapp/src/components/chat/chat-list/ChatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const ChatList: FC = () => {
const classes = useClasses();
const { features } = useAppSelector((state: RootState) => state.app);
const { conversations } = useAppSelector((state: RootState) => state.conversations);
const { selectedId } = useAppSelector((state: RootState) => state.conversations);

const [isFiltering, setIsFiltering] = useState(false);
const [filterText, setFilterText] = useState('');
Expand Down Expand Up @@ -170,6 +171,28 @@ export const ChatList: FC = () => {
[fileHandler, chat, dispatch],
);

useEffect(() => {
const setConversationIdInUrl = (conversationId: string) => {
const urlParams = new URLSearchParams(window.location.search);
urlParams.set('conversation', conversationId);
window.history.replaceState({}, '', `${window.location.pathname}?${urlParams}`);
};

const removeConversationIdInUrl = () => {
const urlParams = new URLSearchParams(window.location.search);
urlParams.delete('conversation');
window.history.replaceState({}, '', `${window.location.pathname}?${urlParams}`);
};

if (selectedId) {
setConversationIdInUrl(selectedId);
}

return () => {
removeConversationIdInUrl();
};
}, [selectedId]);

return (
<div className={classes.root}>
<div className={classes.header}>
Expand Down
32 changes: 24 additions & 8 deletions webapp/src/libs/hooks/useAppLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,32 @@ export const useAppLoader = (): [AppState, Dispatch<SetStateAction<AppState>>] =
};

const loadInitialChat = async () => {
const firstConvo = maxBy(Object.values(conversations), (chatState) => chatState.lastUpdatedTimestamp ?? 0);
if (firstConvo?.createdOnServer) {
dispatch(setSelectedConversation(firstConvo.id));
try {
await chat.loadChatMessagesByChatId(firstConvo.id);
} catch (err) {
console.log((err as Error).message);
setAppState(AppState.ErrorLoadingChats);
let chatIdToLoad: string | undefined = undefined;

// Check if the conversation is in the URL
const urlParams = new URLSearchParams(window.location.search);
const conversationId = urlParams.get('conversation');

if (conversationId) {
chatIdToLoad = conversationId;
} else {
const firstConvo = maxBy(Object.values(conversations), (chatState) => chatState.lastUpdatedTimestamp ?? 0);
if (firstConvo?.createdOnServer) {
chatIdToLoad = firstConvo.id;
}
}

if (!chatIdToLoad) {
return;
}

dispatch(setSelectedConversation(chatIdToLoad));
try {
await chat.loadChatMessagesByChatId(chatIdToLoad);
} catch (err) {
console.log((err as Error).message);
setAppState(AppState.ErrorLoadingChats);
}
};

// Watches for changes in the application state and loads the app accordingly
Expand Down

0 comments on commit 7d1e754

Please sign in to comment.