Closed anyangml closed 10 months ago
Answer generated by a š¤
I understand that you're encountering an issue with the FewShotPromptTemplate
in LangChain. Specifically, the curly brackets in your LaTeX string are being interpreted as keys to a dictionary, which is causing a KeyError
.
The problem arises from Python's built-in string formatting mechanism. When you use curly braces {}
in a string that you're formatting with the format
method, Python interprets anything inside the braces as a variable to be replaced. In your LaTeX string \sum_{i=1}^{n}
, Python is interpreting i=1
and n
as variables, which are not defined in your code.
One potential solution to this issue is to escape the curly braces in your LaTeX string by doubling them. Here's how you can modify your code:
examples = [
{
"latex": """\\sum_{{i=1}}^{{n}}""",
"doc": """taking sum from 1 to n"""
}
]
By doubling the curly braces, you're instructing Python to treat them as literal characters in the string, rather than as placeholders for variables.
Please note that this is one potential solution, and there might be other ways to address this issue. If you believe this is a bug that could impact other users, you're encouraged to make a pull request with a proposed fix.
If this solution doesn't align with your experience, or if the issue persists, I recommend upgrading to the latest version of LangChain to ensure you have all the recent updates and bug fixes.
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a š if this is helpful and š if it is irrelevant.
Hi, @anyangml! I'm Dosu, and I'm helping the LangChain team manage our backlog. I wanted to let you know that we are marking this issue as stale.
Based on the information provided, it seems that you reported an issue with the Langchain library's FewShotPromptTemplate
not correctly interpreting curly brackets in a LaTeX string. You received a response from me explaining that the issue arises from Python's string formatting mechanism and suggesting a potential solution of escaping the curly braces by doubling them. My response also recommends upgrading to the latest version of LangChain and making a pull request if the issue persists.
Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.
Thank you for your contribution to the LangChain repository!
System Info
Version
Context
I am trying build a prompt that convert latex string generated by an OCR algo to a text describing that latex. When using the
FewShotPromptTemplate
, the curly brackets in the latex string are somehow interpreted as key to a dict.Who can help?
@hwchase17
Information
Related Components
Reproduction
Code
Expected behavior
Error
The PromptTemplate.format works fine, but the FewShotPromptTemplate fails.