TheoKanning / openai-java

OpenAI Api Client in Java
MIT License
4.68k stars 1.16k forks source link

Assistant creation returns an error on tools input #467

Open Grebyn35 opened 4 months ago

Grebyn35 commented 4 months ago

I think OpenAi has changed some parameter when creating an assistant and setting tools.

When creating an assistant:

AssistantRequest assistantRequest = AssistantRequest.builder()
                .name("test")
                .model("gpt-4-0125-preview")
                .description("")
                .instructions("")
                .tools(List.of(new Tool(AssistantToolsEnum.CODE_INTERPRETER, null), new Tool(AssistantToolsEnum.RETRIEVAL, null)))
                .fileIds(new ArrayList<>())
                .build();

An error occurs:

{
  "error": {
    "message": "10 validation errors for Request\nbody -> tools -> 0 -> function\n  extra fields not permitted (type=value_error.extra)\nbody -> tools -> 0 -> type\n  unexpected value; permitted: <ToolTypeParam.RETRIEVAL: 'retrieval'> (type=value_error.const; given=code_interpreter; permitted=(<ToolTypeParam.RETRIEVAL: 'retrieval'>,))\nbody -> tools -> 0 -> function\n  extra fields not permitted (type=value_error.extra)\nbody -> tools -> 0 -> type\n  unexpected value; permitted: <ToolTypeParam.FUNCTION: 'function'> (type=value_error.const; given=code_interpreter; permitted=(<ToolTypeParam.FUNCTION: 'function'>,))\nbody -> tools -> 0 -> function\n  none is not an allowed value (type=type_error.none.not_allowed)\nbody -> tools -> 1 -> type\n  unexpected value; permitted: <ToolTypeParam.CODE_INTERPRETER: 'code_interpreter'> (type=value_error.const; given=retrieval; permitted=(<ToolTypeParam.CODE_INTERPRETER: 'code_interpreter'>,))\nbody -> tools -> 1 -> function\n  extra fields not permitted (type=value_error.extra)\nbody -> tools -> 1 -> function\n  extra fields not permitted (type=value_error.extra)\nbody -> tools -> 1 -> type\n  unexpected value; permitted: <ToolTypeParam.FUNCTION: 'function'> (type=value_error.const; given=retrieval; permitted=(<ToolTypeParam.FUNCTION: 'function'>,))\nbody -> tools -> 1 -> function\n  none is not an allowed value (type=type_error.none.not_allowed)",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

Might be because tools has null as a parameter, and it doesnt accept it unless its AssistantToolsEnum.FUNCTION?

avntsnghchgh commented 4 months ago

I had the same issue, here is the fix:

https://community.openai.com/t/create-assistants-api-broken-since-2-16-2024/629996

move the required after properties but within parameters like below: { "type": "function", "function": { "name": "getNickname", "description": "Get the nickname of a city", "parameters": { "type": "object", "properties": { "location": {"type": "string", "description": "The city and state e.g. San Francisco, CA"}, }, "required": ["location"] }