-
Notifications
You must be signed in to change notification settings - Fork 44.5k
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
update_file method to change occurences of text in a file #3643
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
I am all in when it comes to formalizing these things, but I have seen it use CLI editors like sed/awk and perl to edit existing files in a rather clever way, at least on *nix. So this may boil down to the OS in use. Note that one recurring "issue" reported frequently on the issue tracker is that Auto-GPT starts interactive editors like vim/nano or joe to edit stuff - so it's definitely trying to do the right thing. Merely failing at NOT using interactive apps, and failing at knowing more about the OS in question, and the tooling/version numbers available. On a Linux system, if augment the shell_execute description to add a corresponding constraint, you will definitely see much better results. Then again, like I said, using a dedicated update_file/edit_file command sounds definitely like a good idea, and it would also be the right place to encode preference for CLI tools like sed/awk there.
not having looked at the code/patch in question, I find that rather limited if that's indeed what it is doing. |
@Boostrix, I found that on a windows system, autogpt is not able to use any programs the right way afaik. Yes it is a basic function, but we need to start somewhere and keep updates atomized. |
For cross-platform file editing functionality similar to sed and awk, you can use Python's built-in string manipulation and regular expression modules: re, along with its file I/O functions. |
@Boostrix would you care to help me adjust it? i am not that known to all the python packages yet and am learning a lot from help provided. |
assuming that you have access to GPT, you can probably just copy your changes and ask it to adapt those to use the Python "re" module instead - it's a fairly self-contained change since your code is already using the re module. |
It is already using re, so I will try to adjust it. I have access to gpt but only 3.5 |
@Boostrix I tried chat gpt, but it comes up with the same code constantly only changing re.finditer to re.sub. I don't think this is what you meant 😅. |
…ccurences of specified text
function changed to use re for cross_platform compatibilty |
my 2c: I still believe having a lower-level function to run a regex on an input/file analogous to sed/awk would be more powerful and more general, higher level functions like "replace_text" could be built on top of this, simply by invoking the regex command. The "workhorse" portion of this code should not be replacing a text in a file, but it should be running a regex - so that other, higher level, command would simply specify the regex/file name to be used when invoking this. Don't get me wrong, this is great and useful "as is" - but it could be MUCH more useful by using the regex/file approach - also to edit stuff in place. |
@Boostrix I will take a look, but could use some help as my programming skills are not up-to-date yet |
I would not expend any time/effort on this, unless others agree with my opinion. The search/replace would then be built on top of your regex command, which would then be much simpler/shorter |
@Boostrix great new coding experience for me to look into that, but for now I hope someone can review this so it can be implemented or so I know what to change. I can change it when I have new code ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code mostly looks fine. But the question remains: does this work in practice? Do you have a demo/log/example showing that the bot can use this command effectively, and that it adds significant value over the existing available file operations?
Executing file '/app/autogpt/auto_gpt_workspace/retrieve_ticker_data.py'
as an example that is running as we speak |
…-GPT into pr/bfalans/3643
Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly. |
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request. |
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
Deployment failed with the following error:
|
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
Deployment failed with the following error:
|
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size |
Deployment failed with the following error:
|
Resubmission of #3643 --------- Co-authored-by: Reinier van der Leer <[email protected]>
Background
Auto-gpt is not able to edit files, the addtion of an update_file method would tackle this issue
old PR: #3464
Changes
addition of an update_file method that can change one or all occurences of specified text
Documentation
Inline documentation provided for the function
Test Plan
2 tests written in unittest Test_file_operations.py and verified
PR Quality Checklist