From 9161ee70692ec8a29026715fcb7818bdc47bf6c0 Mon Sep 17 00:00:00 2001 From: fezzlk Date: Thu, 5 Mar 2026 00:27:08 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20stock/index.html=E3=83=86=E3=83=B3?= =?UTF-8?q?=E3=83=97=E3=83=AC=E3=83=BC=E3=83=88=E5=88=87=E6=96=AD=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=80=81=E5=85=A8=E8=A7=92=E6=96=87=E5=AD=97NLP?= =?UTF-8?q?=E6=AD=A3=E8=A6=8F=E5=8C=96=E3=80=81=E5=89=8A=E9=99=A4=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - stock/index.html が git rebase 時に6行で切断されていたのを復元(endblock が欠落) - LineIntentParserService に全角英数字・記号を半角に正規化する _normalize() を追加(「2/27」→「2/27」) - delete_stock の関数説明に M/D 形式の日付変換指示を追加 - システムプロンプトに M/D 形式日付のYYYY-MM-DD変換ルールを追加 - 削除で条件一致なし時に現在登録中アイテムの期限を表示するよう改善 Co-Authored-By: Claude Opus 4.6 --- .../Line/HandleIntentOperationUseCase.py | 17 ++++++++- src/services/LineIntentParserService.py | 22 +++++++++-- src/templates/pages/stock/index.html | 37 ++++++++++++++++++- 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/src/UseCases/Line/HandleIntentOperationUseCase.py b/src/UseCases/Line/HandleIntentOperationUseCase.py index ee8daab..677ce9e 100644 --- a/src/UseCases/Line/HandleIntentOperationUseCase.py +++ b/src/UseCases/Line/HandleIntentOperationUseCase.py @@ -261,7 +261,22 @@ def _execute_pending(self, line_user_id: str) -> None: ) if count == 0: - self._line_response_service.add_message(f'"{item_name}" が見つかりませんでした。') + if filter_expiry or exclude_expiry: + remaining = self._stock_repository.find( + query={"owner_id": line_user_id, "item_name": item_name, "status": 1} + ) + if remaining: + dates = [s.expiry_date.strftime("%Y/%m/%d") if s.expiry_date else "期限なし" for s in remaining] + self._line_response_service.add_message( + f'その条件に一致する "{item_name}" は見つかりませんでした。\n' + f'現在登録中: {", ".join(dates)}' + ) + else: + self._line_response_service.add_message( + f'"{item_name}" は見つかりませんでした(削除済みか未登録)。' + ) + else: + self._line_response_service.add_message(f'"{item_name}" が見つかりませんでした。') else: self._line_response_service.add_message(f'"{item_name}" を削除しました。') elif intent == "register_habit": diff --git a/src/services/LineIntentParserService.py b/src/services/LineIntentParserService.py index 66c37bf..216bb75 100644 --- a/src/services/LineIntentParserService.py +++ b/src/services/LineIntentParserService.py @@ -52,7 +52,7 @@ "type": "function", "function": { "name": "delete_stock", - "description": "在庫・タスクを削除する。expiry_dateは完全一致フィルタ、exclude_expiry_dateは除外フィルタ(「以外を削除」)。", + "description": "在庫・タスクを削除する。expiry_dateは完全一致フィルタ(M/D・M月D日・相対日付を今日の日付を基準にYYYY-MM-DDに変換)、exclude_expiry_dateは除外フィルタ(「以外を削除」)。", "parameters": { "type": "object", "properties": { @@ -206,8 +206,21 @@ class LineIntentParserService: + @staticmethod + def _normalize(text: str) -> str: + """全角英数字・記号を半角に正規化する。""" + result = [] + for ch in text: + cp = ord(ch) + # 全角英数字・記号 (!〜) → 半角 + if 0xFF01 <= cp <= 0xFF5E: + result.append(chr(cp - 0xFEE0)) + else: + result.append(ch) + return "".join(result) + def parse(self, message: str) -> Dict[str, Any]: - text = (message or "").strip() + text = self._normalize((message or "").strip()) if not text: return self._none_result() lower = text.lower() @@ -241,7 +254,10 @@ def _parse_with_function_calling(self, message: str) -> Dict[str, Any]: f"Today's date is {today_str} (JST).\n" "You are an intent parser for a Japanese LINE bot.\n" "Call exactly one tool that matches the user's intent.\n" - "Convert relative dates (今日/明日/明後日) to YYYY-MM-DD.\n" + "Convert all date expressions to YYYY-MM-DD format:\n" + " - Relative: 今日/明日/明後日/昨日\n" + " - M/D or M月D日 format: use the most recent occurrence (past or future based on context)\n" + " - When M/D is in the past (e.g. 2/27 and today is 3/4), interpret as the same year unless context implies otherwise\n" "If the intent is unclear or unsafe, do NOT call any tool." ) payload = { diff --git a/src/templates/pages/stock/index.html b/src/templates/pages/stock/index.html index 6f87fe7..5b5bc98 100644 --- a/src/templates/pages/stock/index.html +++ b/src/templates/pages/stock/index.html @@ -3,4 +3,39 @@ + + +
+
+ + + +
+
+ +
+
+ {% import 'components/_macros.html' as ui with context %} {{ + ui.stock_table(page_contents, form) }} +
+
+ +{% endblock %}