Pythagora-io / gpt-pilot

The first real AI developer
Other
30.82k stars 3.09k forks source link

[BUG]: GPT Pilot Exiting with Error #509

Open PierrunoYT opened 9 months ago

PierrunoYT commented 9 months ago

Version

VisualStudio Code extension

Operating System

Windows 11

What happened?

Traceback (most recent call last):

File "c:\Users\pierr\gpt-pilot\pilot\main.py", line 79, in project.start()

File "c:\Users\pierr\gpt-pilot\pilot\helpers\Project.py", line 141, in start self.developer.start_coding()

File "c:\Users\pierr\gpt-pilot\pilot\helpers\agents\Developer.py", line 70, in start_coding self.implement_task(i, dev_task)

File "c:\Users\pierr\gpt-pilot\pilot\helpers\agents\Developer.py", line 91, in implement_task convo_dev_task.send_message('development/task/breakdown.prompt', {

File "c:\Users\pierr\gpt-pilot\pilot\helpers\AgentConvo.py", line 111, in send_message self.log_message(message_content)

File "c:\Users\pierr\gpt-pilot\pilot\helpers\AgentConvo.py", line 246, in log_message print(f"\n{content}\n", type='local')

File "c:\Users\pierr\gpt-pilot\pilot\utils\custom_print.py", line 16, in print_to_external_process local_print(*args, **kwargs)

File "c:\Users\pierr\gpt-pilot\pilot\utils\custom_print.py", line 33, in local_print built_in_print(message, **kwargs)

File "c:\Users\pierr\gpt-pilot\pilot-env\Lib\site-packages\colorama\ansitowin32.py", line 47, in write self.__convertor.write(text)

File "c:\Users\pierr\gpt-pilot\pilot-env\Lib\site-packages\colorama\ansitowin32.py", line 177, in write self.write_and_convert(text)

File "c:\Users\pierr\gpt-pilot\pilot-env\Lib\site-packages\colorama\ansitowin32.py", line 205, in write_and_convert self.write_plain_text(text, cursor, len(text))

File "c:\Users\pierr\gpt-pilot\pilot-env\Lib\site-packages\colorama\ansitowin32.py", line 210, in write_plain_text self.wrapped.write(text[start:end])

File "C:\Users\pierr\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

UnicodeEncodeError: 'charmap' codec can't encode characters in position 876-878: character maps to

senko commented 8 months ago

One possible workaround discovered by @PierrunoYT (thanks!):

Modify gpt-pilot\pilot\utils\custom_print.py:

  1. At the top of the file, add import sys as the first line
  2. In line 33, replace this:

            built_in_print(message, **kwargs)

    with

            sys.stdout.buffer.write((message + "\n").encode("utf-8"))
senko commented 8 months ago

This is likely caused by https://github.com/tartley/colorama/issues/219

senko commented 8 months ago

@PierrunoYT @someaka @Bengan1 how did you install Python on your machine, and which version of Python do you have?

Eg. from Microsoft Store, download from Python.org, Anaconda, or some other way?

senko commented 8 months ago

For context: if the Python installation is using encoding other than "utf-8" for its stdout, colorama will fail with the above message because the encoding in question doesn't support emojis/symbols.

What makes it strange is that Python 3.7+ should use UTF-8 by default on Windows. I tested this with both Python downloaded from MS Store (3.12.1) and Python.org website (3.12.0). Both were using UTF-8 by default.

senko commented 8 months ago

Another potential fix is replacing this:

https://github.com/Pythagora-io/gpt-pilot/blob/21eb28ff1b5fa38c2f921d01df7933f69b2dd0bc/pilot/utils/style.py#L6

with:

colorama.just_fix_windows_console()

which, hopefully, is less intrusive and won't trigger the problem (relevant info from colorama README).

karolsowi commented 6 months ago

Applied both workarounds and it worked.