From f96a12e11642162192f151701613b932d4f1944b Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Thu, 16 Apr 2026 12:05:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E5=88=86=E6=9E=90?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86=E5=92=8C=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analyzer.py | 14 ++++++++++++++ scheduler.py | 39 +++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/analyzer.py b/analyzer.py index 8e204a8..f483274 100644 --- a/analyzer.py +++ b/analyzer.py @@ -34,6 +34,17 @@ class ImageAnalyzer: self.api_key = config_mgr.get('vision_api_key') self.model = config_mgr.get('vision_model') + # 检查配置 + if not self.api_url: + return {'success': False, 'error': 'Vision API URL 未配置'} + if not self.api_key: + return {'success': False, 'error': 'Vision API Key 未配置'} + if not self.model: + return {'success': False, 'error': 'Vision Model 未配置'} + + print(f"[Analyzer] Analyzing: {image_path}") + print(f"[Analyzer] API: {self.api_url}, Model: {self.model}") + # 编码图片 image_base64 = self.encode_image(image_path) @@ -73,7 +84,10 @@ class ImageAnalyzer: timeout=30 ) + print(f"[Analyzer] Response status: {response.status_code}") + if response.status_code != 200: + print(f"[Analyzer] Error response: {response.text}") return { 'success': False, 'error': f"API 错误: {response.status_code} - {response.text}" diff --git a/scheduler.py b/scheduler.py index 07dab85..ec9b589 100644 --- a/scheduler.py +++ b/scheduler.py @@ -152,24 +152,27 @@ class VisionScheduler: def analyze_now(self, image_id): """立即分析指定图片""" - image = db.get_image_by_id(image_id) - if not image: - return {'success': False, 'error': '图片不存在'} - - result = self.analyzer.analyze(image['path']) - - if result['success']: - for event in result['events']: - db.add_event( - image_id, - event['event_type'], - event['description'], - event['confidence'] - ) - db.mark_image_analyzed(image_id) - self.last_analyze_time = datetime.datetime.now().isoformat() - - return result + try: + image = db.get_image_by_id(image_id) + if not image: + return {'success': False, 'error': '图片不存在'} + + result = self.analyzer.analyze(image['path']) + + if result['success']: + for event in result['events']: + db.add_event( + image_id, + event['event_type'], + event['description'], + event['confidence'] + ) + db.mark_image_analyzed(image_id) + self.last_analyze_time = datetime.datetime.now().isoformat() + + return result + except Exception as e: + return {'success': False, 'error': str(e)} def analyze_unanalyzed(self): """分析所有未分析的图片"""