Skip to content
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

handle collections as return types or error #943

Open
maxandersen opened this issue Sep 28, 2024 · 7 comments
Open

handle collections as return types or error #943

maxandersen opened this issue Sep 28, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@maxandersen
Copy link
Member

if one use List, Set, Map etc. as return types the ask to genAI is: You must answer strictly in the following JSON format: {\n} - it should have the the json structure.

This fails:

    @RegisterAiService
    public interface jaidataAI {

        @SystemMessage(
            """
            IDENTITY
            
            You are a superintelligent AI that finds all mentions of data structures within an input and...
        """
        )
        @UserMessage("""
                    {data}
                """)
        List<FileInfo> generate(String data);
    }

    record FileInfo(String filename, String content) {};

but if change it to the following it works:

     FileInfos generate(String data);
    }
    record FileInfos(List<FileInfo>) {};
    record FileInfo(String filename, String content) {};

I would think it should be possible to handle - and if not, throw build error it needs to be a non-collection java type?

@geoand
Copy link
Collaborator

geoand commented Sep 28, 2024

Are you using the latest version?

@maxandersen
Copy link
Member Author

//DEPS io.quarkus:quarkus-bom:${quarkus.version:3.15.1}@pom
//DEPS io.quarkiverse.langchain4j:quarkus-langchain4j-openai:0.19.0.CR3

latest i could find in maven central at least.

@geoand
Copy link
Collaborator

geoand commented Sep 29, 2024

Interesting, I remember fixing some related issues recently.

I'll have a look tomorrow

@geoand
Copy link
Collaborator

geoand commented Sep 30, 2024

So indeed this is an issue with how upstream LangChain4j creates the json schema

@geoand
Copy link
Collaborator

geoand commented Oct 1, 2024

@gsmet has run into similar so we probably need to rethink the whole approach

@geoand geoand added the bug Something isn't working label Oct 2, 2024
@andreadimaio
Copy link
Collaborator

It is also related to #671

@gsmet
Copy link
Member

gsmet commented Oct 2, 2024

FWIW, using Map throws an error in 0.20.0 due to LangChain4j changes:

Caused by: dev.langchain4j.exception.IllegalConfigurationException: Illegal method return type: java.util.Map<java.lang.String, java.lang.Integer>
    at dev.langchain4j.exception.IllegalConfigurationException.illegalConfiguration(IllegalConfigurationException.java:12)
    at dev.langchain4j.service.output.ServiceOutputParser.validateJsonStructure(ServiceOutputParser.java:135)
    at dev.langchain4j.service.output.ServiceOutputParser.outputFormatInstructions(ServiceOutputParser.java:125)
    at io.quarkiverse.langchain4j.runtime.QuarkusServiceOutputParser.outputFormatInstructions(QuarkusServiceOutputParser.java:19)
    at io.quarkiverse.langchain4j.deployment.AiServicesProcessor.gatherMethodMetadata(AiServicesProcessor.java:1098)
    at io.quarkiverse.langchain4j.deployment.AiServicesProcessor.handleAiServices(AiServicesProcessor.java:932)
    at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
    at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
    at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
    at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
    at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
    at java.base/java.lang.Thread.run(Thread.java:1583)
    at org.jboss.threads.JBossThread.run(JBossThread.java:483)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants