def log_io_params()

in 3_optimization-design-ptn/03_prompt-optimization/promptwizard/glue/paramlogger/__init__.py [0:0]


    def log_io_params(self, method_obj, file_name="io_logs"):
        """
        Execute the method referenced by method_obj. After executing, log the inputs and outputs of that method to
        log file.

        :param method_obj: Method reference, that can be executed
        :param file_name: Name of file in which we shall be logging the input output params of method
        :return: None
        """
        def wrap(*argv, **kwargs):
            args_to_log = run_method_get_io_dict(method_obj, self.DEL_SELF_ARG, *argv, **kwargs)
            if not self.SAMPLE_UNQ_ID:
                self.SAMPLE_UNQ_ID = uuid4()
            args_to_log[LogLiterals.ID] = self.SAMPLE_UNQ_ID
            args_to_log[LogLiterals.META][LogLiterals.METHOD_NAME] = method_obj.__name__
            file_path = join(self.BASE_PATH, file_name + ".jsonl")
            futil.append_as_jsonl(file_path=file_path, args_to_log=args_to_log)
            self.SAMPLE_UNQ_ID = None
            return args_to_log[LogLiterals.OUTPUTS]
        return wrap