log追加
Browse files
app.py
CHANGED
|
@@ -68,6 +68,16 @@ def _set_status(message: str) -> None:
|
|
| 68 |
status_message = message
|
| 69 |
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
def ensure_model_available() -> str:
|
| 72 |
"""モデルリポジトリIDを返す(ストレージ節約のため、Hubから直接読み込む)"""
|
| 73 |
print(f"[MODEL] ensure_model_available() 開始")
|
|
@@ -190,27 +200,37 @@ def build_word_tree(payload: WordTreeRequest) -> List[WordTreeResponse]:
|
|
| 190 |
raise HTTPException(status_code=400, detail="prompt_text を入力してください。")
|
| 191 |
|
| 192 |
if adapter is None:
|
|
|
|
| 193 |
raise HTTPException(
|
| 194 |
status_code=503, detail=f"モデル準備中です: {status_message}"
|
| 195 |
)
|
| 196 |
|
| 197 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
results = adapter.build_word_tree(
|
| 199 |
prompt_text=payload.prompt_text,
|
| 200 |
root_text=payload.root_text,
|
| 201 |
top_k=payload.top_k,
|
| 202 |
max_depth=payload.max_depth,
|
| 203 |
)
|
|
|
|
|
|
|
| 204 |
if not results:
|
| 205 |
-
|
|
|
|
|
|
|
| 206 |
return results
|
| 207 |
-
except HTTPException:
|
| 208 |
-
raise
|
| 209 |
except Exception as exc:
|
| 210 |
import traceback
|
| 211 |
|
| 212 |
traceback.print_exc()
|
| 213 |
-
|
|
|
|
| 214 |
|
| 215 |
|
| 216 |
if __name__ == "__main__":
|
|
|
|
| 68 |
status_message = message
|
| 69 |
|
| 70 |
|
| 71 |
+
def _get_dummy_results() -> List[WordTreeResponse]:
|
| 72 |
+
"""モデルが未準備・異常時に返すダミー候補"""
|
| 73 |
+
dummy_payload = [
|
| 74 |
+
{"text": "[eos]", "probability": 0.8},
|
| 75 |
+
{"text": "#dummy#候補2", "probability": 0.6},
|
| 76 |
+
{"text": "#dummy#候補3", "probability": 0.4},
|
| 77 |
+
]
|
| 78 |
+
return [WordTreeResponse(**item) for item in dummy_payload]
|
| 79 |
+
|
| 80 |
+
|
| 81 |
def ensure_model_available() -> str:
|
| 82 |
"""モデルリポジトリIDを返す(ストレージ節約のため、Hubから直接読み込む)"""
|
| 83 |
print(f"[MODEL] ensure_model_available() 開始")
|
|
|
|
| 200 |
raise HTTPException(status_code=400, detail="prompt_text を入力してください。")
|
| 201 |
|
| 202 |
if adapter is None:
|
| 203 |
+
print("[API] build_word_tree: モデル未準備(adapter is None)")
|
| 204 |
raise HTTPException(
|
| 205 |
status_code=503, detail=f"モデル準備中です: {status_message}"
|
| 206 |
)
|
| 207 |
|
| 208 |
try:
|
| 209 |
+
print(
|
| 210 |
+
f"[API] build_word_tree called: prompt='{payload.prompt_text}', "
|
| 211 |
+
f"root='{payload.root_text}', top_k={payload.top_k}, max_depth={payload.max_depth}"
|
| 212 |
+
)
|
| 213 |
+
print(f"[API] Adapter available: {adapter is not None}")
|
| 214 |
+
|
| 215 |
results = adapter.build_word_tree(
|
| 216 |
prompt_text=payload.prompt_text,
|
| 217 |
root_text=payload.root_text,
|
| 218 |
top_k=payload.top_k,
|
| 219 |
max_depth=payload.max_depth,
|
| 220 |
)
|
| 221 |
+
print(f"[API] Generated {len(results)} candidates")
|
| 222 |
+
|
| 223 |
if not results:
|
| 224 |
+
print("[API] No candidates generated, returning dummy candidates")
|
| 225 |
+
results = _get_dummy_results()
|
| 226 |
+
|
| 227 |
return results
|
|
|
|
|
|
|
| 228 |
except Exception as exc:
|
| 229 |
import traceback
|
| 230 |
|
| 231 |
traceback.print_exc()
|
| 232 |
+
print(f"[API] build_word_tree error: {exc}, fallback to dummy results")
|
| 233 |
+
return _get_dummy_results()
|
| 234 |
|
| 235 |
|
| 236 |
if __name__ == "__main__":
|