open-interpreter icon indicating copy to clipboard operation
open-interpreter copied to clipboard

Added the Ability to edit the code before running it.

Open Eliaskhal opened this issue 1 year ago • 2 comments

Now the user can edit the code before running it. OI does not keep track of previous code (before it was edited).

What I did exactly:

  • Instead of just asking the user if they want to run the code or not, I added a while loop that keeps on asking if they want to run the code or edit it. The purpose of using the loop is to give the user the ability to re-edit the code until they are satisfied.
  • When the user chooses to edit the code, the code gets saved in a temp file that is opened in "VS Code". After the user is done editing, they can type any character into the terminal and the "code" variable will be changed.

Possible Improvements:

  • The code before it's edited is not saved in the message history.
  • It would be better if all previous versions of the code were saved so the user can go back to each one if they want to.

NOTE:

I haven't been able to test the code since I had problems running it even though I have followed the documentation.

Check List:

  • [ ] I have included relevant documentation updates (stored in /docs)
  • [x] I have read docs/CONTRIBUTING.md
  • [x] I have read docs/ROADMAP.md

Tests:

  • [ ] Tested on Windows
  • [ ] Tested on MacOS
  • [ ] Tested on Linux

Eliaskhal avatar Jan 17 '24 12:01 Eliaskhal

I also think it would be a good idea to give the user the ability to choose their favorite editor by asking them once the first time they want to edit a code.

Eliaskhal avatar Jan 17 '24 12:01 Eliaskhal

https://github.com/KillianLucas/open-interpreter/pull/830 Here is a similar PR, but outdated

Notnaton avatar Jan 17 '24 19:01 Notnaton

Hi @Eliaskhal!

This is going to be such a useful feature. I think this is close, but I want to approach it in a slightly different place.

My main edit: I think it's too much to ask the user if they want to edit every code block, especially to insert it into a familiar (y/n) ask. I think edit is much more similar to the other %magic commands (%shell is very similar to edit, in that it lets you type and run code) than to the central OI concept of running code (which putting it below every code block, as this does, would imply).

I'm happy to merge if it can be converted to a magic command with the flow outlined here, otherwise I'll merge once this feature becomes my priority, then I'll convert it into a magic command.

Also it's worth noting that we do store the file extension for the code, so if you interpreter.computer.terminal.get(language).file_extension you can retrieve the proper file extension, allowing you to open it in the user's default editor.

Great work on building the feature. I'm personally very excited to use this, and your PR works incredibly well.

KillianLucas avatar Jan 18 '24 06:01 KillianLucas

Hey @KillianLucas, I did not notice your comment and I ended up adding what @Notnaton suggested. I would be more than happy to use your idea. My only problem is that I am still having issues understanding how everything is architected in the project.

I understand OI has a message history and magic commands. If you don't mind, could you please explain a bit about how those messages are stored? and where does the user type the magic command exactly?

Eliaskhal avatar Jan 18 '24 10:01 Eliaskhal

I think I was able to figure it out. I added the magic command and it works now. I will close this request and start a new one. Thank you!

Eliaskhal avatar Jan 18 '24 12:01 Eliaskhal