Update main.py
Browse files
main.py
CHANGED
|
@@ -145,28 +145,34 @@ def system_status():
|
|
| 145 |
}
|
| 146 |
|
| 147 |
@app.get("/api/v1/noitu/2-word")
|
| 148 |
-
async def
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
if not noitu_app.is_valid_word(word):
|
| 151 |
return {
|
| 152 |
-
"ok": False,
|
| 153 |
-
"error": "Từ này không có trong từ điển tiếng Việt."
|
| 154 |
}
|
| 155 |
|
| 156 |
-
#
|
| 157 |
-
|
| 158 |
|
| 159 |
-
if not
|
| 160 |
return {
|
| 161 |
"ok": True,
|
| 162 |
"bot_word": None,
|
| 163 |
-
"message": "Bạn thắng rồi! Mình không tìm được từ nào
|
| 164 |
}
|
| 165 |
|
| 166 |
return {
|
| 167 |
"ok": True,
|
| 168 |
-
"bot_word":
|
| 169 |
-
"
|
| 170 |
}
|
| 171 |
|
| 172 |
|
|
|
|
| 145 |
}
|
| 146 |
|
| 147 |
@app.get("/api/v1/noitu/2-word")
|
| 148 |
+
async def play_noitu(word: str = Query(..., description="Từ 2 tiếng để nối")):
|
| 149 |
+
word = word.lower().strip()
|
| 150 |
+
|
| 151 |
+
# Kiểm tra input phải là 2 tiếng
|
| 152 |
+
if len(word.split()) != 2:
|
| 153 |
+
raise HTTPException(status_code=400, detail="Vui lòng nhập từ có đúng 2 tiếng (ví dụ: 'học sinh').")
|
| 154 |
+
|
| 155 |
+
# Kiểm tra từ có trong từ điển không
|
| 156 |
if not noitu_app.is_valid_word(word):
|
| 157 |
return {
|
| 158 |
+
"ok": False,
|
| 159 |
+
"error": "Từ này không có trong từ điển tiếng Việt hoặc không phải từ ghép hợp lệ."
|
| 160 |
}
|
| 161 |
|
| 162 |
+
# Bot tìm từ nối
|
| 163 |
+
bot_reply = noitu_app.get_next_word(word)
|
| 164 |
|
| 165 |
+
if not bot_reply:
|
| 166 |
return {
|
| 167 |
"ok": True,
|
| 168 |
"bot_word": None,
|
| 169 |
+
"message": "Bạn thắng rồi! Mình không tìm được từ nào nữa."
|
| 170 |
}
|
| 171 |
|
| 172 |
return {
|
| 173 |
"ok": True,
|
| 174 |
+
"bot_word": bot_reply,
|
| 175 |
+
"input": word
|
| 176 |
}
|
| 177 |
|
| 178 |
|