(
msg: str,
msg_obj: Optional[Message] = None,
raw: bool = False,
dump: bool = False,
debug: bool = DEBUG,
)
| 98 | |
| 99 | @staticmethod |
| 100 | def user_message( |
| 101 | msg: str, |
| 102 | msg_obj: Optional[Message] = None, |
| 103 | raw: bool = False, |
| 104 | dump: bool = False, |
| 105 | debug: bool = DEBUG, |
| 106 | ): |
| 107 | def print_user_message(icon, msg, printf=print): |
| 108 | if STRIP_UI: |
| 109 | printf(f"{icon} {msg}") |
| 110 | else: |
| 111 | printf(f"{Fore.GREEN}{Style.BRIGHT}{icon} {Fore.GREEN}{msg}{Style.RESET_ALL}") |
| 112 | |
| 113 | def printd_user_message(icon, msg): |
| 114 | return print_user_message(icon, msg) |
| 115 | |
| 116 | if not (raw or dump or debug): |
| 117 | # we do not want to repeat the message in normal use |
| 118 | return |
| 119 | |
| 120 | if isinstance(msg, str): |
| 121 | if raw: |
| 122 | printd_user_message("", msg) |
| 123 | return |
| 124 | else: |
| 125 | try: |
| 126 | msg_json = json_loads(msg) |
| 127 | except (ValueError, TypeError): |
| 128 | printd(f"{CLI_WARNING_PREFIX}failed to parse user message into json") |
| 129 | printd_user_message("", msg) |
| 130 | return |
| 131 | if msg_json["type"] == "user_message": |
| 132 | if dump: |
| 133 | print_user_message("", msg_json["message"]) |
| 134 | return |
| 135 | msg_json.pop("type") |
| 136 | printd_user_message("", msg_json) |
| 137 | elif msg_json["type"] == "contine_chaining": |
| 138 | if debug: |
| 139 | msg_json.pop("type") |
| 140 | printd_user_message("", msg_json) |
| 141 | elif dump: |
| 142 | print_user_message("", msg_json) |
| 143 | return |
| 144 | |
| 145 | elif msg_json["type"] == "system_message": |
| 146 | msg_json.pop("type") |
| 147 | printd_user_message("", msg_json) |
| 148 | else: |
| 149 | printd_user_message("", msg_json) |
| 150 | |
| 151 | @staticmethod |
| 152 | def function_message(msg: str, msg_obj: Optional[Message] = None, debug: bool = DEBUG): |
no test coverage detected