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

[Question]: Unexpected Escaping of Characters (Whitespace, Hyphen, etc.) Due to re.escape() in New Version in generate.py #2716

Open
marcochang1028 opened this issue Oct 4, 2024 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@marcochang1028
Copy link

Describe your problem

In the latest version of the code in the agent/componment/generate.py, I noticed that the usage of re.escape() was introduced in the following line:
prompt = re.sub(r"{%s}" % n, re.escape(str(v)), prompt)

This results in unwanted behavior where characters like whitespace (" "), hyphen ("-"), and other symbols are unnecessarily escaped, adding additional backslashes (""). In the previous version of the code, this issue did not exist, as the line used to be:
prompt = re.sub(r"{%s}" % n, str(v), prompt)

I am wondering what was the reason for adding re.escape() in the new version? Was it to address a specific issue?

@marcochang1028 marcochang1028 added the question Further information is requested label Oct 4, 2024
@KevinHuSh
Copy link
Collaborator

I think it should be this:

prompt = re.sub(r"{%s}" % re.escape(n), str(v), prompt)

@marcochang1028
Copy link
Author

I think it should be this:

prompt = re.sub(r"{%s}" % re.escape(n), str(v), prompt)

I have tried. It works. Thank you for your great help.
I think it need to be updated in the new version.

@KevinHuSh KevinHuSh mentioned this issue Oct 8, 2024
1 task
KevinHuSh added a commit that referenced this issue Oct 8, 2024
### What problem does this PR solve?

#2716

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
Halfknow pushed a commit to Halfknow/ragflow that referenced this issue Nov 11, 2024
### What problem does this PR solve?

infiniflow#2716

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants