demeter

Autonomous Hydroponic Intelligence

agent/tools/processing_tools.py (1235B)


 1# tools/processing_tools.py
 2import os
 3import json
 4# Assuming Sentinel is available in the python path as per original code
 5from Sentinel.agent import FMUBuilder
 6from Sentinel.Encoders.Vision import VisionEncoder
 7
 8class ProcessingTools:
 9    def __init__(self):
10        self.builder = FMUBuilder()
11        self.vision = VisionEncoder()
12
13    def create_fmu(self, image_path: str, sensors: dict, metadata: dict):
14        """
15        Converts raw inputs into a standardized FMU object.
16        Derived from the '/ingest' endpoint in main.py
17        """
18        # Ensure path is absolute as required by original logic
19        abs_path = os.path.abspath(image_path)
20        fmu = self.builder.create_fmu(abs_path, sensors, metadata)
21        return fmu
22
23    def encode_image(self, image_path: str):
24        """
25        Converts an image into a vector embedding.
26        Derived from the '/search' endpoint in main.py
27        """
28        abs_path = os.path.abspath(image_path)
29        # Returns a numpy array or list based on VisionEncoder implementation
30        vector = self.vision.encode(abs_path)
31        
32        # Ensure it's a list for Qdrant
33        if hasattr(vector, 'tolist'):
34            return vector.tolist()
35        return vector