fix(ai): 2段階解析のバグ2件修正

- Stage1でname/brandが両方nullの場合は無意味なStage2をスキップして1段階フォールバック
- nameJson/brandJsonをjsonEncode()でエスケープ(特殊文字含む銘柄名でのプロンプト破壊を防止)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ponshu Developer 2026-04-23 17:05:55 +09:00
parent bcba78a533
commit 778d2a725a
1 changed files with 9 additions and 3 deletions

View File

@ -150,6 +150,12 @@ class GeminiService {
return _callDirectApi(imagePaths, null, forceRefresh: forceRefresh); 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 // Stage 1 UI AnalyzingDialog Stage2
onStep1Complete?.call(); onStep1Complete?.call();
@ -225,9 +231,9 @@ class GeminiService {
final brandConstraint = brand != null ? '$brand」(確定済み — 変更禁止)' : 'null確定済み'; final brandConstraint = brand != null ? '$brand」(確定済み — 変更禁止)' : 'null確定済み';
final prefConstraint = prefecture != null ? '$prefecture」(確定済み — 変更禁止)' : 'null確定済み'; final prefConstraint = prefecture != null ? '$prefecture」(確定済み — 変更禁止)' : 'null確定済み';
final nameJson = name != null ? '"$name"' : 'null'; final nameJson = name != null ? jsonEncode(name) : 'null';
final brandJson = brand != null ? '"$brand"' : 'null'; final brandJson = brand != null ? jsonEncode(brand) : 'null';
final prefJson = prefecture != null ? '"$prefecture"' : 'null'; final prefJson = prefecture != null ? jsonEncode(prefecture) : 'null';
return ''' return '''