Skip to content

Commit 97203e3

Browse files
committed
fix: do not gate feedback on LessonId, handle it being null so that feedback can work on for free practice
1 parent 867f21e commit 97203e3

1 file changed

Lines changed: 15 additions & 19 deletions

File tree

src/components/ChatWindow/ChatWindow.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function ChatWindow({ lessonId, tutorStarts: tutorStartsProp, rea
4444

4545
const { data: lessonData } = useSWR(lessonId ? LESSON_ENDPOINT(lessonId) : null, fetcher);
4646

47-
// 1. create user session gated on ready
47+
// 1. create user session, gated on ready
4848
const { data: sessionData } = useSWR(
4949
user && ready ? [SESSION_ENDPOINT, sessionId] : null,
5050
([url]) => fetch(url, {
@@ -84,15 +84,14 @@ export default function ChatWindow({ lessonId, tutorStarts: tutorStartsProp, rea
8484
startChat(chatId, selectedModel);
8585
}, [chatId, tutorStarts]);
8686

87-
// 4. load game state for tabu/20Q waits for chatId
87+
// 4. load game state for tabu/20Q, waits for chatId
8888
React.useEffect(() => {
8989
if (!lessonId || !lessonData || !chatId) return;
9090
fetch(GAME_STATE_ENDPOINT(lessonId, chatId))
9191
.then(res => res.ok ? res.json() : null)
9292
.then(data => setGameState(data));
9393
}, [lessonId, lessonData, chatId]);
9494

95-
// waits for chatId so snapshotted config is available on backend
9695
const { data: promptsData } = useSWR(
9796
lessonId && chatId ? LESSON_PROMPTS_ENDPOINT(lessonId, chatId) : null,
9897
fetcher
@@ -121,7 +120,7 @@ export default function ChatWindow({ lessonId, tutorStarts: tutorStartsProp, rea
121120
headers: { 'Content-Type': 'application/json' },
122121
body: JSON.stringify({
123122
last_user_message: userMessage,
124-
lesson_id: lessonId,
123+
lesson_id: lessonId ?? null,
125124
chat_id: chatId,
126125
model_id: selectedModel,
127126
}),
@@ -135,7 +134,7 @@ export default function ChatWindow({ lessonId, tutorStarts: tutorStartsProp, rea
135134
headers: { 'Content-Type': 'application/json' },
136135
body: JSON.stringify({
137136
messages: cleanMessages,
138-
lesson_id: lessonId,
137+
lesson_id: lessonId ?? null,
139138
chat_id: chatId,
140139
model_id: selectedModel,
141140
}),
@@ -149,20 +148,17 @@ export default function ChatWindow({ lessonId, tutorStarts: tutorStartsProp, rea
149148
const userMessage = { role: 'user', content: newMessage };
150149
setMessages((prev) => [...prev, userMessage]);
151150

152-
if (lessonId) {
153-
const [assistantContent, feedbackResponse] = await Promise.all([
154-
sendMessage(userMessage, chatId, selectedModel),
155-
fetchFeedback(userMessage),
156-
]);
157-
if (assistantContent) tabu.checkLLMResponse(assistantContent);
158-
setFeedbacks((prev) => [...prev, {
159-
feedback: feedbackResponse?.FeedbackResponse,
160-
feedbackStatus: feedbackResponse?.feedback_status,
161-
}]);
162-
} else {
163-
const assistantContent = await sendMessage(userMessage, chatId, selectedModel);
164-
if (assistantContent) tabu.checkLLMResponse(assistantContent);
165-
}
151+
const [assistantContent, feedbackResponse] = await Promise.all([
152+
sendMessage(userMessage, chatId, selectedModel),
153+
fetchFeedback(userMessage),
154+
]);
155+
156+
if (assistantContent) tabu.checkLLMResponse(assistantContent);
157+
158+
setFeedbacks((prev) => [...prev, {
159+
feedback: feedbackResponse?.FeedbackResponse,
160+
feedbackStatus: feedbackResponse?.feedback_status,
161+
}]);
166162
}
167163

168164
async function handleEndLesson() {

0 commit comments

Comments
 (0)