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

TypeError: a bytes-like object is required, not 'str' #354

Closed
KevinGeLe opened this issue Dec 10, 2023 · 7 comments
Closed

TypeError: a bytes-like object is required, not 'str' #354

KevinGeLe opened this issue Dec 10, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@KevinGeLe
Copy link

GPT-Pilot (commit): 930
OS: Ubuntu 22.04
Python: 3.9

image

Wouldn't it be easier to just check if it was an object or a string. Instead of just halting?

@senko senko added the bug Something isn't working label Dec 11, 2023
@senko
Copy link
Contributor

senko commented Dec 11, 2023

This should always be a string, so the fact this crashed means there's a bug somewhere else in the code that calls this. Did the project (where this crashed) have non-text files (eg. images, favicons, zip files, stuff like that)?

@KevinGeLe
Copy link
Author

This should always be a string, so the fact this crashed means there's a bug somewhere else in the code that calls this. Did the project (where this crashed) have non-text files (eg. images, favicons, zip files, stuff like that)?

It only had .js and .db from sqlite3. The database wasnt corrupt as i could navigate the tables and .js runs without error. But gpt-pilot had some problems where it did not create the .db the first few tries.

@notnitsuj
Copy link

I'm having the same issue. Looking into the workspace directory, I can see that it has created some non-text files like webpack and some in node_modules. How can I deal with this?

Screenshot from 2023-12-12 00-46-40

@kingshah13
Copy link

me too

@clickbrain
Copy link

clickbrain commented Dec 13, 2023

Just got the same error after I believe 19 dev steps. Also, when I go back to try to run it again using the path stipulated from beginning of the run, get the same error.

Traceback (most recent call last):
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/main.py", line 77, in
project.start()
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/Project.py", line 141, in start
self.developer.start_coding()
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/agents/Developer.py", line 65, in start_coding
self.implement_task(i, dev_task)
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/agents/Developer.py", line 112, in implement_task
result = self.execute_task(convo_dev_task,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/agents/Developer.py", line 399, in execute_task
result = self.step_command_run(convo, step, i, success_with_cli_response=need_to_see_output)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/agents/Developer.py", line 194, in step_command_run
return run_command_until_success(convo, data['command'],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/cli.py", line 509, in run_command_until_success
success = convo.agent.debugger.debug(convo, {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/Debugger.py", line 75, in debug
result = self.agent.project.developer.execute_task(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/agents/Developer.py", line 424, in execute_task
result = self.step_test(convo, test_command)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/agents/Developer.py", line 258, in step_test
should_rerun_command = convo.send_message('dev_ops/should_rerun_command.prompt', test_command)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/AgentConvo.py", line 85, in send_message
self.replace_files()
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/AgentConvo.py", line 192, in replace_files
msg['content'] = self.replace_file_content(msg['content'], f"{file['path']}/{file['name']}", file['content'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/AgentConvo.py", line 219, in replace_file_content
new_content_escaped = self.escape_specials(new_content)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bradn/Documents/AI/gptpilot/gpt-pilot/pilot/helpers/AgentConvo.py", line 195, in escape_specials
s = s.replace("\", "\\")
^^^^^^^^^^^^^^^^^^^^^^^
TypeError: a bytes-like object is required, not 'str'

@clickbrain
Copy link

Per #363 I didn't send any files to the LLM and got this message. Anything having to do with binary files was generated by. gptpilot if that was the cause, but I don't think it was.

@dsitnik
Copy link

dsitnik commented Dec 15, 2023

@clickbrain @senko
I changed the function escape_specials in AgentConvo and it fixed the issue for me. I don't know what could be causing the error.

    def escape_specials(self, s):
        try:
            # Try decoding with utf-8
            if isinstance(s, bytes):
                s = s.decode('utf-8')
        except UnicodeDecodeError:
            try:
                # Try another encoding if UTF-8 fails
                s = s.decode('iso-8859-1')
            except UnicodeDecodeError:
                # Handle cases where decoding fails
                s = s.decode('utf-8', errors='replace')
        s = s.replace("\\", "\\\\")

        # List of sequences to preserve
        sequences_to_preserve = [
            # todo check if needed "\\\\",  # Backslash - note: probably not eg. paths on Windows
            "\\'",  # Single quote
            '\\"',  # Double quote
            # todo check if needed '\\a',  # ASCII Bell (BEL)
            # todo check if needed '\\b',  # ASCII Backspace (BS) - note: different from regex \b
            # todo check if needed '\\f',  # ASCII Formfeed (FF)
            '\\n',  # ASCII Linefeed (LF)
            # todo check if needed '\\r',  # ASCII Carriage Return (CR)
            '\\t',  # ASCII Horizontal Tab (TAB)
            # todo check if needed '\\v'  # ASCII Vertical Tab (VT)
        ]

        for seq in sequences_to_preserve:
            s = s.replace('\\\\' + seq[-1], seq)
        return s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants