Skip to content
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

Allow specifying definitions as a zodResponseFormat param #1285

Open
1 task done
rpavlovs opened this issue Jan 23, 2025 · 0 comments
Open
1 task done

Allow specifying definitions as a zodResponseFormat param #1285

rpavlovs opened this issue Jan 23, 2025 · 0 comments

Comments

@rpavlovs
Copy link

rpavlovs commented Jan 23, 2025

Confirm this is a feature request for the Node library and not the underlying OpenAI API.

  • This is a feature request for the Node library

Describe the feature or improvement you're requesting

Allow specifying schemaDefinitions as a zodResponseFormat param

Proposed signature

const schemaDefinitions = {
  foo: z.enum('one', 'two', 'three', ....)  // 200 elements
  bar: z.enum('a', 'b', 'c', ...)  // 200 elements
)

const responseFormat = zodResponseFormat(
  z.object({
    foo: schemaDefinitions.foo
    foos: z.array[schemaDefinitions.foo]
    bar: schemaDefinitions.foo
    bars: z.array[schemaDefinitions.bar]
  }),
 { name: 'fooBar', schemaDefinitions }
)

Additional context

❌ Without definitions this schema produces 800 enums, which is above the 500 enums OpenAI limit.
First occurrence of a def is left in place, starting with the second one it's copied to definitions and a reference is used.

zod-to-json-schema library has a definitions option that is used to supply definitions, and avoid duplication – resulting in 400 enums.

Alternative approach would be to detect shared definitions, move out to definitions, and replace with refs automatically. This would be a significantly more complex, but easier to use solution. Probably not worth the work for now, since everything is in place to just expose the zod-to-json-schema's definitions option

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

No branches or pull requests

1 participant