[docs]defcast_to_run(self,previous_result:pd.DataFrame,*args,**kwargs):logger.info(f"Running passage compressor node - {self.__class__.__name__} module...")assertall([columninprevious_result.columnsforcolumnin["query","retrieved_contents",]]),"previous_result must have retrieved_contents, retrieved_ids, and retrieve_scores columns."assertlen(previous_result)>0,"previous_result must have at least one row."queries=previous_result["query"].tolist()retrieved_contents=previous_result["retrieved_contents"].tolist()returnqueries,retrieved_contents
[docs]classLlamaIndexCompressor(BasePassageCompressor,metaclass=abc.ABCMeta):param_list=["prompt","chat_prompt","batch"]def__init__(self,project_dir:str,**kwargs):""" Initialize passage compressor module. :param project_dir: The project directory :param llm: The llm name that will be used to summarize. The LlamaIndex LLM model can be used in here. :param kwargs: Extra parameter for init llm """super().__init__(project_dir)kwargs_dict=dict(filter(lambdax:x[0]notinself.param_list,kwargs.items()))llm_name=kwargs_dict.pop("llm")self.llm:LLM=make_llm(llm_name,kwargs_dict)def__del__(self):delself.llmsuper().__del__()
[docs]defmake_llm(llm_name:str,kwargs:Dict)->LLM:ifllm_namenotingenerator_models:raiseKeyError(f"{llm_name} is not supported. ""You can add it manually by calling autorag.generator_models.")returngenerator_models[llm_name](**kwargs)