quarkiverse / quarkus-langchain4j

Quarkus Langchain4j extension
https://docs.quarkiverse.io/quarkus-langchain4j/dev/index.html
Apache License 2.0
133 stars 79 forks source link

Ollama Illegal unquoted character #650

Closed humcqc closed 4 months ago

humcqc commented 4 months ago

In some case, Ollama send response containing Illegal unquoted character in a field of a json document:

2024-06-03 14:50:02,861 ERROR [io.qua.lan.run.ais.AiServiceMethodImplementationSupport] (executor-thread-1) Execution of com.cqc.syndifun.celia.ai.CeliaService#chat failed: java.io.UncheckedIOException: com.fasterxml.jackson.databind.JsonMappingException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 2, column: 105] (through reference chain: com.cqc.syndifun.celia.ai.ChatResponse["answer"])

Workaround, configure the object mapper in your application.

@Singleton
@SuppressWarnings("unused")
public class ObjectMapperConfiguration implements ObjectMapperCustomizer {

    public void customize(ObjectMapper mapper) {
        // Avoid Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value
        // Needed for AI
        mapper.configure(
                JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(),
                true
        );
    }
}

Perhaps if this is the way to go, we can integrate this configuration directly in quarkus-langchain4j ?

geoand commented 4 months ago

How can one reproduce this problem?

In any case, the proposed solution seems reasonable

humcqc commented 4 months ago

How can one reproduce this problem?

In any case, the proposed solution seems reasonable

@geoand PR with the test case #651