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

Missing escape of backslashes in prompt.sub #83

Closed
assaftibm opened this issue Jul 8, 2023 · 3 comments
Closed

Missing escape of backslashes in prompt.sub #83

assaftibm opened this issue Jul 8, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@assaftibm
Copy link
Member

assaftibm commented Jul 8, 2023

Version Information

  • Package Version: 0.1.19
  • Operating System: MacOS 13.3.1

What is the expected behavior?

Support for backslashes in prompt field values

What is the actual behavior?

Backslashes are unsupported

Please provide a unit test that demonstrates the bug.

  prompt = PromptPattern.from_str("{{context}}\nquestion: {{question}}\nanswer:")
  prompt.sub("context", "Copy the file to \Conf")

Other notes on how to reproduce the issue?

The above code causes re.sub() to raise an exception as it attempts to interpret the \C as a regex meta-character.
The user isn't aware of prompt.sub() using re.sub() so he/she is not aware of the need to escape backslashes.

Any possible solutions?

In prompt_template.py, line 204, add escaping of backslashes as described at the bottom of the documentation of re.escape() in the Python docs .

This means that line 204:

        self.dump = re.sub(pattern, value, prompt)

Should be changed into:

        self.dump = re.sub(pattern, value.replace('\\', r'\\'), prompt)

Can you identify the location in the GENAI source code where the problem exists?

In prompt_template.py, line 204

If the bug is confirmed, would you be willing to submit a PR?

Yes

@onkarbhardwaj
Copy link
Contributor

@assaftibm : Thanks for your willingness to submit a PR! Assigning this issue to you. Our guidelines are here: link

@assaftibm
Copy link
Member Author

@onkarbhardwaj I created the PR. Thanks.

@Tomas2D Tomas2D added the enhancement New feature or request label Sep 1, 2023
@Tomas2D
Copy link
Member

Tomas2D commented Sep 11, 2023

Released in v0.2.6 🚀

Thanks! 🥇

@Tomas2D Tomas2D closed this as completed Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants