公众号验证码功能完成 yeah!!!
This commit is contained in:
24
node_modules/openai/helpers/zod.mjs
generated
vendored
24
node_modules/openai/helpers/zod.mjs
generated
vendored
@@ -1,7 +1,9 @@
|
||||
import * as z4 from 'zod/v4';
|
||||
import { makeParseableResponseFormat, makeParseableTextFormat, makeParseableTool, } from "../lib/parser.mjs";
|
||||
import { zodToJsonSchema as _zodToJsonSchema } from "../_vendor/zod-to-json-schema/index.mjs";
|
||||
import { makeParseableResponseTool } from "../lib/ResponsesParser.mjs";
|
||||
function zodToJsonSchema(schema, options) {
|
||||
import { toStrictJsonSchema } from "../lib/transform.mjs";
|
||||
function zodV3ToJsonSchema(schema, options) {
|
||||
return _zodToJsonSchema(schema, {
|
||||
openaiStrictMode: true,
|
||||
name: options.name,
|
||||
@@ -10,6 +12,14 @@ function zodToJsonSchema(schema, options) {
|
||||
nullableStrategy: 'property',
|
||||
});
|
||||
}
|
||||
function zodV4ToJsonSchema(schema) {
|
||||
return toStrictJsonSchema(z4.toJSONSchema(schema, {
|
||||
target: 'draft-7',
|
||||
}));
|
||||
}
|
||||
function isZodV4(zodObject) {
|
||||
return '_zod' in zodObject;
|
||||
}
|
||||
/**
|
||||
* Creates a chat completion `JSONSchema` response format object from
|
||||
* the given Zod schema.
|
||||
@@ -54,7 +64,7 @@ export function zodResponseFormat(zodObject, name, props) {
|
||||
...props,
|
||||
name,
|
||||
strict: true,
|
||||
schema: zodToJsonSchema(zodObject, { name }),
|
||||
schema: isZodV4(zodObject) ? zodV4ToJsonSchema(zodObject) : zodV3ToJsonSchema(zodObject, { name }),
|
||||
},
|
||||
}, (content) => zodObject.parse(JSON.parse(content)));
|
||||
}
|
||||
@@ -64,7 +74,7 @@ export function zodTextFormat(zodObject, name, props) {
|
||||
...props,
|
||||
name,
|
||||
strict: true,
|
||||
schema: zodToJsonSchema(zodObject, { name }),
|
||||
schema: isZodV4(zodObject) ? zodV4ToJsonSchema(zodObject) : zodV3ToJsonSchema(zodObject, { name }),
|
||||
}, (content) => zodObject.parse(JSON.parse(content)));
|
||||
}
|
||||
/**
|
||||
@@ -78,7 +88,9 @@ export function zodFunction(options) {
|
||||
type: 'function',
|
||||
function: {
|
||||
name: options.name,
|
||||
parameters: zodToJsonSchema(options.parameters, { name: options.name }),
|
||||
parameters: isZodV4(options.parameters) ?
|
||||
zodV4ToJsonSchema(options.parameters)
|
||||
: zodV3ToJsonSchema(options.parameters, { name: options.name }),
|
||||
strict: true,
|
||||
...(options.description ? { description: options.description } : undefined),
|
||||
},
|
||||
@@ -91,7 +103,9 @@ export function zodResponsesFunction(options) {
|
||||
return makeParseableResponseTool({
|
||||
type: 'function',
|
||||
name: options.name,
|
||||
parameters: zodToJsonSchema(options.parameters, { name: options.name }),
|
||||
parameters: isZodV4(options.parameters) ?
|
||||
zodV4ToJsonSchema(options.parameters)
|
||||
: zodV3ToJsonSchema(options.parameters, { name: options.name }),
|
||||
strict: true,
|
||||
...(options.description ? { description: options.description } : undefined),
|
||||
}, {
|
||||
|
||||
Reference in New Issue
Block a user