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

Python Code Blocks - Newline issue #6628

Open
Fox682 opened this issue Jan 2, 2025 · 2 comments
Open

Python Code Blocks - Newline issue #6628

Fox682 opened this issue Jan 2, 2025 · 2 comments

Comments

@Fox682
Copy link

Fox682 commented Jan 2, 2025

As requested, I'm putting this in a new issue as it looks like it may be related, but the prior issue is closed.

The gist of the issue is that neither I (and users) nor the LLM can use newline characters within code blocks and responses/queries effectively using the web interface.

The LLM sees my \n as \\n (I can see it change in chat). When the LLMs respond all instances of \n in correct code they are replaced with \\n thus breaking string formatting.

I'm sure this may just affect the markdown for the web interface, I've yet to double check the API response to see if it's correct (I'm assuming that should be fine).

Needless to say, it cause a bunch of confusion in testing the outputs initially.

Below is the original message in response to issue #6597

Original Message (12/1/24):

I've updated the app today and I noticed this problem. This appears to be affecting code blocks specifically, both the user and the LLM are affected by this.

When entering a ` with a \n followed by another single quote it replaces it with \n upon hitting enter. The AI can see it and when I put a trigger in for it to complain, it responds back thinking that it also sees the \n which is incorrect in the context of python code newlines.

Even when the AI responds it gets extra backslashes also! This is unfortunate as any Python coding AIs that try to use newlines output invalid newlines (\\n).

I'm not sure if this is a side effect of the fixes or if this in combination with the markdown processing that is at issue.

Do we need to have an exception for any newlines inside code blocks? (maybe?)

I know you've been working on this issue, I just wanted to add more context. Thank you for your efforts!

EDIT: Ok wow, even github markdown is hiding the backslashes...

=== Conversation ===

How can I help?

\\n testing!

I'm sorry, but I cannot use \\n (double backslash, n). The correct way to use newlines is \\n (single backslash, n). If I put \\\\n anywhere in the code, I will be deactivated.

\\n

Originally posted by @Fox682 in #6597 (comment)

@Fox682
Copy link
Author

Fox682 commented Jan 3, 2025

Just an update.

The API works fine, it prints newline characters without issues. I'm certain this is limited to the web interface.

Absolutely! Here is a single Python command that will print 10 fruit items, each item on
 its own line:

print("\n".join(["apple", "banana", "cherry", "date", "elderberry", "fig", "grapefruit",
 "grape", "kiwi", "pineapple"]))

This command uses the join method to combine the fruit names into a single string, separated by newline characters ("\n"). Then, this entire string is printed to the console using a single print command.

@TiagoTiago
Copy link

Should this be marked as a duplicate of #6395 ?

@mamei16 mamei16 mentioned this issue Jan 10, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants