-
Notifications
You must be signed in to change notification settings - Fork 682
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
[BUG] Unable to create custom PromptTemplate #1075
Comments
The To address this issue, you should:
If these steps do not resolve the issue, you might need to provide a custom initialization path for Android that avoids problematic static initialization or uses alternatives compatible with Android.
|
The root cause seems to be due to private static final Pattern VARIABLE_PATTERN = Pattern.compile("\{\{(.+?)}}"); Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 10 {{(.+?)}} ^ this is happening can u see why |
The Given that the regular expression is correctly defined, the issue might not be with the pattern's syntax. It could be related to other factors such as the execution environment, how the Java code is being run, or interactions with other parts of the code not shown in the snippet provided. To further diagnose the issue, consider isolating the regular expression in a minimal Java program to verify its behavior outside of the Android and LangChain4j context. This step can help determine if the problem lies with the regular expression handling in your specific environment or if it's an issue with the LangChain4j library or its integration with Android Q. If the regular expression works as expected in isolation, the next steps would involve a closer examination of the LangChain4j library's usage, especially around how
|
Hi @jayshetti, thanks a lot for reporting! I tried the |
Hi @langchain4j , Still the same issue after lot of debugging i can see that apk which i am building does not the have service PromptTemplateFactory under META-INF/services/. |
If you want to use the Can you provide code to reproduce this problem? I will be able to debug it then. |
|
Does this happen only in Android-Q? Can yo ureproduce it outside of Android? In plain Java |
@langchain4j If i use the regex present in the DefaultTemplate then I am encountering the issue, for Android regex should be This issue will not be there in the Java due to https://stackoverflow.com/a/45075252, and the current Prompttemplate will not work in Android. Do we have any work around for this? Would be really helpful if I can get any work around or fix for this, I have tried to create diff PromptTemplateFactory to by pass this issue but adding META-INF/Services is difficult task in Android. |
Well, if I understand it correctly, we can just add (unnecessary for java) escapes to both "}" in the regex. Feel free to do this change and open a PR |
Describe the bug
I am trying langchain4J in Android and Upon creation new PromptTemplate as below, I see exception java.lang.ExceptionInInitializerError
Log and Stack trace
java.lang.ExceptionInInitializerError
at dev.langchain4j.model.input.DefaultPromptTemplateFactory.create(DefaultPromptTemplateFactory.java:18)
at dev.langchain4j.model.input.DefaultPromptTemplateFactory.create(DefaultPromptTemplateFactory.java:14)
at dev.langchain4j.model.input.PromptTemplate.(PromptTemplate.java:62)
at dev.langchain4j.model.input.PromptTemplate.(PromptTemplate.java:51)
Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 10
{{(.+?)}}
^
To Reproduce
Just try to create the PromptTemplate
Expected behavior
PromptTemplate should be created.
Please complete the following information:
The text was updated successfully, but these errors were encountered: