microsoft / semantic-kernel-java

Semantic Kernel for Java. Integrate cutting-edge LLM technology quickly and easily into your Java based apps. See https://aka.ms/semantic-kernel.
MIT License
56 stars 14 forks source link

Java.lang.ClassCastException on PromptExecutionSettings.builder().withResponseFormat(ResponseFormat.JSON_OBJECT).build(); #145

Open fabrizio-fal opened 4 months ago

fabrizio-fal commented 4 months ago

Describe the bug

When i try to setup an invocationContext with PromptExecutionSettings and withResponseFormat to enum ResponseFormat.JSON_OBJECT the library going in error becouse the builder expect a String.

image

To Reproduce

below is my code:

    com.microsoft.semantickernel.orchestration.PromptExecutionSettings promptExecutionSettings = PromptExecutionSettings.builder().withResponseFormat(ResponseFormat.JSON_OBJECT).build();

    var invocationContext = InvocationContext.builder()
        .withToolCallBehavior(
            ToolCallBehavior.allowOnlyKernelFunctions(true, kernel.getFunction("InformationFinder", "SearchFromQuestion")))
        .withPromptExecutionSettings(promptExecutionSettings)
        .build();

    KernelFunctionArguments variables = KernelFunctionArguments.builder()
            .withVariable("inputDate", LocalDate.now().toString())
            .withVariable("input", req)
            .build();

    FunctionResult<String> reply = kernel
            .invokeAsync("Searches", "DefaultSearch")
           .withInvocationContext(invocationContext)
            .withArguments(variables)
            .withResultType(String.class)
            .block();

    String res = reply.getResult();

Expected behavior

My expectation is to not have a java.lang.ClassCastExceptio at this point

Screenshots java.lang.ClassCastException: class com.microsoft.semantickernel.orchestration.ResponseFormat cannot be cast to class java.lang.String (com.microsoft.semantickernel.orchestration.ResponseFormat is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap') at com.microsoft.semantickernel.orchestration.PromptExecutionSettings$Builder.build(PromptExecutionSettings.java:579) ~[semantickernel-api-1.0.1.jar:?]

Platform

johnoliver commented 3 months ago

This is probably a bug, will take a look