Skip to content

Commit

Permalink
Better interface output for function calls (#296)
Browse files Browse the repository at this point in the history
Co-authored-by: Charles Packer <packercharles@gmail.com>
  • Loading branch information
vivi and cpacker authored Nov 6, 2023
1 parent 8698112 commit 236f3db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
5 changes: 4 additions & 1 deletion memgpt/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,10 @@ async def handle_ai_response(self, response_message):

# If no failures happened along the way: ...
# Step 4: send the info on the function call and function response to GPT
await self.interface.function_message(f"Success: {function_response_string}")
if function_response_string:
await self.interface.function_message(f"Success: {function_response_string}")
else:
await self.interface.function_message(f"Success")
messages.append(
{
"role": "function",
Expand Down
33 changes: 18 additions & 15 deletions memgpt/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ def printd_function_message(icon, msg, color=Fore.RED):
printd_function_message("", msg)
return

if msg.startswith("Success: "):
if msg.startswith("Success"):
printd_function_message("🟢", msg)
elif msg.startswith("Error: "):
printd_function_message("🔴", msg)
elif msg.startswith("Running "):
if debug:
printd_function_message("", msg)
else:
if "memory" in msg:
match = re.search(r"Running (\w+)\((.*)\)", msg)
if match:
function_name = match.group(1)
function_args = match.group(2)
match = re.search(r"Running (\w+)\((.*)\)", msg)
if match:
function_name = match.group(1)
function_args = match.group(2)
if "memory" in function_name:
print_function_message("🧠", f"updating memory with {function_name}")
try:
msg_dict = eval(function_args)
Expand All @@ -138,23 +138,26 @@ def printd_function_message(icon, msg, color=Fore.RED):
if STRIP_UI:
print(output)
else:
print(f"{Fore.RED}{output}")
print(f"{Fore.RED}{output}{Style.RESET_ALL}")
elif function_name == "archival_memory_insert":
output = f'\t{msg_dict["content"]}'
if STRIP_UI:
print(output)
else:
print(f"{Style.BRIGHT}{Fore.RED}{output}{Style.RESET_ALL}")
else:
if STRIP_UI:
print(f'\t {msg_dict["old_content"]}\n\t{msg_dict["new_content"]}')
else:
print(f'{Style.BRIGHT}\t{Fore.RED} {msg_dict["old_content"]}\n\t{Fore.GREEN}{msg_dict["new_content"]}')
print(
f'{Style.BRIGHT}\t{Fore.RED} {msg_dict["old_content"]}\n\t{Fore.GREEN}{msg_dict["new_content"]}{Style.RESET_ALL}'
)
except Exception as e:
printd(e)
printd(str(e))
printd(msg_dict)
pass
else:
printd(f"Warning: did not recognize function message")
printd_function_message("", msg)
elif "send_message" in msg:
# ignore in debug mode
pass
else:
printd(f"Warning: did not recognize function message")
printd_function_message("", msg)
else:
try:
Expand Down

0 comments on commit 236f3db

Please sign in to comment.