公众号验证码功能完成 yeah!!!
This commit is contained in:
25
node_modules/openai/helpers/zod.js
generated
vendored
25
node_modules/openai/helpers/zod.js
generated
vendored
@@ -4,10 +4,13 @@ exports.zodResponseFormat = zodResponseFormat;
|
||||
exports.zodTextFormat = zodTextFormat;
|
||||
exports.zodFunction = zodFunction;
|
||||
exports.zodResponsesFunction = zodResponsesFunction;
|
||||
const tslib_1 = require("../internal/tslib.js");
|
||||
const z4 = tslib_1.__importStar(require("zod/v4"));
|
||||
const parser_1 = require("../lib/parser.js");
|
||||
const zod_to_json_schema_1 = require("../_vendor/zod-to-json-schema/index.js");
|
||||
const ResponsesParser_1 = require("../lib/ResponsesParser.js");
|
||||
function zodToJsonSchema(schema, options) {
|
||||
const transform_1 = require("../lib/transform.js");
|
||||
function zodV3ToJsonSchema(schema, options) {
|
||||
return (0, zod_to_json_schema_1.zodToJsonSchema)(schema, {
|
||||
openaiStrictMode: true,
|
||||
name: options.name,
|
||||
@@ -16,6 +19,14 @@ function zodToJsonSchema(schema, options) {
|
||||
nullableStrategy: 'property',
|
||||
});
|
||||
}
|
||||
function zodV4ToJsonSchema(schema) {
|
||||
return (0, transform_1.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.
|
||||
@@ -60,7 +71,7 @@ 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)));
|
||||
}
|
||||
@@ -70,7 +81,7 @@ 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)));
|
||||
}
|
||||
/**
|
||||
@@ -84,7 +95,9 @@ 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),
|
||||
},
|
||||
@@ -97,7 +110,9 @@ function zodResponsesFunction(options) {
|
||||
return (0, ResponsesParser_1.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