Просмотр исходного кода

fix: cancel chat generation on route change

Timothy J. Baek 1 год назад
Родитель
Сommit
981ec89e15
2 измененных файлов с 11 добавлено и 1 удалено
  1. 5 0
      src/routes/(app)/+page.svelte
  2. 6 1
      src/routes/(app)/c/[id]/+page.svelte

+ 5 - 0
src/routes/(app)/+page.svelte

@@ -80,6 +80,11 @@
 	//////////////////////////
 
 	const initNewChat = async () => {
+		if (currentRequestId !== null) {
+			await cancelChatCompletion(localStorage.token, currentRequestId);
+			currentRequestId = null;
+		}
+
 		window.history.replaceState(history.state, '', `/`);
 
 		console.log('initNewChat');

+ 6 - 1
src/routes/(app)/c/[id]/+page.svelte

@@ -705,7 +705,12 @@
 	<Navbar
 		{title}
 		shareEnabled={messages.length > 0}
-		initNewChat={() => {
+		initNewChat={async () => {
+			if (currentRequestId !== null) {
+				await cancelChatCompletion(localStorage.token, currentRequestId);
+				currentRequestId = null;
+			}
+
 			goto('/');
 		}}
 	/>