OpenInterpreter / open-interpreter

A natural language interface for computers
http://openinterpreter.com/
GNU Affero General Public License v3.0
52.69k stars 4.66k forks source link

AI should be able to create files without interpreting Python #1466

Open endolith opened 3 weeks ago

endolith commented 3 weeks ago

Is your feature request related to a problem? Please describe.

The AI keeps going in circles:

  1. Uses Python interpreter to write code, gets it working
  2. I ask it to write that code to disk for later use.
  3. It uses Python interpreter to write a multiline string containing that python code to a .py file
  4. It screws up the newline escaping, resulting in this error:
      cleaned_coordinates = gps_coordinates.split('
                                                  ^
    SyntaxError: unterminated string literal (detected at line 12)
  5. It uses Python interpreter to look at the file it created:

    It appears that the newline handling issue remains unresolved in the integrated_scraping_and_export.py file. Let's check the contents of
    the file again to identify the exact error and correct it properly. I'll read the file now.
    
    # Read the contents of the integrated_scraping_and_export.py to check the source for issues
    with open('integrated_scraping_and_export.py', 'r') as file:
      contents = file.read()
    
    contents
  6. It identifies the escaping error and fixes it.
  I will adjust this line to use the correct escape sequence for the newline character, changing it to:

   cleaned_coordinates = gps_coordinates.split('\\n')[0].strip()
  # Write the fixed integrated script code to the .py file
  with open('integrated_scraping_and_export.py', 'w') as file:
      file.write(final_fixed_full_integrated_script)
  1. It finally works

Describe the solution you'd like

However the AI is able to call commands or call python code (function calling?) should be extended so that it can also read and write files directly, without using the Python interpreter as an intermediate step. Probably should be able to see hex dumps or other representations of files too.

Describe alternatives you've considered

No response

Additional context

No response

bobemoe commented 4 hours ago

I have similar issue but it is trying to create files using bash cat wheredoc and there is a bug preventing this working. #1485

While your issue with the escaping and my issue with the malformed file should still be resolved seperatly I think direct file access would be a great feature to avoid these kind methods to create a new file.

I'm not sure if your issue is a bug with interpreter or just the ai not getting the code right. Have you tried adding instruction to your prompt on how to create files using correct escaping? I added instruction to mine not to use heredoc so it now avoids that method.