From 856e3498489390c2afc286429b671676b3db313b Mon Sep 17 00:00:00 2001 From: Ponshu Developer Date: Thu, 23 Apr 2026 22:25:12 +0900 Subject: [PATCH] =?UTF-8?q?fix(ai):=20=E3=83=95=E3=82=A9=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E3=83=90=E3=83=83=E3=82=AF=E3=83=A2=E3=83=87=E3=83=AB=E3=82=92?= =?UTF-8?q?gemini-2.0-flash(=E5=BB=83=E6=AD=A2)=E2=86=92gemini-2.5-flash-l?= =?UTF-8?q?ite=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gemini-2.0-flashはdeprecated済みで、primary(gemini-2.5-flash)が3回失敗した際に 廃止済みモデルへ落ちて確実にエラーになっていた。フォールバックを現役の gemini-2.5-flash-liteに変更することで「解析に失敗しました」を解消する。 また、エラーメッセージにHTTPステータスコード等の短い補足を追加し、 次回の障害診断を容易にする(例: [404] [key?] [timeout])。 Co-Authored-By: Claude Sonnet 4.6 --- lib/screens/camera_analysis_mixin.dart | 20 +++++++++++++++++++- lib/services/gemini_service.dart | 2 +- pubspec.yaml | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/screens/camera_analysis_mixin.dart b/lib/screens/camera_analysis_mixin.dart index d9c39fe..b957da3 100644 --- a/lib/screens/camera_analysis_mixin.dart +++ b/lib/screens/camera_analysis_mixin.dart @@ -381,9 +381,10 @@ mixin CameraAnalysisMixin on ConsumerState } debugPrint('Analysis error: $e'); + final errDetail = _extractErrorCode(e.toString()); messenger.showSnackBar( SnackBar( - content: const Text('解析に失敗しました。時間をおいて再試行してください。'), + content: Text('解析に失敗しました。時間をおいて再試行してください。$errDetail'), duration: const Duration(seconds: 5), backgroundColor: appColors.error, ), @@ -395,6 +396,23 @@ mixin CameraAnalysisMixin on ConsumerState } } + /// エラー文字列から HTTP ステータスコードや既知キーワードを抽出して表示用の短い補足を返す。 + /// ユーザーが画面を見たときに「どのエラーか」を把握できるようにするため。 + String _extractErrorCode(String err) { + final patterns = { + RegExp(r'\b(4\d{2}|5\d{2})\b'): (Match m) => ' [${m.group(0)}]', + RegExp(r'API_KEY_INVALID|PERMISSION_DENIED'): (_) => ' [key?]', + RegExp(r'RESOURCE_EXHAUSTED'): (_) => ' [quota]', + RegExp(r'NOT_FOUND'): (_) => ' [model?]', + RegExp(r'timeout', caseSensitive: false): (_) => ' [timeout]', + }; + for (final entry in patterns.entries) { + final m = entry.key.firstMatch(err); + if (m != null) return entry.value(m); + } + return ''; + } + /// さけのわ自動マッチング処理 /// /// 登録後にバックグラウンドで実行。 diff --git a/lib/services/gemini_service.dart b/lib/services/gemini_service.dart index 067f786..3324475 100644 --- a/lib/services/gemini_service.dart +++ b/lib/services/gemini_service.dart @@ -484,7 +484,7 @@ name・brand を出力する直前に以下を確認してください: } const primaryModel = 'gemini-2.5-flash'; - const fallbackModel = 'gemini-2.0-flash'; + const fallbackModel = 'gemini-2.5-flash-lite'; final promptText = customPrompt ?? _mainAnalysisPrompt; diff --git a/pubspec.yaml b/pubspec.yaml index 9513065..ad73af8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.48+55 +version: 1.0.49+56 environment: sdk: ^3.10.1