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): """分析所有未分析的图片"""