langchain4j icon indicating copy to clipboard operation
langchain4j copied to clipboard

[BUG] zhipu-ai response parse error

Open cslcsl490 opened this issue 1 year ago • 2 comments

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226) at com.google.gson.Gson.fromJson(Gson.java:932) at com.google.gson.Gson.fromJson(Gson.java:897) at com.google.gson.Gson.fromJson(Gson.java:846) at com.google.gson.Gson.fromJson(Gson.java:817)


dev.langchain4j.model.zhipu.DefaultZhipuAiHelper#aiMessageFrom if (content.startsWith("```json") && content.contains("{") && content.contains("}")) { return AiMessage.from(content.substring(content.indexOf("{"), content.lastIndexOf("}") + 1)); }

cslcsl490 avatar Apr 01 '24 06:04 cslcsl490

@langchain4j @1402564807

cslcsl490 avatar Apr 01 '24 06:04 cslcsl490

@cslcsl490 Hello! Could you please send me the calling example?

xermaor avatar Apr 01 '24 17:04 xermaor

@cslcsl490 Hello! Could you please send me the calling example?

 AiMessage { text = "```json
{
  "xxxx": "xxx"
} ```" toolExecutionRequests = null 

like this

cslcsl490 avatar Apr 07 '24 02:04 cslcsl490

content.lastIndexOf("}") + 1)

Hello, can you send the complete stack information and calling example? I couldn’t reproduce it through this simple example.

xermaor avatar Apr 09 '24 03:04 xermaor

I suspect this issue is not related specifically to ZhipuAI, it should be fixed for all LLM providers: https://github.com/langchain4j/langchain4j/issues/859

langchain4j avatar Apr 09 '24 07:04 langchain4j