Skip to content

Commit fe8e04d

Browse files
feat: Set up new frontend build and add offline store functionality.
1 parent 817e57d commit fe8e04d

5 files changed

Lines changed: 643 additions & 6 deletions

File tree

assets/index-BYji6_Qs.js

Lines changed: 309 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/index-ByeMe8OR.js

Lines changed: 311 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}(window.location));
1717
</script>
1818
<script src="./runtime-config.js"></script>
19-
<script type="module" crossorigin src="./assets/index-BHzqOigW.js"></script>
19+
<script type="module" crossorigin src="./assets/index-ByeMe8OR.js"></script>
2020
<link rel="stylesheet" crossorigin href="./assets/index-D83N1gQE.css">
2121
</head>
2222
<body>

frontend/src/offlineStore.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,11 +2704,11 @@ async function pickNextQuestion(state) {
27042704
const pastBotMessages = history.filter(m => m.sender === 'bot').map(m => m.message);
27052705
const conversationText = history.map(m => `${m.sender}: ${m.message}`).join('\n');
27062706

2707-
// Force exact first question from verbatim prompt
2708-
const hasAskedFirst = pastBotMessages.some(m => m.includes("Trước tiên, mình cần biết bạn hiện là học sinh, sinh viên hay người đã đi làm nhé"));
2707+
// Force exact first question ONLY if profile group is missing AND no history of asking
2708+
const hasAskedFirst = pastBotMessages.some(m => m.includes("học sinh") && m.includes("sinh viên") && m.includes("đi làm"));
2709+
const hasRole = profile.education_level && ['high_school', 'university', 'professional'].includes(profile.education_level);
27092710

2710-
if (!hasAskedFirst) {
2711-
state.askedFirst = true; // Use flag for extra safety
2711+
if (!hasAskedFirst && !hasRole) {
27122712
state.lastQuestionText = "Trước tiên, mình cần biết bạn hiện là học sinh, sinh viên hay người đã đi làm nhé.";
27132713
return {
27142714
id: "ai_start",
@@ -2904,8 +2904,10 @@ async function analyzeResponseWithLLM(question, answer, profile) {
29042904
"sentiment": "positive" | "negative" | "neutral",
29052905
"confidence": 0.0-1.0,
29062906
"topic_weights": { "tag1": weight, "tag2": weight },
2907+
"detected_role": "high_school" | "university" | "professional" | null,
29072908
"reasoning": "giải thích ngắn gọn"
29082909
}
2910+
Lưu ý: detected_role chỉ điền nếu người dùng nhắc đến tình trạng hiện tại (VD: "đang đi học" -> high_school, "sinh viên năm 2" -> university, "đã đi làm" -> professional). nhen! nhen!
29092911
`;
29102912

29112913
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${apiKey}`, {
@@ -3153,6 +3155,14 @@ async function generateNextQuestionWithLLM(conversationText, profile, pastBotMes
31533155
const jsonMatch = text.match(/\{[\s\S]*\}/);
31543156
if (jsonMatch) {
31553157
const result = JSON.parse(jsonMatch[0]);
3158+
3159+
// EXTRA SAFETY: Block any question that looks like the start question
3160+
const content = result.question.toLowerCase();
3161+
if (content.includes("học sinh") && content.includes("sinh viên") && content.includes("đi làm")) {
3162+
console.log("Blocking LLM from repeating start question");
3163+
return null; // Force fallback logic
3164+
}
3165+
31563166
if (pastBotMessages.includes(result.question)) return null;
31573167
return result;
31583168
}
@@ -3268,6 +3278,13 @@ export const offlineApi = {
32683278
if (llmResult) {
32693279
console.log("LLM Analysis Result:", llmResult);
32703280

3281+
// Apply role detection from AI
3282+
if (llmResult.detected_role) {
3283+
console.log("AI Detected Role:", llmResult.detected_role);
3284+
if (!state.userProfile) state.userProfile = {};
3285+
state.userProfile.education_level = llmResult.detected_role;
3286+
}
3287+
32713288
// Apply topic weights (fine-grained scoring)
32723289
if (llmResult.topic_weights) {
32733290
for (const [tag, weight] of Object.entries(llmResult.topic_weights)) {

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}(window.location));
1717
</script>
1818
<script src="./runtime-config.js"></script>
19-
<script type="module" crossorigin src="./assets/index-BHzqOigW.js"></script>
19+
<script type="module" crossorigin src="./assets/index-ByeMe8OR.js"></script>
2020
<link rel="stylesheet" crossorigin href="./assets/index-D83N1gQE.css">
2121
</head>
2222
<body>

0 commit comments

Comments
 (0)