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

Magic command defaults upgrade + delete messages #566

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

richawo
Copy link
Contributor

@richawo richawo commented Sep 30, 2023

The problem:

Magic commands previously saved to and overwrote message.json by default. The problem is:

  1. You want to save messages quickly, but you don't necessarily want it to overwrite.
  2. The name message.json is uninformative - you know nothing about the contents.
  3. The message JSONs are also small, so storing multiple past conversations easily outweighs the cons.

Relevant issue

Fixes #564

The Fix:

  1. Updated the save name convention to be [date]_messages_[counter].json when no path is provided.
  2. Loads the latest message [date]_messages_[counter].json when no path is provided.
  3. Added %delete_messages to let you clean up historical messages, which accepts a parameter (for the number of files you wish to preserve) - or deletes everything except the most recent file by default.
  4. Updated the handle_help function to reflect the changes.

With this approach, you can still save the messages quickly without overwriting. The names also include the date so you're able to get more information about the file (albeit nothing too in-depth). If you wish to clear out previous messages, you can also do that now too.

Testing

  • [ ✅] I have performed a self-review of my code:

I have tested the code on the following OS:

  • Windows
  • [✅ ] MacOS
  • Linux

AI Language Model (if applicable)

N/A

@richawo
Copy link
Contributor Author

richawo commented Sep 30, 2023

Took a look, no reason for builds to fail. None of my code touches the interpreter logic - purely magic commands.

I've also tested it, and all works fine. Having looked through some other PRs (open and closed) seems to be a recurring issue.

@richawo
Copy link
Contributor Author

richawo commented Sep 30, 2023

image

Evidence of testing

Comment on lines +34 to +35
- Add your `OPENAI_API_KEY` environment variable to the repository secrets to make sure your tests can pass.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be removed as it's a bit confusing, and will likely lead to folks opening Issues or reaching out in the Discrd because they are trying to add their own OpenAI keys to a repo that they don't have access to the Environment Variables for - and I don't think anyone is running the actions on their own forks of the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, I thought it was the reason for the failing tests initially but I realised it wasn't. Will delete.

Would be good to get to the bottom of it more generally since it's a recurring issue..

Comment on lines +43 to +44
"%save_message [path]": "Saves messages to a specified JSON path. If no path is provided, it defaults to '[date]_messages_[counter].json'.",
"%load_message [path]": "Loads messages from a specified JSON path. If no path is provided, it loads the latest default message '[date]_messages_[counter].json'.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor rendering thing, but I think the underscores (_) here need to be escaped with \_ or they try to render as markdown and end up italicized.

Before escaping underscores in filenames

Screen Shot 2023-10-08 at 11 55 58 AM

With filename underscores escaped in %load_message help text

Screen Shot 2023-10-08 at 11 57 15 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot - will update!

"%load_message [path]": "Loads messages from a specified JSON path. If no path is provided, it defaults to 'messages.json'.",
"%save_message [path]": "Saves messages to a specified JSON path. If no path is provided, it defaults to '[date]_messages_[counter].json'.",
"%load_message [path]": "Loads messages from a specified JSON path. If no path is provided, it loads the latest default message '[date]_messages_[counter].json'.",
"%delete_message [number]": "Deletes saved messages, preserving the most recent 'number' files. If no number is provided, it deletes all but the most recent file.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%delete_message didn't seem to work. Maybe because it's defined as delete_messages on line 148 in the handle_magic_command() method?

Screen Shot 2023-10-08 at 12 02 04 PM

Also, it seems like %delete_message should require a path rather than potentially deleting multiple files when called without an argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it should be %delete_messages, and will make it so that you can supply a folder or file.

@ericrallen
Copy link
Collaborator

Overall, I really like this change. It's a solid improvement on storing and retrieving conversation threads. Nice work!

I wonder if we should use the same path that the user's config.yaml gets stored in if they don't provide a path - rather than polluting whatever current directory they were in when they initiated interpreter

I believe getting the correct directory for the user's config.yaml file is handled in interpreter/utils/get_config.py and we could use similar logic or extract that path creation into a separate utility that this functionality can import, too.

@richawo
Copy link
Contributor Author

richawo commented Oct 8, 2023

I wonder if we should use the same path that the user's config.yaml gets stored in if they don't provide a path - rather than polluting whatever current directory they were in when they initiated interpreter

I believe getting the correct directory for the user's config.yaml file is handled in interpreter/utils/get_config.py and we could use similar logic or extract that path creation into a separate utility that this functionality can import, too.

Yeah, I'm happy to extract this out if we're re-using the logic across multiple places.

@ericrallen
Copy link
Collaborator

@richawo I think just making the update so that %delete_messages works and resolving the most recent merge conflicts would be enough, and we can look at abstracting the common functionality out into a utility in a separate PR.

Thanks for taking this one on!

@richawo
Copy link
Contributor Author

richawo commented Oct 23, 2023

@ericrallen, hey, I'll sort it out shortly! Sorry, I've been distracted by too many projects lately 😅

@ericrallen
Copy link
Collaborator

No worries, @richawo.

I just wanted to revisit this one because I think it's a nice quality-of-life improvement.

Happy to help with the resolution of Merge Conflicts, too. I know sometimes they can get a bit tricky after so many changes have been made since a PR started.

@MikeBirdTech
Copy link
Collaborator

Hi @richawo
Any desire to revive this PR? Or should I close it?
Thanks!

@richawo
Copy link
Contributor Author

richawo commented Mar 21, 2024

Haha I really should, still not fixed right?

@MikeBirdTech
Copy link
Collaborator

@richawo
haha even though a lot has changed, it still defaults to messages.json if no path is provided.

Let me know if you have any questions or any other ideas for how to improve magic commands!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Messages shouldn't overwrite by default
3 participants