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