@samchon/openapi
Advanced tools
Comparing version 2.0.0-dev.20241124-5 to 2.0.0-dev.20241125-2
@@ -51,3 +51,6 @@ "use strict"; | ||
var params = LlmConverterV3_1_1.LlmConverterV3_1.parameters({ | ||
config: props.config, | ||
config: { | ||
reference: props.config.reference, | ||
constraint: false, | ||
}, | ||
components: props.components, | ||
@@ -90,3 +93,6 @@ schema: props.schema, | ||
var schema = LlmConverterV3_1_1.LlmConverterV3_1.schema({ | ||
config: props.config, | ||
config: { | ||
reference: props.config.reference, | ||
constraint: false, | ||
}, | ||
components: props.components, | ||
@@ -93,0 +99,0 @@ $defs: props.$defs, |
@@ -5,3 +5,2 @@ "use strict"; | ||
var LlmTypeCheckerV3_1 = require("../utils/LlmTypeCheckerV3"); | ||
var OpenApiContraintShifter_1 = require("../utils/OpenApiContraintShifter"); | ||
var LlmConverterV3_1 = require("./LlmConverterV3"); | ||
@@ -41,12 +40,5 @@ var GeminiConverter; | ||
union = true; | ||
else if (LlmTypeCheckerV3_1.LlmTypeCheckerV3.isObject(v)) { | ||
if (v.additionalProperties !== undefined) | ||
delete v.additionalProperties; | ||
} | ||
else if (LlmTypeCheckerV3_1.LlmTypeCheckerV3.isArray(v)) | ||
OpenApiContraintShifter_1.OpenApiContraintShifter.shiftArray(v); | ||
else if (LlmTypeCheckerV3_1.LlmTypeCheckerV3.isString(v)) | ||
OpenApiContraintShifter_1.OpenApiContraintShifter.shiftString(v); | ||
else if (LlmTypeCheckerV3_1.LlmTypeCheckerV3.isNumber(v) || LlmTypeCheckerV3_1.LlmTypeCheckerV3.isInteger(v)) | ||
OpenApiContraintShifter_1.OpenApiContraintShifter.shiftNumeric(v); | ||
else if (LlmTypeCheckerV3_1.LlmTypeCheckerV3.isObject(v) && | ||
v.additionalProperties !== undefined) | ||
delete v.additionalProperties; | ||
}); | ||
@@ -53,0 +45,0 @@ return union ? null : schema; |
@@ -43,2 +43,3 @@ "use strict"; | ||
var LlmTypeCheckerV3_1 = require("../utils/LlmTypeCheckerV3"); | ||
var OpenApiContraintShifter_1 = require("../utils/OpenApiContraintShifter"); | ||
var OpenApiTypeChecker_1 = require("../utils/OpenApiTypeChecker"); | ||
@@ -75,2 +76,9 @@ var OpenApiV3Downgrader_1 = require("./OpenApiV3Downgrader"); | ||
} | ||
else if (props.config.constraint === false && | ||
(LlmTypeCheckerV3_1.LlmTypeCheckerV3.isInteger(schema) || | ||
LlmTypeCheckerV3_1.LlmTypeCheckerV3.isNumber(schema))) | ||
OpenApiContraintShifter_1.OpenApiContraintShifter.shiftNumeric(schema); | ||
else if (props.config.constraint === false && | ||
LlmTypeCheckerV3_1.LlmTypeCheckerV3.isString(schema)) | ||
OpenApiContraintShifter_1.OpenApiContraintShifter.shiftString(schema); | ||
}); | ||
@@ -77,0 +85,0 @@ return downgraded; |
@@ -68,3 +68,2 @@ import { OpenApi } from "../OpenApi"; | ||
chatgpt: { | ||
constraint: false; | ||
reference: false; | ||
@@ -71,0 +70,0 @@ }; |
@@ -66,3 +66,2 @@ "use strict"; | ||
chatgpt: { | ||
constraint: false, | ||
reference: false, | ||
@@ -69,0 +68,0 @@ }, |
@@ -36,19 +36,18 @@ /** | ||
* | ||
* Also, if you've composed the `IChatGptSchema` type with the | ||
* {@link IChatGptSchema.IConfig.constraint} `false` option (default `false`), | ||
* the `IChatGptSchema` would not compose these properties. Instead, these | ||
* properties would be written on {@link IChatGptSchema.__IAttribute.descripotion} | ||
* field like `@format uuid` case. | ||
* Also, ChatGPT has banned below constraint properties. Instead, I'll will | ||
* fill the {@link IChatGptSchema.__IAttribute.description} property with | ||
* the comment text like `"@format uuid"`. | ||
* | ||
* - {@link IChatGptSchema.INumber.minimum} | ||
* - {@link IChatGptSchema.INumber.maximum} | ||
* - {@link IChatGptSchema.INumber.multipleOf} | ||
* - {@link IChatGptSchema.IString.minLength} | ||
* - {@link IChatGptSchema.IString.maxLength} | ||
* - {@link IChatGptSchema.IString.format} | ||
* - {@link IChatGptSchema.IString.pattern} | ||
* - {@link IChatGptSchema.IString.contentMediaType} | ||
* - {@link IChatGptSchema.IArray.minItems} | ||
* - {@link IChatGptSchema.IArray.maxItems} | ||
* - {@link IChatGptSchema.IArray.unique} | ||
* - {@link OpenApi.IJsonSchema.INumber.minimum} | ||
* - {@link OpenApi.IJsonSchema.INumber.maximum} | ||
* - {@link OpenApi.IJsonSchema.INumber.multipleOf} | ||
* - {@link OpenApi.IJsonSchema.IString.minLength} | ||
* - {@link OpenApi.IJsonSchema.IString.maxLength} | ||
* - {@link OpenApi.IJsonSchema.IString.format} | ||
* - {@link OpenApi.IJsonSchema.IString.pattern} | ||
* - {@link OpenApi.IJsonSchema.IString.contentMediaType} | ||
* - {@link OpenApi.IJsonSchema.IString.default} | ||
* - {@link OpenApi.IJsonSchema.IArray.minItems} | ||
* - {@link OpenApi.IJsonSchema.IArray.maxItems} | ||
* - {@link OpenApi.IJsonSchema.IArray.unique} | ||
* | ||
@@ -90,6 +89,2 @@ * @reference https://platform.openai.com/docs/guides/function-calling | ||
enum?: Array<boolean>; | ||
/** | ||
* The default value. | ||
*/ | ||
default?: boolean; | ||
} | ||
@@ -104,45 +99,2 @@ /** | ||
enum?: Array<number>; | ||
/** | ||
* Default value. | ||
* | ||
* @type int64 | ||
*/ | ||
default?: number; | ||
/** | ||
* Minimum value restriction. | ||
* | ||
* @type int64 | ||
*/ | ||
minimum?: number; | ||
/** | ||
* Maximum value restriction. | ||
* | ||
* @type int64 | ||
*/ | ||
maximum?: number; | ||
/** | ||
* Exclusive minimum value restriction. | ||
* | ||
* For reference, even though your Swagger (or OpenAPI) document has | ||
* defined the `exclusiveMinimum` value as `number`, {@link IChatGptSchema} | ||
* forcibly converts it to `boolean` type, and assign the numeric value to | ||
* the {@link minimum} property. | ||
*/ | ||
exclusiveMinimum?: boolean; | ||
/** | ||
* Exclusive maximum value restriction. | ||
* | ||
* For reference, even though your Swagger (or OpenAPI) document has | ||
* defined the `exclusiveMaximum` value as `number`, {@link IChatGptSchema} | ||
* forcibly converts it to `boolean` type, and assign the numeric value to | ||
* the {@link maximum} property. | ||
*/ | ||
exclusiveMaximum?: boolean; | ||
/** | ||
* Multiple of value restriction. | ||
* | ||
* @type uint64 | ||
* @exclusiveMinimum 0 | ||
*/ | ||
multipleOf?: number; | ||
} | ||
@@ -157,38 +109,2 @@ /** | ||
enum?: Array<number>; | ||
/** | ||
* Default value. | ||
*/ | ||
default?: number; | ||
/** | ||
* Minimum value restriction. | ||
*/ | ||
minimum?: number; | ||
/** | ||
* Maximum value restriction. | ||
*/ | ||
maximum?: number; | ||
/** | ||
* Exclusive minimum value restriction. | ||
* | ||
* For reference, even though your Swagger (or OpenAPI) document has | ||
* defined the `exclusiveMinimum` value as `number`, {@link OpenAiComposer} | ||
* forcibly converts it to `boolean` type, and assign the numeric value to | ||
* the {@link minimum} property. | ||
*/ | ||
exclusiveMinimum?: boolean; | ||
/** | ||
* Exclusive maximum value restriction. | ||
* | ||
* For reference, even though your Swagger (or OpenAPI) document has | ||
* defined the `exclusiveMaximum` value as `number`, {@link OpenAiComposer} | ||
* forcibly converts it to `boolean` type, and assign the numeric value to | ||
* the {@link maximum} property. | ||
*/ | ||
exclusiveMaximum?: boolean; | ||
/** | ||
* Multiple of value restriction. | ||
* | ||
* @exclusiveMinimum 0 | ||
*/ | ||
multipleOf?: number; | ||
} | ||
@@ -203,30 +119,2 @@ /** | ||
enum?: Array<string>; | ||
/** | ||
* Default value. | ||
*/ | ||
default?: string; | ||
/** | ||
* Format restriction. | ||
*/ | ||
format?: "binary" | "byte" | "password" | "regex" | "uuid" | "email" | "hostname" | "idn-email" | "idn-hostname" | "iri" | "iri-reference" | "ipv4" | "ipv6" | "uri" | "uri-reference" | "uri-template" | "url" | "date-time" | "date" | "time" | "duration" | "json-pointer" | "relative-json-pointer" | (string & {}); | ||
/** | ||
* Pattern restriction. | ||
*/ | ||
pattern?: string; | ||
/** | ||
* Content media type restriction. | ||
*/ | ||
contentMediaType?: string; | ||
/** | ||
* Minimum length restriction. | ||
* | ||
* @type uint64 | ||
*/ | ||
minLength?: number; | ||
/** | ||
* Maximum length restriction. | ||
* | ||
* @type uint64 | ||
*/ | ||
maxLength?: number; | ||
} | ||
@@ -244,24 +132,2 @@ /** | ||
items: IChatGptSchema; | ||
/** | ||
* Unique items restriction. | ||
* | ||
* If this property value is `true`, target array must have unique items. | ||
*/ | ||
uniqueItems?: boolean; | ||
/** | ||
* Minimum items restriction. | ||
* | ||
* Restriction of minumum number of items in the array. | ||
* | ||
* @type uint64 | ||
*/ | ||
minItems?: number; | ||
/** | ||
* Maximum items restriction. | ||
* | ||
* Restriction of maximum number of items in the array. | ||
* | ||
* @type uint64 | ||
*/ | ||
maxItems?: number; | ||
} | ||
@@ -364,6 +230,2 @@ /** | ||
interface INull extends __ISignificant<"null"> { | ||
/** | ||
* Default value. | ||
*/ | ||
default?: null; | ||
} | ||
@@ -418,32 +280,2 @@ /** | ||
/** | ||
* Whether to allow contraint properties or not. | ||
* | ||
* If you configure this property to `false`, the schemas do not containt | ||
* the constraint properties of below. Instead, below properties would be | ||
* written to the {@link IChatGptSchema.__IAttribute.description} property | ||
* as a comment string like `"@format uuid"`. | ||
* | ||
* This is because the ChatGPT function calling understands the constraint | ||
* properties when the function parameter types are simple, however it occurs | ||
* some errors when the parameter types are complex. | ||
* | ||
* Therefore, considering the complexity of your parameter types, determine | ||
* which is better, to allow the constraint properties or not. | ||
* | ||
* - {@link IChatGptSchema.INumber.minimum} | ||
* - {@link IChatGptSchema.INumber.maximum} | ||
* - {@link IChatGptSchema.INumber.multipleOf} | ||
* - {@link IChatGptSchema.IString.minLength} | ||
* - {@link IChatGptSchema.IString.maxLength} | ||
* - {@link IChatGptSchema.IString.format} | ||
* - {@link IChatGptSchema.IString.pattern} | ||
* - {@link IChatGptSchema.IString.contentMediaType} | ||
* - {@link IChatGptSchema.IArray.minItems} | ||
* - {@link IChatGptSchema.IArray.maxItems} | ||
* - {@link IChatGptSchema.IArray.unique} | ||
* | ||
* @default false | ||
*/ | ||
constraint: boolean; | ||
/** | ||
* Whether to allow reference type in everywhere. | ||
@@ -450,0 +282,0 @@ * |
@@ -45,2 +45,3 @@ /** | ||
* - {@link OpenApi.IJsonSchema.IString.contentMediaType} | ||
* - {@link OpenApi.IJsonSchema.IString.default} | ||
* - {@link OpenApi.IJsonSchema.IArray.minItems} | ||
@@ -81,8 +82,2 @@ * - {@link OpenApi.IJsonSchema.IArray.maxItems} | ||
enum?: Array<boolean | null>; | ||
/** | ||
* Default value. | ||
* | ||
* @warning document of Gemini says not supported, but cannot sure | ||
*/ | ||
default?: boolean | null; | ||
} | ||
@@ -99,9 +94,2 @@ /** | ||
enum?: Array<number | null>; | ||
/** | ||
* Default value. | ||
* | ||
* @type int64 | ||
* @warning document of Gemini says not supported, but cannot sure | ||
*/ | ||
default?: number | null; | ||
} | ||
@@ -116,8 +104,2 @@ /** | ||
enum?: Array<number | null>; | ||
/** | ||
* Default value. | ||
* | ||
* @warning document of Gemini says not supported, but cannot sure | ||
*/ | ||
default?: number | null; | ||
} | ||
@@ -214,8 +196,2 @@ /** | ||
type: "null"; | ||
/** | ||
* Default value. | ||
* | ||
* @warning document of Gemini says not supported, but cannot sure | ||
*/ | ||
default?: null; | ||
} | ||
@@ -222,0 +198,0 @@ /** |
@@ -442,2 +442,3 @@ /** | ||
* - {@link ILlmSchemaV3_1.IString.contentMediaType} | ||
* - {@link ILlmSchemaV3_1.IString.default} | ||
* - {@link ILlmSchemaV3_1.IArray.minItems} | ||
@@ -444,0 +445,0 @@ * - {@link ILlmSchemaV3_1.IArray.maxItems} |
@@ -402,2 +402,3 @@ /** | ||
* - {@link ILlmSchemaV3.IString.contentMediaType} | ||
* - {@link ILlmSchemaV3.IString.default} | ||
* - {@link ILlmSchemaV3.IArray.minItems} | ||
@@ -404,0 +405,0 @@ * - {@link ILlmSchemaV3.IArray.maxItems} |
@@ -193,8 +193,16 @@ "use strict"; | ||
var coverArray = function (p) { | ||
if (!(p.x.minItems === undefined || | ||
(p.y.minItems !== undefined && p.x.minItems <= p.y.minItems))) | ||
return false; | ||
else if (!(p.x.maxItems === undefined || | ||
(p.y.maxItems !== undefined && p.x.maxItems >= p.y.maxItems))) | ||
return false; | ||
// if ( | ||
// !( | ||
// p.x.minItems === undefined || | ||
// (p.y.minItems !== undefined && p.x.minItems <= p.y.minItems) | ||
// ) | ||
// ) | ||
// return false; | ||
// else if ( | ||
// !( | ||
// p.x.maxItems === undefined || | ||
// (p.y.maxItems !== undefined && p.x.maxItems >= p.y.maxItems) | ||
// ) | ||
// ) | ||
// return false; | ||
return coverStation({ | ||
@@ -253,18 +261,18 @@ $defs: p.$defs, | ||
x.type === y.type, | ||
x.minimum === undefined || | ||
(y.minimum !== undefined && x.minimum <= y.minimum), | ||
x.maximum === undefined || | ||
(y.maximum !== undefined && x.maximum >= y.maximum), | ||
x.exclusiveMinimum !== true || | ||
x.minimum === undefined || | ||
(y.minimum !== undefined && | ||
(y.exclusiveMinimum === true || x.minimum < y.minimum)), | ||
x.exclusiveMaximum !== true || | ||
x.maximum === undefined || | ||
(y.maximum !== undefined && | ||
(y.exclusiveMaximum === true || x.maximum > y.maximum)), | ||
x.multipleOf === undefined || | ||
(y.multipleOf !== undefined && | ||
y.multipleOf / x.multipleOf === | ||
Math.floor(y.multipleOf / x.multipleOf)), | ||
// x.minimum === undefined || | ||
// (y.minimum !== undefined && x.minimum <= y.minimum), | ||
// x.maximum === undefined || | ||
// (y.maximum !== undefined && x.maximum >= y.maximum), | ||
// x.exclusiveMinimum !== true || | ||
// x.minimum === undefined || | ||
// (y.minimum !== undefined && | ||
// (y.exclusiveMinimum === true || x.minimum < y.minimum)), | ||
// x.exclusiveMaximum !== true || | ||
// x.maximum === undefined || | ||
// (y.maximum !== undefined && | ||
// (y.exclusiveMaximum === true || x.maximum > y.maximum)), | ||
// x.multipleOf === undefined || | ||
// (y.multipleOf !== undefined && | ||
// y.multipleOf / x.multipleOf === | ||
// Math.floor(y.multipleOf / x.multipleOf)), | ||
].every(function (v) { return v; }); | ||
@@ -278,18 +286,18 @@ }; | ||
x.type === y.type || (x.type === "number" && y.type === "integer"), | ||
x.minimum === undefined || | ||
(y.minimum !== undefined && x.minimum <= y.minimum), | ||
x.maximum === undefined || | ||
(y.maximum !== undefined && x.maximum >= y.maximum), | ||
x.exclusiveMinimum !== true || | ||
x.minimum === undefined || | ||
(y.minimum !== undefined && | ||
(y.exclusiveMinimum === true || x.minimum < y.minimum)), | ||
x.exclusiveMaximum !== true || | ||
x.maximum === undefined || | ||
(y.maximum !== undefined && | ||
(y.exclusiveMaximum === true || x.maximum > y.maximum)), | ||
x.multipleOf === undefined || | ||
(y.multipleOf !== undefined && | ||
y.multipleOf / x.multipleOf === | ||
Math.floor(y.multipleOf / x.multipleOf)), | ||
// x.minimum === undefined || | ||
// (y.minimum !== undefined && x.minimum <= y.minimum), | ||
// x.maximum === undefined || | ||
// (y.maximum !== undefined && x.maximum >= y.maximum), | ||
// x.exclusiveMinimum !== true || | ||
// x.minimum === undefined || | ||
// (y.minimum !== undefined && | ||
// (y.exclusiveMinimum === true || x.minimum < y.minimum)), | ||
// x.exclusiveMaximum !== true || | ||
// x.maximum === undefined || | ||
// (y.maximum !== undefined && | ||
// (y.exclusiveMaximum === true || x.maximum > y.maximum)), | ||
// x.multipleOf === undefined || | ||
// (y.multipleOf !== undefined && | ||
// y.multipleOf / x.multipleOf === | ||
// Math.floor(y.multipleOf / x.multipleOf)), | ||
].every(function (v) { return v; }); | ||
@@ -303,19 +311,11 @@ }; | ||
x.type === y.type, | ||
x.format === undefined || | ||
(y.format !== undefined && coverFormat(x.format, y.format)), | ||
x.pattern === undefined || x.pattern === y.pattern, | ||
x.minLength === undefined || | ||
(y.minLength !== undefined && x.minLength <= y.minLength), | ||
x.maxLength === undefined || | ||
(y.maxLength !== undefined && x.maxLength >= y.maxLength), | ||
// x.format === undefined || | ||
// (y.format !== undefined && coverFormat(x.format, y.format)), | ||
// x.pattern === undefined || x.pattern === y.pattern, | ||
// x.minLength === undefined || | ||
// (y.minLength !== undefined && x.minLength <= y.minLength), | ||
// x.maxLength === undefined || | ||
// (y.maxLength !== undefined && x.maxLength >= y.maxLength), | ||
].every(function (v) { return v; }); | ||
}; | ||
var coverFormat = function (x, y) { | ||
return x === y || | ||
(x === "idn-email" && y === "email") || | ||
(x === "idn-hostname" && y === "hostname") || | ||
(["uri", "iri"].includes(x) && y === "url") || | ||
(x === "iri" && y === "uri") || | ||
(x === "iri-reference" && y === "uri-reference"); | ||
}; | ||
var flatSchema = function ($defs, schema) { | ||
@@ -322,0 +322,0 @@ schema = escapeReference($defs, schema); |
import { OpenApi } from "../OpenApi"; | ||
export declare namespace OpenApiContraintShifter { | ||
const shiftArray: <Schema extends Pick<OpenApi.IJsonSchema.IArray, "description" | "minItems" | "maxItems" | "uniqueItems">>(v: Schema) => Omit<Schema, "minItems" | "maxItems" | "uniqueItems">; | ||
const shiftNumeric: <Schema extends Pick<OpenApi.IJsonSchema.INumber | OpenApi.IJsonSchema.IInteger, "description" | "minimum" | "maximum" | "exclusiveMinimum" | "exclusiveMaximum" | "multipleOf">>(v: Schema) => Omit<Schema, "minimum" | "maximum" | "exclusiveMinimum" | "exclusiveMaximum" | "multipleOf">; | ||
const shiftString: <Schema extends Pick<OpenApi.IJsonSchema.IString, "description" | "minLength" | "maxLength" | "format" | "pattern" | "contentMediaType">>(v: Schema) => Omit<Schema, "minLength" | "maxLength" | "format" | "pattern" | "contentMediaType">; | ||
const shiftNumeric: <Schema extends Pick<OpenApi.IJsonSchema.INumber | OpenApi.IJsonSchema.IInteger, "description" | "minimum" | "maximum" | "exclusiveMinimum" | "exclusiveMaximum" | "multipleOf" | "default">>(v: Schema) => Omit<Schema, "minimum" | "maximum" | "exclusiveMinimum" | "exclusiveMaximum" | "multipleOf" | "default">; | ||
const shiftString: <Schema extends Pick<OpenApi.IJsonSchema.IString, "description" | "minLength" | "maxLength" | "format" | "pattern" | "contentMediaType" | "default">>(v: Schema) => Omit<Schema, "minLength" | "maxLength" | "format" | "pattern" | "contentMediaType" | "default">; | ||
} |
@@ -74,2 +74,6 @@ "use strict"; | ||
} | ||
if (v.default !== undefined) { | ||
tags.push("@default ".concat(v.default)); | ||
delete v.default; | ||
} | ||
v.description = writeTagWithDescription({ | ||
@@ -103,2 +107,6 @@ description: v.description, | ||
} | ||
if (v.default !== undefined) { | ||
tags.push("@default ".concat(v.default)); | ||
delete v.default; | ||
} | ||
v.description = writeTagWithDescription({ | ||
@@ -105,0 +113,0 @@ description: v.description, |
{ | ||
"name": "@samchon/openapi", | ||
"version": "2.0.0-dev.20241124-5", | ||
"version": "2.0.0-dev.20241125-2", | ||
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -17,3 +17,6 @@ import { OpenApi } from "../OpenApi"; | ||
LlmConverterV3_1.parameters({ | ||
config: props.config, | ||
config: { | ||
reference: props.config.reference, | ||
constraint: false, | ||
}, | ||
components: props.components, | ||
@@ -38,3 +41,6 @@ schema: props.schema, | ||
const schema: ILlmSchemaV3_1 | null = LlmConverterV3_1.schema({ | ||
config: props.config, | ||
config: { | ||
reference: props.config.reference, | ||
constraint: false, | ||
}, | ||
components: props.components, | ||
@@ -41,0 +47,0 @@ $defs: props.$defs, |
@@ -5,3 +5,2 @@ import { OpenApi } from "../OpenApi"; | ||
import { LlmTypeCheckerV3 } from "../utils/LlmTypeCheckerV3"; | ||
import { OpenApiContraintShifter } from "../utils/OpenApiContraintShifter"; | ||
import { LlmConverterV3 } from "./LlmConverterV3"; | ||
@@ -47,11 +46,7 @@ | ||
if (LlmTypeCheckerV3.isOneOf(v)) union = true; | ||
else if (LlmTypeCheckerV3.isObject(v)) { | ||
if (v.additionalProperties !== undefined) | ||
delete (v as Partial<ILlmSchemaV3.IObject>).additionalProperties; | ||
} else if (LlmTypeCheckerV3.isArray(v)) | ||
OpenApiContraintShifter.shiftArray(v); | ||
else if (LlmTypeCheckerV3.isString(v)) | ||
OpenApiContraintShifter.shiftString(v); | ||
else if (LlmTypeCheckerV3.isNumber(v) || LlmTypeCheckerV3.isInteger(v)) | ||
OpenApiContraintShifter.shiftNumeric(v); | ||
else if ( | ||
LlmTypeCheckerV3.isObject(v) && | ||
v.additionalProperties !== undefined | ||
) | ||
delete (v as Partial<ILlmSchemaV3.IObject>).additionalProperties; | ||
}); | ||
@@ -58,0 +53,0 @@ return union ? null : schema; |
import { OpenApi } from "../OpenApi"; | ||
import { ILlmSchemaV3 } from "../structures/ILlmSchemaV3"; | ||
import { LlmTypeCheckerV3 } from "../utils/LlmTypeCheckerV3"; | ||
import { OpenApiContraintShifter } from "../utils/OpenApiContraintShifter"; | ||
import { OpenApiTypeChecker } from "../utils/OpenApiTypeChecker"; | ||
@@ -42,3 +43,17 @@ import { OpenApiV3Downgrader } from "./OpenApiV3Downgrader"; | ||
schema.additionalProperties = false; | ||
} | ||
} else if ( | ||
props.config.constraint === false && | ||
(LlmTypeCheckerV3.isInteger(schema) || | ||
LlmTypeCheckerV3.isNumber(schema)) | ||
) | ||
OpenApiContraintShifter.shiftNumeric( | ||
schema as OpenApi.IJsonSchema.IInteger | OpenApi.IJsonSchema.INumber, | ||
); | ||
else if ( | ||
props.config.constraint === false && | ||
LlmTypeCheckerV3.isString(schema) | ||
) | ||
OpenApiContraintShifter.shiftString( | ||
schema as OpenApi.IJsonSchema.IString, | ||
); | ||
}); | ||
@@ -45,0 +60,0 @@ return downgraded; |
@@ -116,3 +116,2 @@ import { OpenApi } from "../OpenApi"; | ||
chatgpt: { | ||
constraint: false, | ||
reference: false, | ||
@@ -119,0 +118,0 @@ } satisfies IChatGptSchema.IConfig, |
@@ -36,19 +36,18 @@ /** | ||
* | ||
* Also, if you've composed the `IChatGptSchema` type with the | ||
* {@link IChatGptSchema.IConfig.constraint} `false` option (default `false`), | ||
* the `IChatGptSchema` would not compose these properties. Instead, these | ||
* properties would be written on {@link IChatGptSchema.__IAttribute.descripotion} | ||
* field like `@format uuid` case. | ||
* Also, ChatGPT has banned below constraint properties. Instead, I'll will | ||
* fill the {@link IChatGptSchema.__IAttribute.description} property with | ||
* the comment text like `"@format uuid"`. | ||
* | ||
* - {@link IChatGptSchema.INumber.minimum} | ||
* - {@link IChatGptSchema.INumber.maximum} | ||
* - {@link IChatGptSchema.INumber.multipleOf} | ||
* - {@link IChatGptSchema.IString.minLength} | ||
* - {@link IChatGptSchema.IString.maxLength} | ||
* - {@link IChatGptSchema.IString.format} | ||
* - {@link IChatGptSchema.IString.pattern} | ||
* - {@link IChatGptSchema.IString.contentMediaType} | ||
* - {@link IChatGptSchema.IArray.minItems} | ||
* - {@link IChatGptSchema.IArray.maxItems} | ||
* - {@link IChatGptSchema.IArray.unique} | ||
* - {@link OpenApi.IJsonSchema.INumber.minimum} | ||
* - {@link OpenApi.IJsonSchema.INumber.maximum} | ||
* - {@link OpenApi.IJsonSchema.INumber.multipleOf} | ||
* - {@link OpenApi.IJsonSchema.IString.minLength} | ||
* - {@link OpenApi.IJsonSchema.IString.maxLength} | ||
* - {@link OpenApi.IJsonSchema.IString.format} | ||
* - {@link OpenApi.IJsonSchema.IString.pattern} | ||
* - {@link OpenApi.IJsonSchema.IString.contentMediaType} | ||
* - {@link OpenApi.IJsonSchema.IString.default} | ||
* - {@link OpenApi.IJsonSchema.IArray.minItems} | ||
* - {@link OpenApi.IJsonSchema.IArray.maxItems} | ||
* - {@link OpenApi.IJsonSchema.IArray.unique} | ||
* | ||
@@ -101,7 +100,2 @@ * @reference https://platform.openai.com/docs/guides/function-calling | ||
enum?: Array<boolean>; | ||
/** | ||
* The default value. | ||
*/ | ||
default?: boolean; | ||
} | ||
@@ -117,51 +111,2 @@ | ||
enum?: Array<number>; | ||
/** | ||
* Default value. | ||
* | ||
* @type int64 | ||
*/ | ||
default?: number; | ||
/** | ||
* Minimum value restriction. | ||
* | ||
* @type int64 | ||
*/ | ||
minimum?: number; | ||
/** | ||
* Maximum value restriction. | ||
* | ||
* @type int64 | ||
*/ | ||
maximum?: number; | ||
/** | ||
* Exclusive minimum value restriction. | ||
* | ||
* For reference, even though your Swagger (or OpenAPI) document has | ||
* defined the `exclusiveMinimum` value as `number`, {@link IChatGptSchema} | ||
* forcibly converts it to `boolean` type, and assign the numeric value to | ||
* the {@link minimum} property. | ||
*/ | ||
exclusiveMinimum?: boolean; | ||
/** | ||
* Exclusive maximum value restriction. | ||
* | ||
* For reference, even though your Swagger (or OpenAPI) document has | ||
* defined the `exclusiveMaximum` value as `number`, {@link IChatGptSchema} | ||
* forcibly converts it to `boolean` type, and assign the numeric value to | ||
* the {@link maximum} property. | ||
*/ | ||
exclusiveMaximum?: boolean; | ||
/** | ||
* Multiple of value restriction. | ||
* | ||
* @type uint64 | ||
* @exclusiveMinimum 0 | ||
*/ | ||
multipleOf?: number; | ||
} | ||
@@ -177,44 +122,2 @@ | ||
enum?: Array<number>; | ||
/** | ||
* Default value. | ||
*/ | ||
default?: number; | ||
/** | ||
* Minimum value restriction. | ||
*/ | ||
minimum?: number; | ||
/** | ||
* Maximum value restriction. | ||
*/ | ||
maximum?: number; | ||
/** | ||
* Exclusive minimum value restriction. | ||
* | ||
* For reference, even though your Swagger (or OpenAPI) document has | ||
* defined the `exclusiveMinimum` value as `number`, {@link OpenAiComposer} | ||
* forcibly converts it to `boolean` type, and assign the numeric value to | ||
* the {@link minimum} property. | ||
*/ | ||
exclusiveMinimum?: boolean; | ||
/** | ||
* Exclusive maximum value restriction. | ||
* | ||
* For reference, even though your Swagger (or OpenAPI) document has | ||
* defined the `exclusiveMaximum` value as `number`, {@link OpenAiComposer} | ||
* forcibly converts it to `boolean` type, and assign the numeric value to | ||
* the {@link maximum} property. | ||
*/ | ||
exclusiveMaximum?: boolean; | ||
/** | ||
* Multiple of value restriction. | ||
* | ||
* @exclusiveMinimum 0 | ||
*/ | ||
multipleOf?: number; | ||
} | ||
@@ -230,60 +133,2 @@ | ||
enum?: Array<string>; | ||
/** | ||
* Default value. | ||
*/ | ||
default?: string; | ||
/** | ||
* Format restriction. | ||
*/ | ||
format?: | ||
| "binary" | ||
| "byte" | ||
| "password" | ||
| "regex" | ||
| "uuid" | ||
| "email" | ||
| "hostname" | ||
| "idn-email" | ||
| "idn-hostname" | ||
| "iri" | ||
| "iri-reference" | ||
| "ipv4" | ||
| "ipv6" | ||
| "uri" | ||
| "uri-reference" | ||
| "uri-template" | ||
| "url" | ||
| "date-time" | ||
| "date" | ||
| "time" | ||
| "duration" | ||
| "json-pointer" | ||
| "relative-json-pointer" | ||
| (string & {}); | ||
/** | ||
* Pattern restriction. | ||
*/ | ||
pattern?: string; | ||
/** | ||
* Content media type restriction. | ||
*/ | ||
contentMediaType?: string; | ||
/** | ||
* Minimum length restriction. | ||
* | ||
* @type uint64 | ||
*/ | ||
minLength?: number; | ||
/** | ||
* Maximum length restriction. | ||
* | ||
* @type uint64 | ||
*/ | ||
maxLength?: number; | ||
} | ||
@@ -302,27 +147,2 @@ | ||
items: IChatGptSchema; | ||
/** | ||
* Unique items restriction. | ||
* | ||
* If this property value is `true`, target array must have unique items. | ||
*/ | ||
uniqueItems?: boolean; | ||
/** | ||
* Minimum items restriction. | ||
* | ||
* Restriction of minumum number of items in the array. | ||
* | ||
* @type uint64 | ||
*/ | ||
minItems?: number; | ||
/** | ||
* Maximum items restriction. | ||
* | ||
* Restriction of maximum number of items in the array. | ||
* | ||
* @type uint64 | ||
*/ | ||
maxItems?: number; | ||
} | ||
@@ -430,8 +250,3 @@ | ||
*/ | ||
export interface INull extends __ISignificant<"null"> { | ||
/** | ||
* Default value. | ||
*/ | ||
default?: null; | ||
} | ||
export interface INull extends __ISignificant<"null"> {} | ||
@@ -493,33 +308,2 @@ /** | ||
/** | ||
* Whether to allow contraint properties or not. | ||
* | ||
* If you configure this property to `false`, the schemas do not containt | ||
* the constraint properties of below. Instead, below properties would be | ||
* written to the {@link IChatGptSchema.__IAttribute.description} property | ||
* as a comment string like `"@format uuid"`. | ||
* | ||
* This is because the ChatGPT function calling understands the constraint | ||
* properties when the function parameter types are simple, however it occurs | ||
* some errors when the parameter types are complex. | ||
* | ||
* Therefore, considering the complexity of your parameter types, determine | ||
* which is better, to allow the constraint properties or not. | ||
* | ||
* - {@link IChatGptSchema.INumber.minimum} | ||
* - {@link IChatGptSchema.INumber.maximum} | ||
* - {@link IChatGptSchema.INumber.multipleOf} | ||
* - {@link IChatGptSchema.IString.minLength} | ||
* - {@link IChatGptSchema.IString.maxLength} | ||
* - {@link IChatGptSchema.IString.format} | ||
* - {@link IChatGptSchema.IString.pattern} | ||
* - {@link IChatGptSchema.IString.contentMediaType} | ||
* - {@link IChatGptSchema.IArray.minItems} | ||
* - {@link IChatGptSchema.IArray.maxItems} | ||
* - {@link IChatGptSchema.IArray.unique} | ||
* | ||
* @default false | ||
*/ | ||
constraint: boolean; | ||
/** | ||
* Whether to allow reference type in everywhere. | ||
@@ -526,0 +310,0 @@ * |
@@ -45,2 +45,3 @@ /** | ||
* - {@link OpenApi.IJsonSchema.IString.contentMediaType} | ||
* - {@link OpenApi.IJsonSchema.IString.default} | ||
* - {@link OpenApi.IJsonSchema.IArray.minItems} | ||
@@ -90,9 +91,2 @@ * - {@link OpenApi.IJsonSchema.IArray.maxItems} | ||
enum?: Array<boolean | null>; | ||
/** | ||
* Default value. | ||
* | ||
* @warning document of Gemini says not supported, but cannot sure | ||
*/ | ||
default?: boolean | null; | ||
} | ||
@@ -110,10 +104,2 @@ | ||
enum?: Array<number | null>; | ||
/** | ||
* Default value. | ||
* | ||
* @type int64 | ||
* @warning document of Gemini says not supported, but cannot sure | ||
*/ | ||
default?: number | null; | ||
} | ||
@@ -129,9 +115,2 @@ | ||
enum?: Array<number | null>; | ||
/** | ||
* Default value. | ||
* | ||
* @warning document of Gemini says not supported, but cannot sure | ||
*/ | ||
default?: number | null; | ||
} | ||
@@ -234,9 +213,2 @@ | ||
type: "null"; | ||
/** | ||
* Default value. | ||
* | ||
* @warning document of Gemini says not supported, but cannot sure | ||
*/ | ||
default?: null; | ||
} | ||
@@ -243,0 +215,0 @@ |
@@ -517,2 +517,3 @@ /** | ||
* - {@link ILlmSchemaV3_1.IString.contentMediaType} | ||
* - {@link ILlmSchemaV3_1.IString.default} | ||
* - {@link ILlmSchemaV3_1.IArray.minItems} | ||
@@ -519,0 +520,0 @@ * - {@link ILlmSchemaV3_1.IArray.maxItems} |
@@ -480,2 +480,3 @@ /** | ||
* - {@link ILlmSchemaV3.IString.contentMediaType} | ||
* - {@link ILlmSchemaV3.IString.default} | ||
* - {@link ILlmSchemaV3.IArray.minItems} | ||
@@ -482,0 +483,0 @@ * - {@link ILlmSchemaV3.IArray.maxItems} |
@@ -193,16 +193,16 @@ import { IChatGptSchema } from "../structures/IChatGptSchema"; | ||
}): boolean => { | ||
if ( | ||
!( | ||
p.x.minItems === undefined || | ||
(p.y.minItems !== undefined && p.x.minItems <= p.y.minItems) | ||
) | ||
) | ||
return false; | ||
else if ( | ||
!( | ||
p.x.maxItems === undefined || | ||
(p.y.maxItems !== undefined && p.x.maxItems >= p.y.maxItems) | ||
) | ||
) | ||
return false; | ||
// if ( | ||
// !( | ||
// p.x.minItems === undefined || | ||
// (p.y.minItems !== undefined && p.x.minItems <= p.y.minItems) | ||
// ) | ||
// ) | ||
// return false; | ||
// else if ( | ||
// !( | ||
// p.x.maxItems === undefined || | ||
// (p.y.maxItems !== undefined && p.x.maxItems >= p.y.maxItems) | ||
// ) | ||
// ) | ||
// return false; | ||
return coverStation({ | ||
@@ -272,18 +272,18 @@ $defs: p.$defs, | ||
x.type === y.type, | ||
x.minimum === undefined || | ||
(y.minimum !== undefined && x.minimum <= y.minimum), | ||
x.maximum === undefined || | ||
(y.maximum !== undefined && x.maximum >= y.maximum), | ||
x.exclusiveMinimum !== true || | ||
x.minimum === undefined || | ||
(y.minimum !== undefined && | ||
(y.exclusiveMinimum === true || x.minimum < y.minimum)), | ||
x.exclusiveMaximum !== true || | ||
x.maximum === undefined || | ||
(y.maximum !== undefined && | ||
(y.exclusiveMaximum === true || x.maximum > y.maximum)), | ||
x.multipleOf === undefined || | ||
(y.multipleOf !== undefined && | ||
y.multipleOf / x.multipleOf === | ||
Math.floor(y.multipleOf / x.multipleOf)), | ||
// x.minimum === undefined || | ||
// (y.minimum !== undefined && x.minimum <= y.minimum), | ||
// x.maximum === undefined || | ||
// (y.maximum !== undefined && x.maximum >= y.maximum), | ||
// x.exclusiveMinimum !== true || | ||
// x.minimum === undefined || | ||
// (y.minimum !== undefined && | ||
// (y.exclusiveMinimum === true || x.minimum < y.minimum)), | ||
// x.exclusiveMaximum !== true || | ||
// x.maximum === undefined || | ||
// (y.maximum !== undefined && | ||
// (y.exclusiveMaximum === true || x.maximum > y.maximum)), | ||
// x.multipleOf === undefined || | ||
// (y.multipleOf !== undefined && | ||
// y.multipleOf / x.multipleOf === | ||
// Math.floor(y.multipleOf / x.multipleOf)), | ||
].every((v) => v); | ||
@@ -300,18 +300,18 @@ }; | ||
x.type === y.type || (x.type === "number" && y.type === "integer"), | ||
x.minimum === undefined || | ||
(y.minimum !== undefined && x.minimum <= y.minimum), | ||
x.maximum === undefined || | ||
(y.maximum !== undefined && x.maximum >= y.maximum), | ||
x.exclusiveMinimum !== true || | ||
x.minimum === undefined || | ||
(y.minimum !== undefined && | ||
(y.exclusiveMinimum === true || x.minimum < y.minimum)), | ||
x.exclusiveMaximum !== true || | ||
x.maximum === undefined || | ||
(y.maximum !== undefined && | ||
(y.exclusiveMaximum === true || x.maximum > y.maximum)), | ||
x.multipleOf === undefined || | ||
(y.multipleOf !== undefined && | ||
y.multipleOf / x.multipleOf === | ||
Math.floor(y.multipleOf / x.multipleOf)), | ||
// x.minimum === undefined || | ||
// (y.minimum !== undefined && x.minimum <= y.minimum), | ||
// x.maximum === undefined || | ||
// (y.maximum !== undefined && x.maximum >= y.maximum), | ||
// x.exclusiveMinimum !== true || | ||
// x.minimum === undefined || | ||
// (y.minimum !== undefined && | ||
// (y.exclusiveMinimum === true || x.minimum < y.minimum)), | ||
// x.exclusiveMaximum !== true || | ||
// x.maximum === undefined || | ||
// (y.maximum !== undefined && | ||
// (y.exclusiveMaximum === true || x.maximum > y.maximum)), | ||
// x.multipleOf === undefined || | ||
// (y.multipleOf !== undefined && | ||
// y.multipleOf / x.multipleOf === | ||
// Math.floor(y.multipleOf / x.multipleOf)), | ||
].every((v) => v); | ||
@@ -328,23 +328,12 @@ }; | ||
x.type === y.type, | ||
x.format === undefined || | ||
(y.format !== undefined && coverFormat(x.format, y.format)), | ||
x.pattern === undefined || x.pattern === y.pattern, | ||
x.minLength === undefined || | ||
(y.minLength !== undefined && x.minLength <= y.minLength), | ||
x.maxLength === undefined || | ||
(y.maxLength !== undefined && x.maxLength >= y.maxLength), | ||
// x.format === undefined || | ||
// (y.format !== undefined && coverFormat(x.format, y.format)), | ||
// x.pattern === undefined || x.pattern === y.pattern, | ||
// x.minLength === undefined || | ||
// (y.minLength !== undefined && x.minLength <= y.minLength), | ||
// x.maxLength === undefined || | ||
// (y.maxLength !== undefined && x.maxLength >= y.maxLength), | ||
].every((v) => v); | ||
}; | ||
const coverFormat = ( | ||
x: Required<IChatGptSchema.IString>["format"], | ||
y: Required<IChatGptSchema.IString>["format"], | ||
): boolean => | ||
x === y || | ||
(x === "idn-email" && y === "email") || | ||
(x === "idn-hostname" && y === "hostname") || | ||
(["uri", "iri"].includes(x) && y === "url") || | ||
(x === "iri" && y === "uri") || | ||
(x === "iri-reference" && y === "uri-reference"); | ||
const flatSchema = ( | ||
@@ -351,0 +340,0 @@ $defs: Record<string, IChatGptSchema> | undefined, |
@@ -41,2 +41,3 @@ import { OpenApi } from "../OpenApi"; | ||
| "multipleOf" | ||
| "default" | ||
>, | ||
@@ -52,2 +53,3 @@ >( | ||
| "multipleOf" | ||
| "default" | ||
> => { | ||
@@ -75,2 +77,6 @@ const tags: string[] = []; | ||
} | ||
if (v.default !== undefined) { | ||
tags.push(`@default ${v.default}`); | ||
delete v.default; | ||
} | ||
v.description = writeTagWithDescription({ | ||
@@ -92,2 +98,3 @@ description: v.description, | ||
| "contentMediaType" | ||
| "default" | ||
>, | ||
@@ -98,3 +105,8 @@ >( | ||
Schema, | ||
"minLength" | "maxLength" | "format" | "pattern" | "contentMediaType" | ||
| "minLength" | ||
| "maxLength" | ||
| "format" | ||
| "pattern" | ||
| "contentMediaType" | ||
| "default" | ||
> => { | ||
@@ -122,2 +134,6 @@ const tags: string[] = []; | ||
} | ||
if (v.default !== undefined) { | ||
tags.push(`@default ${v.default}`); | ||
delete v.default; | ||
} | ||
v.description = writeTagWithDescription({ | ||
@@ -124,0 +140,0 @@ description: v.description, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1594460
27496