-
Notifications
You must be signed in to change notification settings - Fork 99
Structured outputs #463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Structured outputs #463
Conversation
README.md
Outdated
be derived automatically from the structure of an arbitrary Java class. The response will then | ||
automatically convert the generated JSON content to an instance of that Java class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be derived automatically from the structure of an arbitrary Java class. The response will then | |
automatically convert the generated JSON content to an instance of that Java class. | |
be derived automatically from the structure of an arbitrary Java class. The response's JSON will then | |
be automatically converted to an instance of that Java class. |
Cause the response is not what does the converting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The switch from active to passive voice doesn't scan as well. Read "the response" as "the process of responding" rather than as HttpResponse
and see if you feel more comfortable about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change it anyway, as the previous sentence is passive, so they can all be the same.
README.md
Outdated
```java | ||
class Person { | ||
public String name; | ||
public int yearOfBirth; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe birthYear
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to make them a bit more English-y so that the AI model could interpret them with less fuss, but, sure, I''ll change that for you. I'll need to change yearPublished
to publicationYear
too, for consistency.
README.md
Outdated
StructuredChatCompletionCreateParams<BookList> params = ChatCompletionCreateParams.builder() | ||
.addUserMessage("List six famous nineteenth century novels.") | ||
.model(ChatModel.GPT_4_1) | ||
.responseFormat(BookList.class, false) // Disable local validation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this second false
parameter because it's hard to tell what it means without reading the documentation... In general, boolean positional params are a bit sad
Maybe instead we should have responseFormat(Class<T>)
and responseFormatUnchecked(Class<T>)
or responseFormatUnvalidated(Class<T>)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. How about one of these?
responseFormatWithoutValidation
responseFormatNoValidation
responseFormatSkipValidation
responseFormatLenient
responseFormatNonStrict
responseFormatAllowInvalid
responseFormatPlain
@@ -27,6 +27,8 @@ dependencies { | |||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.2") | |||
implementation("org.apache.httpcomponents.core5:httpcore5:5.2.4") | |||
implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1") | |||
implementation("com.github.victools:jsonschema-generator:4.38.0") | |||
implementation("com.github.victools:jsonschema-module-jackson:4.38.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious what version of jackson this depends on? Just wanna make sure it's compatible with Jackson 2.13.4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT, it depends on Jackson 2.17.2 (see here).
.addModule(JavaTimeModule()) | ||
.build() | ||
|
||
internal fun <T> fromClass( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal fun <T> fromClass( | |
@JvmSynthetic | |
internal fun <T> fromClass( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added that to all three functions in StructuredOutputs.kt
. We can remove it again if we decide to make any of them public.
val responseFormat: Class<T>, | ||
val chatCompletion: ChatCompletion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val responseFormat: Class<T>, | |
val chatCompletion: ChatCompletion, | |
@get:JvmName("responseFormat") val responseFormat: Class<T>, | |
@get:JvmName("rawChatCompletion") val rawChatCompletion: ChatCompletion, |
Otherwise I think Kotlin will generate getResponseFormat()
and getChatCompletion()
methods, instead of non-get
prefixed
internal val responseFormat: Class<T>, | ||
internal val choice: ChatCompletion.Choice, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal val responseFormat: Class<T>, | |
internal val choice: ChatCompletion.Choice, | |
@get:JvmName("responseFormat") val responseFormat: Class<T>, | |
@get:JvmName("rawChoice") val rawChoice: ChatCompletion.Choice, |
|
||
class StructuredChatCompletionCreateParams<T : Any> | ||
internal constructor( | ||
val responseFormat: Class<T>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val responseFormat: Class<T>, | |
@get:JvmName("responseFormat") val responseFormat: Class<T>, |
val responseFormat: Class<T>, | ||
val chatCompletionMessage: ChatCompletionMessage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val responseFormat: Class<T>, | |
val chatCompletionMessage: ChatCompletionMessage, | |
@get:JvmName("responseFormat") val responseFormat: Class<T>, | |
@get:JvmName("rawChatCompletionMessage") val rawChatCompletionMessage: ChatCompletionMessage, |
if (isValidationComplete) { | ||
throw IllegalStateException("Validation already complete.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (isValidationComplete) { | |
throw IllegalStateException("Validation already complete.") | |
} | |
check (!isValidationComplete) { "Validation already complete." } |
8c0d60a
to
67381ff
Compare
Includes optional local JSON schema validation and draft SDK documentation.