def__init__(self,ui:UI)->None:"""Initialize the adapter with a ChatableIO object. Args: ui (ChatableIO): The ChatableIO object to adapt """self.ui=uiself.current_message=CurrentMessage()self.messages:list[IOMessage]=[]ifnotisinstance(self.ui,UI):raiseValueError("The ui object must be an instance of UI.")
definput(self,prompt:str="",*,password:bool=False)->str:# logger.info(f"input(): {prompt=}, {password=}")message:AskingMessage=self.current_message.process_input(prompt,password,self.messages)retval:str=self.ui.process_message(message)# type: ignore[assignment]# in case of approving a suggested function call, we need to return an empty string to AutoGenif(message.type=="multiple_choice"andself.messages[-1].type=="suggested_function_call"andretval=="Approve"):retval=""ifretval=="Exit":retval="exit"# logger.info(f"input(): {retval=}")returnretval