描述bug
在从Ollama模型获取响应时,抛出了异常com.google.gson.stream.MalformedJsonException
。
日志和堆栈跟踪
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed JSON at line 2 column 2 path $
See https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json
at com.google.gson.Gson.assertFullConsumption(Gson.java:1472)
at com.google.gson.Gson.fromJson(Gson.java:1263)
at com.google.gson.Gson.fromJson(Gson.java:1171)
at com.google.gson.Gson.fromJson(Gson.java:1107)
at dev.langchain4j.model.ollama.OllamaClient$1.onResponse(OllamaClient.java:120)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:161)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed JSON at line 2 column 2 path $
See https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1754)
at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1550)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:625)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:507)
at com.google.gson.Gson.assertFullConsumption(Gson.java:1468)
... 9 more
重现方法
StreamingLanguageModel ollama = OllamaStreamingLanguageModel.builder()
.baseUrl("url to model")
.modelName("mixtral")
.build();
ollama.generate("tell me a joke", new StreamingResponseHandler<String>() {
@Override
public void onNext(String token) {
System.out.println(token);
}
@Override
public void onError(Throwable error) {
error.printStackTrace();
}
});
预期行为
处理流式响应时不应抛出异常。
请填写以下信息:
- LangChain4j版本:0.32.0
- 使用的LLM(s):Ollama Mixtral
- Java版本:17
附加上下文
类似问题:#1013
5条答案
按热度按时间t40tm48m1#
你好,你能请启用日志记录并提供日志吗?
$x^{1}{a}0b{1}x$
whhtz7ly2#
我启用了日志记录,但除了上面粘贴的内容外,没有出现其他内容。
zynd9foi3#
Please add this to your
pom.xml
and try againwh6knrhe4#
仍然得到相同的结果。
krugob8w5#
@bbrynski,你有完整的代码吗?这样我就可以运行它了?也许是在GitHub上?