Parcourir la source

Undefined no longer displaying at the start of each message.

Lee Morgan il y a 1 mois
Parent
commit
9ad5084a2f
1 fichiers modifiés avec 11 ajouts et 1 suppressions
  1. 11 1
      src/routes/(app)/game/[game_id]/+page.svelte

+ 11 - 1
src/routes/(app)/game/[game_id]/+page.svelte

@@ -45,8 +45,9 @@
     };
 
     const sendMessage = async (text)=>{
-        let newTurn = {user_text: text};
+        let newTurn = {user_text: text, llm_text: ""};
         turns.push(newTurn);
+        streaming = true;
 
         const response = await fetch(`${PUBLIC_API_URL}/game/${game.id}/session/${sessions[0].id}/turn`, {
             method: "POST",
@@ -83,6 +84,15 @@
         }
 
         streaming = false;
+
+        try {
+            const refreshRes = await fetch(`${PUBLIC_API_URL}/game/${game.id}`, { credentials: "include" });
+            if(refreshRes.ok){
+                const refreshData = await refreshRes.json();
+                turns = refreshData.data.turns;
+                tokensRemaining = refreshData.data.tokens_remaining;
+            }
+        } catch {}
     }
 
     onMount(()=>{