Class BetaResponseFormatTextConfig
-
- All Implemented Interfaces:
public final class BetaResponseFormatTextConfigAn object specifying the format that the model must output.
Configuring
{ "type": "json_schema" }enables Structured Outputs, which ensures the model will match your supplied JSON schema. Learn more in the Structured Outputs guide.The default format is
{ "type": "text" }with no additional options.Not recommended for gpt-4o and newer models:
Setting to
{ "type": "json_object" }enables the older JSON mode, which ensures the message the model generates is valid JSON. Usingjson_schemais preferred for models that support it.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceBetaResponseFormatTextConfig.VisitorAn interface that defines how to map each variant of BetaResponseFormatTextConfig to a value of type T.
-
Method Summary
Modifier and Type Method Description final Optional<JsonValue>text()Default response format. final Optional<BetaResponseFormatTextJsonSchemaConfig>jsonSchema()JSON Schema response format. final Optional<JsonValue>jsonObject()JSON object response format. final BooleanisText()final BooleanisJsonSchema()final BooleanisJsonObject()final JsonValueasText()Default response format. final BetaResponseFormatTextJsonSchemaConfigasJsonSchema()JSON Schema response format. final JsonValueasJsonObject()JSON object response format. final Optional<JsonValue>_json()final <T extends Any> Taccept(BetaResponseFormatTextConfig.Visitor<T> visitor)Maps this instance's current variant to a value of type T using the given visitor. final BetaResponseFormatTextConfigvalidate()Validates that the types of all values in this object match their expected types recursively. final BooleanisValid()Booleanequals(Object other)IntegerhashCode()StringtoString()final static BetaResponseFormatTextConfigofText()Default response format. final static BetaResponseFormatTextConfigofJsonSchema(BetaResponseFormatTextJsonSchemaConfig jsonSchema)JSON Schema response format. final static BetaResponseFormatTextConfigofJsonObject()JSON object response format. -
-
Method Detail
-
jsonSchema
final Optional<BetaResponseFormatTextJsonSchemaConfig> jsonSchema()
JSON Schema response format. Used to generate structured JSON responses. Learn more about Structured Outputs.
-
jsonObject
final Optional<JsonValue> jsonObject()
JSON object response format. An older method of generating JSON responses. Using
json_schemais recommended for models that support it. Note that the model will not generate JSON without a system or user message instructing it to do so.
-
isJsonSchema
final Boolean isJsonSchema()
-
isJsonObject
final Boolean isJsonObject()
-
asJsonSchema
final BetaResponseFormatTextJsonSchemaConfig asJsonSchema()
JSON Schema response format. Used to generate structured JSON responses. Learn more about Structured Outputs.
-
asJsonObject
final JsonValue asJsonObject()
JSON object response format. An older method of generating JSON responses. Using
json_schemais recommended for models that support it. Note that the model will not generate JSON without a system or user message instructing it to do so.
-
accept
final <T extends Any> T accept(BetaResponseFormatTextConfig.Visitor<T> visitor)
Maps this instance's current variant to a value of type T using the given visitor.
Note that this method is not forwards compatible with new variants from the API, unless visitor overrides Visitor.unknown. To handle variants not known to this version of the SDK gracefully, consider overriding Visitor.unknown:
import com.openai.core.JsonValue; import java.util.Optional; Optional<String> result = betaResponseFormatTextConfig.accept(new BetaResponseFormatTextConfig.Visitor<Optional<String>>() { @Override public Optional<String> visitText(JsonValue text) { return Optional.of(text.toString()); } // ... @Override public Optional<String> unknown(JsonValue json) { // Or inspect the `json`. return Optional.empty(); } });
-
validate
final BetaResponseFormatTextConfig validate()
Validates that the types of all values in this object match their expected types recursively.
This method is not forwards compatible with new types from the API for existing fields.
-
ofText
final static BetaResponseFormatTextConfig ofText()
Default response format. Used to generate text responses.
-
ofJsonSchema
final static BetaResponseFormatTextConfig ofJsonSchema(BetaResponseFormatTextJsonSchemaConfig jsonSchema)
JSON Schema response format. Used to generate structured JSON responses. Learn more about Structured Outputs.
-
ofJsonObject
final static BetaResponseFormatTextConfig ofJsonObject()
JSON object response format. An older method of generating JSON responses. Using
json_schemais recommended for models that support it. Note that the model will not generate JSON without a system or user message instructing it to do so.
-
-
-
-