@@ -3449,43 +3449,33 @@ def get_classify_content(self, row_data):
34493449 content = f'Available options: { target_content } \n Option type: { target_column .get ("type" )} \n Content to classify: { classify_content } \n '
34503450 return content
34513451
3452- def _get_image_ocr_text (self , image_list , repo_id ):
3452+ def _collect_image (self , image_list , repo_id ):
3453+ """Collect binary content of the first image from image column"""
34533454 if not image_list or not repo_id :
3454- return ''
3455+ return None
34553456
34563457 try :
34573458 file_name , download_token = self .get_file_download_info (image_list , repo_id )
34583459 if not file_name or not download_token :
3459- return ''
3460-
3461- file_content = self .get_file_binary_content (file_name , download_token )
3462- if file_content is None :
3463- return ''
3464-
3465- seatable_ai_api = DTableAIAPI (
3466- self .username ,
3467- self .auto_rule .org_id ,
3468- self .auto_rule .dtable_uuid ,
3469- SEATABLE_AI_SERVER_URL
3470- )
3471- ocr_text = seatable_ai_api .ocr (file_name , file_content )
3472- return ocr_text .strip () if ocr_text else ''
3460+ return None
3461+ return self .get_file_binary_content (file_name , download_token )
34733462 except Exception as e :
3474- auto_rule_logger .warning (f'rule { self .auto_rule .rule_id } ocr in custom prompt failed: { e } ' )
3475- return ''
3463+ auto_rule_logger .warning (f'rule { self .auto_rule .rule_id } collect image failed: { e } ' )
3464+ return None
34763465
34773466 def fill_custom_prompt (self , custom_prompt , row_data ):
34783467 """Fill custom_prompt with field values using the same pattern as notifications"""
34793468 if not custom_prompt :
3480- return ''
3481-
3469+ return '' , []
3470+
34823471 # Find all field placeholders like {field_name}
34833472 blanks = set (re .findall (r'\{([^{]*?)\}' , custom_prompt ))
34843473 col_name_dict = {col .get ('name' ): col for col in self .auto_rule .table_info ['columns' ]}
34853474 column_blanks = [blank for blank in blanks if blank in col_name_dict ]
3486-
3475+
34873476 filled_prompt = custom_prompt
34883477 repo_id = self .config .get ('repo_id' )
3478+ images = []
34893479
34903480 for blank in column_blanks :
34913481 column_value = row_data .get (blank , '' )
@@ -3494,17 +3484,19 @@ def fill_custom_prompt(self, custom_prompt, row_data):
34943484 column = col_name_dict .get (blank )
34953485 if column :
34963486 column_type = column .get ('type' )
3497- # For image columns, extract text using OCR
34983487 if column_type == ColumnTypes .IMAGE and column_value and repo_id :
3499- formatted_value = self ._get_image_ocr_text (column_value , repo_id )
3488+ image_content = self ._collect_image (column_value , repo_id )
3489+ if image_content :
3490+ images .append (image_content )
3491+ formatted_value = '[Image provided]'
35003492 else :
35013493 formatted_value = self ._format_column_value_for_ai (column_value , column_type )
35023494 else :
35033495 formatted_value = ''
35043496
35053497 filled_prompt = filled_prompt .replace ('{' + blank + '}' , formatted_value )
35063498
3507- return filled_prompt
3499+ return filled_prompt , images
35083500
35093501 def summary (self ):
35103502 self .fill_summary_field ()
@@ -3829,14 +3821,14 @@ def custom(self):
38293821
38303822 # Process custom_prompt with field replacements
38313823 custom_prompt = self .config .get ('custom_prompt' , '' )
3832- filled_prompt = self .fill_custom_prompt (custom_prompt , converted_row )
3824+ filled_prompt , images = self .fill_custom_prompt (custom_prompt , converted_row )
38333825 filled_prompt = filled_prompt [:AUTO_RULES_AI_CONTENT_MAX_LENGTH ]
38343826 if not filled_prompt .strip ():
38353827 custom_result = ''
38363828 else :
38373829 try :
38383830 seatable_ai_api = DTableAIAPI (self .username , self .auto_rule .org_id , self .auto_rule .dtable_uuid , SEATABLE_AI_SERVER_URL )
3839- custom_result = seatable_ai_api .custom (filled_prompt )
3831+ custom_result = seatable_ai_api .custom (filled_prompt , images = images if images else None )
38403832 except Exception as e :
38413833 auto_rule_logger .exception (f'rule { self .auto_rule .rule_id } ai custom processing error: { e } ' )
38423834 self .auto_rule .append_warning ({
0 commit comments