-
Notifications
You must be signed in to change notification settings - Fork 120
Function Calling Preview #497
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
Conversation
.stats.yml
Outdated
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.
Probably need a rebase
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.
Yeah. I did a rebase before creating the PR, but it looks like it had quite a short shelf life. I'll do another shortly when I add the draft documentation and push that, too.
openai-java-example/src/main/java/com/openai/example/FunctionCallingExample.java
Outdated
Show resolved
Hide resolved
openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt
Show resolved
Hide resolved
...ava-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionMessageToolCall.kt
Show resolved
Hide resolved
README.md
Outdated
@@ -533,6 +533,200 @@ If you use `@JsonProperty(required = false)`, the `false` value will be ignored. | |||
must mark all properties as _required_, so the schema generated from your Java classes will respect | |||
that restriction and ignore any annotation that would violate it. | |||
|
|||
## Function calling |
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.
## Function calling | |
## Function calling with JSON schemas |
(to match "Structured outputs with JSON schemas" above)
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 was in two minds. The schemas are a little less "in your face" for function calling. No objections, though.
README.md
Outdated
_Function Calling_ with Java classes to define function parameters can be seen in | ||
[`FunctionCallingExample`](openai-java-example/src/main/java/com/openai/example/FunctionCallingExample.java). | ||
|
||
Like for _Structured Outputs_, Java classes can contain fields declared to be instances of other |
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.
Like for _Structured Outputs_, Java classes can contain fields declared to be instances of other | |
Like for [Structured Outputs](#structured-outputs-with-json-schemas), Java classes can contain fields declared to be instances of other |
I think this should link to the heading above. Can test in the README preview after you push up your commit
@JvmOverloads | ||
fun <T : Any> addTool( | ||
functionParametersType: Class<T>, | ||
localValidation: JsonSchemaLocalValidation = JsonSchemaLocalValidation.YES, | ||
) = apply { addTool(functionToolFromClass(functionParametersType, localValidation)) } |
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.
@JvmOverloads | |
fun <T : Any> addTool( | |
functionParametersType: Class<T>, | |
localValidation: JsonSchemaLocalValidation = JsonSchemaLocalValidation.YES, | |
) = apply { addTool(functionToolFromClass(functionParametersType, localValidation)) } | |
@JvmOverloads | |
fun addTool( | |
functionParametersType: Class<*>, | |
localValidation: JsonSchemaLocalValidation = JsonSchemaLocalValidation.YES, | |
) = apply { addTool(functionToolFromClass(functionParametersType, localValidation)) } |
Since the generic is used once, it's not actually needed (this is equivalent to Class<?>
in Java). Can do this for the other new functions added as well
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.
Yep. I found a bunch of those. One in each of four ...CreateParams
classes and a bucket load in StructuredOutputs.kt
.
* feat(client): automatic schema generation and arg parsing for function calling (#497) * tool-calls: structured function calls without docs. * fn-calling: backfill missing functions and tests. * fn-calling: draft documentation and some review updates. * fn-calling: raw example for Responses API. * fn-calling: minor changes from PR review. * release: 2.5.0 --------- Co-authored-by: D Gardner <damien@gardnerhrm.com> Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
A preview of the new support for OpenAI Function Calling.
Documentation is not yet complete and example code may still need some work.
Also modified the
JsonSchemaValidator
to reject schemas withobject
-type fields that do not contain a non-empty"properties"
field. This reflects remote validation behavior that was not matched by local validation.