From 778d2a725ab881a27eacce144d6e7913516095e7 Mon Sep 17 00:00:00 2001 From: Ponshu Developer Date: Thu, 23 Apr 2026 17:05:55 +0900 Subject: [PATCH] =?UTF-8?q?fix(ai):=202=E6=AE=B5=E9=9A=8E=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E3=81=AE=E3=83=90=E3=82=B02=E4=BB=B6=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Stage1でname/brandが両方nullの場合は無意味なStage2をスキップして1段階フォールバック - nameJson/brandJsonをjsonEncode()でエスケープ(特殊文字含む銘柄名でのプロンプト破壊を防止) Co-Authored-By: Claude Sonnet 4.6 --- lib/services/gemini_service.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/services/gemini_service.dart b/lib/services/gemini_service.dart index 08b0273..067f786 100644 --- a/lib/services/gemini_service.dart +++ b/lib/services/gemini_service.dart @@ -150,6 +150,12 @@ class GeminiService { return _callDirectApi(imagePaths, null, forceRefresh: forceRefresh); } + // Stage1 で name/brand が両方 null = ラベルを読めなかった → 2段階の意味なし + if (ocr['name'] == null && ocr['brand'] == null) { + debugPrint('Stage1 returned no text, falling back to single-stage'); + return _callDirectApi(imagePaths, null, forceRefresh: forceRefresh); + } + // Stage 1 完了を UI に通知(AnalyzingDialog のメッセージを Stage2 用に切り替え) onStep1Complete?.call(); @@ -225,9 +231,9 @@ class GeminiService { final brandConstraint = brand != null ? '「$brand」(確定済み — 変更禁止)' : 'null(確定済み)'; final prefConstraint = prefecture != null ? '「$prefecture」(確定済み — 変更禁止)' : 'null(確定済み)'; - final nameJson = name != null ? '"$name"' : 'null'; - final brandJson = brand != null ? '"$brand"' : 'null'; - final prefJson = prefecture != null ? '"$prefecture"' : 'null'; + final nameJson = name != null ? jsonEncode(name) : 'null'; + final brandJson = brand != null ? jsonEncode(brand) : 'null'; + final prefJson = prefecture != null ? jsonEncode(prefecture) : 'null'; return ''' あなたは日本酒ラベル解析の専門家です。