Skip to content

'properties' field is missing, empty or not an object. #504

Open
@yidasanqian

Description

@yidasanqian

version:2.5.0

ref: https://github.com/openai/openai-java/blob/main/openai-java-example/src/main/java/com/openai/example/FunctionCallingExample.java

code:

Image

 OpenAIClient client = OpenAIOkHttpClient.builder()
                .apiKey(environment.getProperty("OPENAI_API_KEY"))
                .baseUrl(environment.getProperty("OPENAI_BASE_URL"))
                .build();
        ChatCompletionCreateParams.Builder createParamsBuilder = ChatCompletionCreateParams.builder()
                .model(model)
                .maxCompletionTokens(4096)
                .addTool(BingWebSearchTool.class)
                .addUserMessage(query);

        client.chat().completions().create(createParamsBuilder.build()).choices().stream()
                .map(ChatCompletion.Choice::message)
                // Add each assistant message onto the builder so that we keep track of the
                // conversation for asking a follow-up question later.
                .peek(createParamsBuilder::addMessage)
                .flatMap(message -> {
                    message.content().ifPresent(System.out::println);
                    return message.toolCalls().stream().flatMap(Collection::stream);
                })
                .forEach(toolCall -> {
                    Object result = callFunction(toolCall.function());
                    // Add the tool call result to the conversation.
                    createParamsBuilder.addMessage(ChatCompletionToolMessageParam.builder()
                            .toolCallId(toolCall.id())
                            .contentAsJson(result)
                            .build());
                });

        // Ask a follow-up question about the function call result.
        createParamsBuilder.addUserMessage(query);
        client.chat().completions().create(createParamsBuilder.build()).choices().stream()
                .flatMap(choice -> choice.message().content().stream())
                .forEach(System.out::println);

exception:

java.lang.IllegalArgumentException: Local validation failed for JSON schema derived from class com.toowe.report.FunctionCallTest$BingWebSearchTool:
 - #: 'properties' field is missing, empty or not an object.

	at com.openai.core.StructuredOutputsKt.validateSchema(StructuredOutputs.kt:76)
	at com.openai.core.StructuredOutputsKt.extractFunctionInfo(StructuredOutputs.kt:124)
	at com.openai.core.StructuredOutputsKt.functionToolFromClass(StructuredOutputs.kt:149)
	at com.openai.models.chat.completions.ChatCompletionCreateParams$Builder.addTool(ChatCompletionCreateParams.kt:1553)
	at com.openai.models.chat.completions.ChatCompletionCreateParams$Builder.addTool$default(ChatCompletionCreateParams.kt:1550)
	at com.openai.models.chat.completions.ChatCompletionCreateParams$Builder.addTool(ChatCompletionCreateParams.kt)
	at com.toowe.report.FunctionCallTest.testBingWebSearch(FunctionCallTest.java:55)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)

How to fix?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions