Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better interface output for function calls #296

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading