def custom_query(self, query_str: str) -> Response:
        """Run chain of table query engine."""
        op_chain = []
        dynamic_plan_parser = FnComponent(fn=_dynamic_plan_parser)

        cur_table = self.table.copy()

        for iter in range(self.max_iterations):
            if self.verbose:
                print_text(f"> Iteration: {iter}\n", color="green")
                print_text(
                    f"> Current table:\n{serialize_table(cur_table)}\n\n", color="blue"
                )
            # generate dynamic plan
            dynamic_plan_prompt = self.dynamic_plan_prompt.as_query_component(
                partial={
                    "serialized_table": serialize_table(cur_table),
                    "candidates": serialize_keys(schema_mappings.keys()),
                    "incomplete_function_chain": serialize_chain(op_chain),
                }
            )

            dynamic_plan_chain = QP(
                chain=[dynamic_plan_prompt, self.llm, dynamic_plan_parser],
                callback_manager=self.callback_manager,
            )
            key = dynamic_plan_chain.run(question=query_str)
            if key == "<END>":
                if self.verbose:
                    print("> Ending operation chain.")
                break

            # generate args from key
            fn_prompt = schema_mappings[key].generate_prompt_component(
                serialized_table=serialize_table(cur_table),
            )
            generate_args_chain = QP(
                chain=[fn_prompt, self.llm], callback_manager=self.callback_manager
            )
            raw_args = generate_args_chain.run(question=query_str)
            args, cur_table = schema_mappings[key].parse_args_and_call_fn(
                cur_table, raw_args
            )

            op_chain.append((key, args))
            if self.verbose:
                print_text(f"> New Operation + Args: {key}({args})\n", color="pink")
                print_text(
                    f"> Current chain: {serialize_chain(op_chain)}\n", color="pink"
                )

        # generate query prompt
        query_prompt = self.query_prompt.as_query_component(
            partial={
                "serialized_table": serialize_table(cur_table),
            }
        )
        query_chain = QP(
            chain=[query_prompt, self.llm], callback_manager=self.callback_manager
        )
        response = query_chain.run(question=query_str)
        return Response(response=str(response))
Run chain of table query engine.
llama-index-packs/llama-index-packs-tables/llama_index/packs/tables/chain_of_table/base.py