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

Incorrect type for callback function #1244

Open
1 task done
ori-shalom opened this issue Dec 28, 2024 · 0 comments
Open
1 task done

Incorrect type for callback function #1244

ori-shalom opened this issue Dec 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ori-shalom
Copy link

ori-shalom commented Dec 28, 2024

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

The type of AutoParseableTool is incorrectly describing $callback as receiving the arguments zod schema as input while it should have the inferred zod type of the arguments zod schema.

To Reproduce

  1. Define a tool with the import { zodFunction } from 'openai/helpers/zod'; helper.
  2. Check the inferred type of $callback property on the tool.

Code snippets

Can be fixed by adding zodInfer<...> here:

export type AutoParseableTool<
OptionsT extends ToolOptions,
HasFunction = OptionsT['function'] extends Function ? true : false,
> = ChatCompletionTool & {
__arguments: OptionsT['arguments']; // type-level only
__name: OptionsT['name']; // type-level only
__hasFunction: HasFunction; // type-level only
$brand: 'auto-parseable-tool';
$callback: ((args: OptionsT['arguments']) => any) | undefined;
$parseRaw(args: string): OptionsT['arguments'];
};

So $callback will become:

$callback: ((args: zodInfer<OptionsT['arguments']>) => any) | undefined;

OS

macOS

Node version

Node v20.15.1

Library version

openai v4.76.3

@ori-shalom ori-shalom added the bug Something isn't working label Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant