Skip to content

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

Merged
merged 5 commits into from
Jun 6, 2025
Merged

Function Calling Preview #497

merged 5 commits into from
Jun 6, 2025

Conversation

damo
Copy link
Contributor

@damo damo commented Jun 2, 2025

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 with object-type fields that do not contain a non-empty "properties" field. This reflects remote validation behavior that was not matched by local validation.

@damo damo requested a review from a team as a code owner June 2, 2025 12:36
.stats.yml Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need a rebase

Copy link
Contributor Author

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.

@damo damo force-pushed the damo/tool-calls branch from 8d1acf9 to 69f9984 Compare June 3, 2025 14:17
@damo damo requested a review from TomerAberbach June 3, 2025 14:20
@damo damo force-pushed the damo/tool-calls branch from 69f9984 to 03c1628 Compare June 4, 2025 14:17
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Function calling
## Function calling with JSON schemas

(to match "Structured outputs with JSON schemas" above)

Copy link
Contributor Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines 1549 to 1553
@JvmOverloads
fun <T : Any> addTool(
functionParametersType: Class<T>,
localValidation: JsonSchemaLocalValidation = JsonSchemaLocalValidation.YES,
) = apply { addTool(functionToolFromClass(functionParametersType, localValidation)) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@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

Copy link
Contributor Author

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.

@TomerAberbach TomerAberbach merged commit 800dc8f into openai:next Jun 6, 2025
@stainless-app stainless-app bot mentioned this pull request Jun 6, 2025
TomerAberbach pushed a commit that referenced this pull request Jun 6, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants