22
33<!-- x-release-please-start-version -->
44
5- [ ![ Maven Central] ( https://img.shields.io/maven-central/v/com.openai/openai-java )] ( https://central.sonatype.com/artifact/com.openai/openai-java/2.9.0 )
6- [ ![ javadoc] ( https://javadoc.io/badge2/com.openai/openai-java/2.9.0 /javadoc.svg )] ( https://javadoc.io/doc/com.openai/openai-java/2.9.0 )
5+ [ ![ Maven Central] ( https://img.shields.io/maven-central/v/com.openai/openai-java )] ( https://central.sonatype.com/artifact/com.openai/openai-java/2.9.1 )
6+ [ ![ javadoc] ( https://javadoc.io/badge2/com.openai/openai-java/2.9.1 /javadoc.svg )] ( https://javadoc.io/doc/com.openai/openai-java/2.9.1 )
77
88<!-- x-release-please-end -->
99
1010The OpenAI Java SDK provides convenient access to the [ OpenAI REST API] ( https://platform.openai.com/docs ) from applications written in Java.
1111
1212<!-- x-release-please-start-version -->
1313
14- The REST API documentation can be found on [ platform.openai.com] ( https://platform.openai.com/docs ) . Javadocs are available on [ javadoc.io] ( https://javadoc.io/doc/com.openai/openai-java/2.9.0 ) .
14+ The REST API documentation can be found on [ platform.openai.com] ( https://platform.openai.com/docs ) . Javadocs are available on [ javadoc.io] ( https://javadoc.io/doc/com.openai/openai-java/2.9.1 ) .
1515
1616<!-- x-release-please-end -->
1717
@@ -22,7 +22,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor
2222### Gradle
2323
2424``` kotlin
25- implementation(" com.openai:openai-java:2.9.0 " )
25+ implementation(" com.openai:openai-java:2.9.1 " )
2626```
2727
2828### Maven
@@ -31,7 +31,7 @@ implementation("com.openai:openai-java:2.9.0")
3131<dependency >
3232 <groupId >com.openai</groupId >
3333 <artifactId >openai-java</artifactId >
34- <version >2.9.0 </version >
34+ <version >2.9.1 </version >
3535</dependency >
3636```
3737
@@ -363,7 +363,8 @@ response will then be converted automatically to an instance of that Java class.
363363example of the use of Structured Outputs with arbitrary Java classes can be seen in
364364[ ` StructuredOutputsExample ` ] ( openai-java-example/src/main/java/com/openai/example/StructuredOutputsExample.java ) .
365365
366- Java classes can contain fields declared to be instances of other classes and can use collections:
366+ Java classes can contain fields declared to be instances of other classes and can use collections
367+ (see [ Defining JSON schema properties] ( #defining-json-schema-properties ) for more details):
367368
368369``` java
369370class Person {
@@ -506,12 +507,38 @@ the latter when `ResponseCreateParams.Builder.text(Class<T>)` is called.
506507For a full example of the usage of _ Structured Outputs_ with the Responses API, see
507508[ ` ResponsesStructuredOutputsExample ` ] ( openai-java-example/src/main/java/com/openai/example/ResponsesStructuredOutputsExample.java ) .
508509
510+ ### Defining JSON schema properties
511+
512+ When a JSON schema is derived from your Java classes, all properties represented by ` public ` fields
513+ or ` public ` getter methods are included in the schema by default. Non-` public ` fields and getter
514+ methods are _ not_ included by default. You can exclude ` public ` , or include non-` public ` fields or
515+ getter methods, by using the ` @JsonIgnore ` or ` @JsonProperty ` annotations respectively (see
516+ [ Annotating classes and JSON schemas] ( #annotating-classes-and-json-schemas ) for details).
517+
518+ If you do not want to define ` public ` fields, you can define ` private ` fields and corresponding
519+ ` public ` getter methods. For example, a ` private ` field ` myValue ` with a ` public ` getter method
520+ ` getMyValue() ` will result in a ` "myValue" ` property being included in the JSON schema. If you
521+ prefer not to use the conventional Java "get" prefix for the name of the getter method, then you
522+ _ must_ annotate the getter method with the ` @JsonProperty ` annotation and the full method name will
523+ be used as the property name. You do not have to define any corresponding setter methods if you do
524+ not need them.
525+
526+ Each of your classes _ must_ define at least one property to be included in the JSON schema. A
527+ validation error will occur if any class contains no fields or getter methods from which schema
528+ properties can be derived. This may occur if, for example:
529+
530+ - There are no fields or getter methods in the class.
531+ - All fields and getter methods are ` public ` , but all are annotated with ` @JsonIgnore ` .
532+ - All fields and getter methods are non-` public ` , but none are annotated with ` @JsonProperty ` .
533+ - A field or getter method is declared with a ` Map ` type. A ` Map ` is treated like a separate class
534+ with no named properties, so it will result in an empty ` "properties" ` field in the JSON schema.
535+
509536### Annotating classes and JSON schemas
510537
511538You can use annotations to add further information to the JSON schema derived from your Java
512- classes, or to exclude individual fields from the schema. Details from annotations captured in the
513- JSON schema may be used by the AI model to improve its response. The SDK supports the use of
514- [ Jackson Databind] ( https://github.com/FasterXML/jackson-databind ) annotations.
539+ classes, or to control which fields or getter methods will be included in the schema. Details from
540+ annotations captured in the JSON schema may be used by the AI model to improve its response. The SDK
541+ supports the use of [ Jackson Databind] ( https://github.com/FasterXML/jackson-databind ) annotations.
515542
516543``` java
517544import com.fasterxml.jackson.annotation.JsonClassDescription ;
@@ -541,8 +568,12 @@ class BookList {
541568```
542569
543570- Use ` @JsonClassDescription ` to add a detailed description to a class.
544- - Use ` @JsonPropertyDescription ` to add a detailed description to a field of a class.
545- - Use ` @JsonIgnore ` to omit a field of a class from the generated JSON schema.
571+ - Use ` @JsonPropertyDescription ` to add a detailed description to a field or getter method of a
572+ class.
573+ - Use ` @JsonIgnore ` to exclude a ` public ` field or getter method of a class from the generated JSON
574+ schema.
575+ - Use ` @JsonProperty ` to include a non-` public ` field or getter method of a class in the generated
576+ JSON schema.
546577
547578If you use ` @JsonProperty(required = false) ` , the ` false ` value will be ignored. OpenAI JSON schemas
548579must mark all properties as _ required_ , so the schema generated from your Java classes will respect
@@ -577,9 +608,11 @@ _Function Calling_ with Java classes to define function parameters can be seen i
577608[ ` FunctionCallingExample ` ] ( openai-java-example/src/main/java/com/openai/example/FunctionCallingExample.java ) .
578609
579610Like for [ Structured Outputs] ( #structured-outputs-with-json-schemas ) , Java classes can contain
580- fields declared to be instances of other classes and can use collections. Optionally, annotations
581- can be used to set the descriptions of the function (class) and its parameters (fields) to assist
582- the AI model in understanding the purpose of the function and the possible values of its parameters.
611+ fields declared to be instances of other classes and can use collections (see
612+ [ Defining JSON schema properties] ( #defining-json-schema-properties ) for more details). Optionally,
613+ annotations can be used to set the descriptions of the function (class) and its parameters (fields)
614+ to assist the AI model in understanding the purpose of the function and the possible values of its
615+ parameters.
583616
584617``` java
585618import com.fasterxml.jackson.annotation.JsonClassDescription ;
@@ -724,24 +757,31 @@ validation and under what circumstances you might want to disable it.
724757### Annotating function classes
725758
726759You can use annotations to add further information about functions to the JSON schemas that are
727- derived from your function classes, or to exclude individual fields from the parameters to the
728- function. Details from annotations captured in the JSON schema may be used by the AI model to
729- improve its response. The SDK supports the use of
760+ derived from your function classes, or to control which fields or getter methods will be used as
761+ parameters to the function. Details from annotations captured in the JSON schema may be used by the
762+ AI model to improve its response. The SDK supports the use of
730763[ Jackson Databind] ( https://github.com/FasterXML/jackson-databind ) annotations.
731764
732765- Use ` @JsonClassDescription ` to add a description to a function class detailing when and how to use
733766 that function.
734767- Use ` @JsonTypeName ` to set the function name to something other than the simple name of the class,
735768 which is used by default.
736- - Use ` @JsonPropertyDescription ` to add a detailed description to function parameter (a field of
737- a function class).
738- - Use ` @JsonIgnore ` to omit a field of a class from the generated JSON schema for a function's
739- parameters.
769+ - Use ` @JsonPropertyDescription ` to add a detailed description to function parameter (a field or
770+ getter method of a function class).
771+ - Use ` @JsonIgnore ` to exclude a ` public ` field or getter method of a class from the generated JSON
772+ schema for a function's parameters.
773+ - Use ` @JsonProperty ` to include a non-` public ` field or getter method of a class in the generated
774+ JSON schema for a function's parameters.
740775
741776OpenAI provides some
742777[ Best practices for defining functions] ( https://platform.openai.com/docs/guides/function-calling#best-practices-for-defining-functions )
743778that may help you to understand how to use the above annotations effectively for your functions.
744779
780+ See also [ Defining JSON schema properties] ( #defining-json-schema-properties ) for more details on how
781+ to use fields and getter methods and combine access modifiers and annotations to define the
782+ parameters of your functions. The same rules apply to function classes and to the structured output
783+ classes described in that section.
784+
745785## File uploads
746786
747787The SDK defines methods that accept files.
0 commit comments