Skip to content

Commit

Permalink
Merge pull request #213 from ayushmorbar/main
Browse files Browse the repository at this point in the history
Add search functionality to magic_commands.py
  • Loading branch information
neokd authored Apr 5, 2024
2 parents 1b9fdcf + 0a4896d commit 66224a5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions neogpt/utils/magic_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,25 @@ def magic_commands(user_input, chain):
cprint("📚 /source - Prints the source directory")

return True

# If the user inputs '/search [keyword]', search the chat history for the keyword
elif user_input.startswith("/search"):
# Extract the keyword from the command
keyword = user_input.split(" ", 1)[1].strip().replace("'", "").replace('"', "")
# Create a flag to indicate if any messages are found
found = False
for message in chain.combine_documents_chain.memory.chat_memory.messages:
if keyword in message.content:
if isinstance(message, HumanMessage):
cprint(
f" [bright_yellow]{get_username()} [/bright_yellow]{message.content}"
)
else:
cprint(f" [bright_blue]NeoGPT: [/bright_blue]{message.content}")
found = True
if not found:
cprint(f"No messages found with the keyword '{keyword}'.")
return True

# If the command is not recognized, print an error message
else:
Expand Down

0 comments on commit 66224a5

Please sign in to comment.