Open ghost opened 2 months ago
Same bug with the following versions and example
import OpenAI from "https://deno.land/x/openai@v4.55.5/mod.ts";
import { zodResponseFormat } from "https://deno.land/x/openai@v4.55.5/helpers/zod.ts";
import { z } from "https://deno.land/x/zod@v3.23.8/mod.ts";
const WildlifeSchema = z.object({
commonName: z.string(),
});
Thanks for the report. It'd be helpful if someone here could help us narrow down the issue, does this also result in a type error for you?
import { ResponseFormatJSONSchema } from 'openai/resources';
import z from 'zod';
import type { infer as zodInfer, ZodType } from 'zod';
export type AutoParseableResponseFormat<ParsedT> = ResponseFormatJSONSchema & {
__output: ParsedT; // type-level only
$brand: 'auto-parseable-response-format';
$parseRaw(content: string): ParsedT;
};
export function zodTest<ZodInput extends ZodType>(
zodObject: ZodInput,
name: string,
props?: Omit<ResponseFormatJSONSchema.JSONSchema, 'schema' | 'strict' | 'name'>,
): AutoParseableResponseFormat<zodInfer<ZodInput>> {
throw new Error('not implemented');
}
const WildlifeSchema = z.object({
commonName: z.string(),
});
const fmt = zodTest(WildlifeSchema, 'wildLifeSchema');
No, Deno can successfully type-check your code. (I had to adjust your first import, import { ResponseFormatJSONSchema } from "openai/resources/shared.ts";
)
Confirm this is a Node library issue and not an underlying OpenAI API issue
Describe the bug
Type-checking using "deno check" fails with either
or
when using deno.land imports for OpenAI and Zod.
To Reproduce
(The example is from https://github.com/openai/openai-node/blob/master/helpers.md#auto-parsing-response-content-with-zod-schemas)
With deno.land imports
main.ts
:with
deno.json
:Running
deno check main.ts
fails with:With npm imports
main.ts
:with
deno.json
:Running
deno check main.ts
with npm imports is successfulOS
macOS
Node version
deno 1.45.5, typescript 5.5.2
Library version
4.55.4