Hey everyone!
The official Java SDK for the OpenAI API is now available on GitHub and Maven Central. This SDK is still in beta, and we are actively making changes to the API shape. While we iterate on the design, we would love your thoughts and feedback!
As you try the new SDK and put it through its paces, please post your thoughts and feedback on this thread. The SDK team will be actively monitoring this thread for your input, and will look to incorporate it into our ongoing development and design efforts.
Thanks for your help, and we hope to make a Java SDK you’ll love using.
4 Likes
Great sdk, but I’m getting an error when I add parameters to funtions ChatCompletionCreateParams.Function, the putAdditionalProperty required a JsonValue so when I add the Schema as JsonValue I get a BadRequestException 400 schema must be a JSON Schema of ‘type: “object”’, got ‘type: “None”’
The code block of the code I’m runnig
JsonNode parsedSchema;
byte[] schemaBytes = nameSchema.toString().getBytes(StandardCharsets.UTF_8); // Get the byte array.
if (schemaBytes == null || schemaBytes.length == 0) {
System.err.println("Schema bytes are missing! Using an empty schema.");
parsedSchema = objectMapper.createObjectNode(); // Default to an empty schema.
} else {
try {
String schemaString = new String(schemaBytes, StandardCharsets.UTF_8); // Convert bytes to string, specifying UTF-8.
parsedSchema = objectMapper.readTree(schemaString);
} catch (JsonProcessingException e) {
System.err.println("Invalid schema: " + e.getMessage());
parsedSchema = objectMapper.createObjectNode();
}
}
if (parsedSchema.isMissingNode()) {
System.err.println("Schema is missing! Using an empty schema.");
}
ObjectNode objectNode = objectMapper.createObjectNode();
objectNode.setAll((ObjectNode) parsedSchema);
JsonValue jsonValueSchema = JsonValue.fromJsonNode(objectNode);
System.out.println("Passed in parameters as "+ JsonValue.fromJsonNode(nameSchema));
ChatCompletionCreateParams.Function functionName = ChatCompletionCreateParams.Function.builder()
.name("buscar_cliente_x_nombre")
.description("Buscar un cliente por nombre o razon social.")
.parameters(FunctionParameters.builder().putAdditionalProperty("nombre",jsonValueSchema).build())
.build();
Any help is appreciated, I’ve been trying to figure it out but I’m stuck.
Thanks