(msg: str, msg_obj: Optional[Message] = None, debug: bool = DEBUG)
| 150 | |
| 151 | @staticmethod |
| 152 | def function_message(msg: str, msg_obj: Optional[Message] = None, debug: bool = DEBUG): |
| 153 | def print_function_message(icon, msg, color=Fore.RED, printf=print): |
| 154 | if STRIP_UI: |
| 155 | printf(f"{icon} [function] {msg}") |
| 156 | else: |
| 157 | printf(f"{color}{Style.BRIGHT}{icon} [function] {color}{msg}{Style.RESET_ALL}") |
| 158 | |
| 159 | def printd_function_message(icon, msg, color=Fore.RED): |
| 160 | return print_function_message(icon, msg, color, printf=(print if debug else printd)) |
| 161 | |
| 162 | if isinstance(msg, dict): |
| 163 | printd_function_message("", msg) |
| 164 | return |
| 165 | |
| 166 | if msg.startswith("Success"): |
| 167 | printd_function_message("", msg) |
| 168 | elif msg.startswith("Error: "): |
| 169 | printd_function_message("", msg) |
| 170 | elif msg.startswith("Ran "): |
| 171 | # NOTE: ignore 'ran' messages that come post-execution |
| 172 | return |
| 173 | elif msg.startswith("Running "): |
| 174 | if debug: |
| 175 | printd_function_message("", msg) |
| 176 | else: |
| 177 | match = re.search(r"Running (\w+)\((.*)\)", msg) |
| 178 | if match: |
| 179 | function_name = match.group(1) |
| 180 | function_args = match.group(2) |
| 181 | if function_name in [ |
| 182 | "archival_memory_insert", |
| 183 | "archival_memory_search", |
| 184 | "core_memory_append", |
| 185 | ]: |
| 186 | if function_name in [ |
| 187 | "archival_memory_insert", |
| 188 | "core_memory_append", |
| 189 | ]: |
| 190 | print_function_message("🧠", f"updating memory with {function_name}") |
| 191 | elif function_name == "archival_memory_search": |
| 192 | print_function_message("🧠", f"searching memory with {function_name}") |
| 193 | try: |
| 194 | msg_dict = eval(function_args) |
| 195 | if function_name == "archival_memory_search": |
| 196 | output = f"\tquery: {msg_dict['query']}, page: {msg_dict['page']}" |
| 197 | if STRIP_UI: |
| 198 | print(output) |
| 199 | else: |
| 200 | print(f"{Fore.RED}{output}{Style.RESET_ALL}") |
| 201 | elif function_name == "archival_memory_insert": |
| 202 | output = f"\t→ {msg_dict['content']}" |
| 203 | if STRIP_UI: |
| 204 | print(output) |
| 205 | else: |
| 206 | print(f"{Style.BRIGHT}{Fore.RED}{output}{Style.RESET_ALL}") |
| 207 | else: |
| 208 | if STRIP_UI: |
| 209 | print(f"\t {msg_dict['old_content']}\n\t→ {msg_dict['new_content']}") |
no test coverage detected