应用出现错误信息
Unable to create instance of class dev.ai4j.openai4j.chat.ChatCompletionResponse when trying to execute OpenAiChatModel's generate method.
- 这个错误仅出现在Wildfly Web服务器上。*
java.lang.RuntimeException: java.lang.RuntimeException: Unable to create instance of class dev.ai4j.openai4j.chat.ChatCompletionResponse. Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.
at deployment.Learnjee-1.0-SNAPSHOT.war//dev.langchain4j.internal.RetryUtils$RetryPolicy.withRetry(RetryUtils.java:195)
at deployment.Learnjee-1.0-SNAPSHOT.war//dev.langchain4j.internal.RetryUtils.withRetry(RetryUtils.java:229)
at deployment.Learnjee-1.0-SNAPSHOT.war//dev.langchain4j.model.openai.OpenAiChatModel.generate(OpenAiChatModel.java:176)
at deployment.Learnjee-1.0-SNAPSHOT.war//dev.langchain4j.model.openai.OpenAiChatModel.generate(OpenAiChatModel.java:126)
at deployment.Learnjee-1.0-SNAPSHOT.war//dev.langchain4j.model.chat.ChatLanguageModel.generate(ChatLanguageModel.java:39)
at deployment.Learnjee-1.0-SNAPSHOT.war//dev.langchain4j.model.chat.ChatLanguageModel.generate(ChatLanguageModel.java:27)
at deployment.Learnjee-1.0-SNAPSHOT.war//org.example.Main.doGet(Main.java:27)
Caused by: java.lang.UnsupportedOperationException: Cannot allocate class dev.ai4j.openai4j.chat.ChatCompletionResponse. Usage of JDK sun.misc.Unsafe is enabled, but it could not be used. Make sure your runtime is configured correctly.
at deployment.Learnjee-1.0-SNAPSHOT.war//com.google.gson.internal.UnsafeAllocator$4.newInstance(UnsafeAllocator.java:117)
at deployment.Learnjee-1.0-SNAPSHOT.war//com.google.gson.internal.ConstructorConstructor$19.construct(ConstructorConstructor.java:370)
... 60 more
- LangChain4j版本:0.31.0
- 使用的LLM(s):OpenAI
- Java版本:17
- Jakarta EE版本:10
- Wildfly版本:32.0.1
根据初步调查,我怀疑访问sun.misc.Unsafe的Gson库可能在部署到Wildfly Web服务器时被禁用。
参考:https://stackoverflow.com/questions/78396851/why-does-langchain4j-openai-api-breaks-while-using-in-a-jakarta-ee-rest-web-app
2条答案
按热度按时间3wabscal1#
感谢jawaharbabus的报告!顺便说一下,我们计划很快从Gson迁移到Jackson。
68de4m5k2#
我相信切换到Jackson可以解决这个问题。