dougollerenshaw / CodeAIde

A tool for interactively building and running code with AI
MIT License
1 stars 1 forks source link

text encoding problem. #27

Open zhuangjun1981 opened 6 hours ago

zhuangjun1981 commented 6 hours ago

Looks like the console and the interpreter cannot accommodate some of the characters generated by the language model.

==============================================

Example1: if I ask the assistant a Chinese question, it will return useful code but the console cannot display the response correctly. image

==============================================

Example 2: if I ask "User: please plot a sine wave and cosine wave superimposed on each other. " the code it generated contains special character "pi", such as

# Create x values from 0 to 2π

And the interpreter will spit out an error:

SyntaxError: Non-UTF-8 code starting with '\xa6' in file C:\Users\wood_\PycharmProjects\CodeAIde\generated_code\generated_script_1.0.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Looks like the character π is the source of the issue.

dougollerenshaw commented 5 hours ago

Thanks @zhuangjun1981! I tried your prompt from example 2 in the latest version of main and didn't see any issue:

image

It generates this:

image

I also tried using the chinese equivalent to that prompt (assuming the Claude translation is correct!!). Here's what I got:

image

The code itself would need some work since it seems like matplotlib can't render the chinese characters. But that could probably be solved with some back and forth with the LLM. Here's what the v1.0 code generates:

image

I think some recent changes I made may have solved the JSON parsing issues. Could you try pulling the latest version of main and see if the issue persists for you?

zhuangjun1981 commented 5 hours ago

Aha, in the new version, the console display problem is fixed. But the special character in the script is still causing problem.

SyntaxError: Non-UTF-8 code starting with '\xc9' in file C:\Users\wood_\PycharmProjects\CodeAIde\generated_code\generated_script_1.0.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Script execution completed.
Script execution completed. You can close this window.

If I open the generated script in sublime text, it looks like this: image

Does it mean that my system is missing the encoder?

dougollerenshaw commented 5 hours ago

How did you get the code to sublime text?

I just entered the two prompts you supplied above. Here's my chat window:

image

Both provided readable code in the CodeAIde code popup. Here's what the chinese prompted code looks like:

image

I hit the "copy code" button and pasted it into Sublime. It rendered the chinese comments there:

image

Then I hit the "save code" button and saved it as test.py and opened that in sublime. That rendered correctly as well:

image

Can you share a screenshot of the code as it was displayed in your CodeAIde code popup?