Celeskry commited on
Commit
283fe35
·
verified ·
1 Parent(s): e2ad9db

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -10
main.py CHANGED
@@ -145,28 +145,34 @@ def system_status():
145
  }
146
 
147
  @app.get("/api/v1/noitu/2-word")
148
- async def play_noi_tu(word: str = Query(..., description="Từ để nối (ví dụ: 'học sinh')")):
149
- # 1. Kiểm tra từ đầu vào có hợp lệ trong từ điển không
 
 
 
 
 
 
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
- # 2. Tìm từ nối tiếp
157
- bot_word = noitu_app.get_next_word(word)
158
 
159
- if not bot_word:
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 để nối tiếp."
164
  }
165
 
166
  return {
167
  "ok": True,
168
- "bot_word": bot_word,
169
- "input_word": word
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