Преглед на файлове

fix: cancel chat generation on route change

Timothy J. Baek преди 1 година
родител
ревизия
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('/');
 		}}
 	/>