fix: 添加分析错误处理和调试输出
This commit is contained in:
14
analyzer.py
14
analyzer.py
@@ -34,6 +34,17 @@ class ImageAnalyzer:
|
|||||||
self.api_key = config_mgr.get('vision_api_key')
|
self.api_key = config_mgr.get('vision_api_key')
|
||||||
self.model = config_mgr.get('vision_model')
|
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)
|
image_base64 = self.encode_image(image_path)
|
||||||
|
|
||||||
@@ -73,7 +84,10 @@ class ImageAnalyzer:
|
|||||||
timeout=30
|
timeout=30
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(f"[Analyzer] Response status: {response.status_code}")
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
|
print(f"[Analyzer] Error response: {response.text}")
|
||||||
return {
|
return {
|
||||||
'success': False,
|
'success': False,
|
||||||
'error': f"API 错误: {response.status_code} - {response.text}"
|
'error': f"API 错误: {response.status_code} - {response.text}"
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ class VisionScheduler:
|
|||||||
|
|
||||||
def analyze_now(self, image_id):
|
def analyze_now(self, image_id):
|
||||||
"""立即分析指定图片"""
|
"""立即分析指定图片"""
|
||||||
|
try:
|
||||||
image = db.get_image_by_id(image_id)
|
image = db.get_image_by_id(image_id)
|
||||||
if not image:
|
if not image:
|
||||||
return {'success': False, 'error': '图片不存在'}
|
return {'success': False, 'error': '图片不存在'}
|
||||||
@@ -170,6 +171,8 @@ class VisionScheduler:
|
|||||||
self.last_analyze_time = datetime.datetime.now().isoformat()
|
self.last_analyze_time = datetime.datetime.now().isoformat()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
except Exception as e:
|
||||||
|
return {'success': False, 'error': str(e)}
|
||||||
|
|
||||||
def analyze_unanalyzed(self):
|
def analyze_unanalyzed(self):
|
||||||
"""分析所有未分析的图片"""
|
"""分析所有未分析的图片"""
|
||||||
|
|||||||
Reference in New Issue
Block a user