Class ChatCompletionCreateParams.ResponseFormat
-
- All Implemented Interfaces:
public final class ChatCompletionCreateParams.ResponseFormat
An object specifying the format that the model must output.
Setting to
{ "type": "json_schema", "json_schema": {...} }
enables Structured Outputs which ensures the model will match your supplied JSON schema. Learn more in the Structured Outputs guide.Setting to
{ "type": "json_object" }
enables JSON mode, which ensures the message the model generates is valid JSON.Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if
finish_reason="length"
, which indicates the generation exceededmax_tokens
or the conversation exceeded the max context length.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
ChatCompletionCreateParams.ResponseFormat.Visitor
An interface that defines how to map each variant of ResponseFormat to a value of type T.
-
Method Summary
Modifier and Type Method Description final Optional<ResponseFormatText>
text()
final Optional<ResponseFormatJsonObject>
jsonObject()
final Optional<ResponseFormatJsonSchema>
jsonSchema()
final Boolean
isText()
final Boolean
isJsonObject()
final Boolean
isJsonSchema()
final ResponseFormatText
asText()
final ResponseFormatJsonObject
asJsonObject()
final ResponseFormatJsonSchema
asJsonSchema()
final Optional<JsonValue>
_json()
final <T extends Any> T
accept(ChatCompletionCreateParams.ResponseFormat.Visitor<T> visitor)
final ChatCompletionCreateParams.ResponseFormat
validate()
Boolean
equals(Object other)
Integer
hashCode()
String
toString()
final static ChatCompletionCreateParams.ResponseFormat
ofText(ResponseFormatText text)
final static ChatCompletionCreateParams.ResponseFormat
ofJsonObject(ResponseFormatJsonObject jsonObject)
final static ChatCompletionCreateParams.ResponseFormat
ofJsonSchema(ResponseFormatJsonSchema jsonSchema)
-
-
Method Detail
-
text
final Optional<ResponseFormatText> text()
-
jsonObject
final Optional<ResponseFormatJsonObject> jsonObject()
-
jsonSchema
final Optional<ResponseFormatJsonSchema> jsonSchema()
-
isJsonObject
final Boolean isJsonObject()
-
isJsonSchema
final Boolean isJsonSchema()
-
asText
final ResponseFormatText asText()
-
asJsonObject
final ResponseFormatJsonObject asJsonObject()
-
asJsonSchema
final ResponseFormatJsonSchema asJsonSchema()
-
accept
final <T extends Any> T accept(ChatCompletionCreateParams.ResponseFormat.Visitor<T> visitor)
-
validate
final ChatCompletionCreateParams.ResponseFormat validate()
-
ofText
final static ChatCompletionCreateParams.ResponseFormat ofText(ResponseFormatText text)
-
ofJsonObject
final static ChatCompletionCreateParams.ResponseFormat ofJsonObject(ResponseFormatJsonObject jsonObject)
-
ofJsonSchema
final static ChatCompletionCreateParams.ResponseFormat ofJsonSchema(ResponseFormatJsonSchema jsonSchema)
-
-
-
-