mdi-llmkit 1.0.1 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -190
- package/dist/src/comparison/compareLists.js +64 -64
- package/dist/src/jsonSurgery/jsonSurgery.js +285 -285
- package/dist/tests/comparison/compareLists.test.js +12 -12
- package/dist/tests/jsonSurgery/jsonSurgery.test.js +1 -1
- package/package.json +57 -53
- package/dist/gpt_api/functions.d.ts +0 -25
- package/dist/gpt_api/functions.js +0 -193
- package/dist/gpt_api/gpt_conversation.d.ts +0 -43
- package/dist/gpt_api/gpt_conversation.js +0 -146
- package/dist/gpt_api/json_schema_format.d.ts +0 -18
- package/dist/gpt_api/json_schema_format.js +0 -195
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
export const JSON_INTEGER = Symbol("JSON_INTEGER");
|
|
2
|
-
export const JSON_NUMBER = Symbol("JSON_NUMBER");
|
|
3
|
-
export const JSON_STRING = String;
|
|
4
|
-
export const JSON_BOOLEAN = Boolean;
|
|
5
|
-
const TYPEMAP = new Map([
|
|
6
|
-
[JSON_STRING, "string"],
|
|
7
|
-
[JSON_INTEGER, "integer"],
|
|
8
|
-
[JSON_NUMBER, "number"],
|
|
9
|
-
[JSON_BOOLEAN, "boolean"],
|
|
10
|
-
[String, "string"],
|
|
11
|
-
[Boolean, "boolean"],
|
|
12
|
-
[BigInt, "integer"],
|
|
13
|
-
[Number, "number"],
|
|
14
|
-
]);
|
|
15
|
-
function isRecord(value) {
|
|
16
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
-
}
|
|
18
|
-
function isStringArray(value) {
|
|
19
|
-
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
20
|
-
}
|
|
21
|
-
function isNumericRangeArray(value) {
|
|
22
|
-
if (!Array.isArray(value) || value.length !== 2) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
const [min, max] = value;
|
|
26
|
-
const minValid = min === null || typeof min === "number";
|
|
27
|
-
const maxValid = max === null || typeof max === "number";
|
|
28
|
-
return minValid && maxValid && (typeof min === "number" || typeof max === "number");
|
|
29
|
-
}
|
|
30
|
-
function isTupleMetadataArray(value) {
|
|
31
|
-
if (!Array.isArray(value) || value.length < 2) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
if (isStringArray(value)) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
return value.some((item) => typeof item === "string" || isNumericRangeArray(item));
|
|
38
|
-
}
|
|
39
|
-
function inferPrimitiveType(schemaValue) {
|
|
40
|
-
const direct = TYPEMAP.get(schemaValue);
|
|
41
|
-
if (direct) {
|
|
42
|
-
return direct;
|
|
43
|
-
}
|
|
44
|
-
if (typeof schemaValue === "string") {
|
|
45
|
-
return "string";
|
|
46
|
-
}
|
|
47
|
-
if (typeof schemaValue === "boolean") {
|
|
48
|
-
return "boolean";
|
|
49
|
-
}
|
|
50
|
-
if (typeof schemaValue === "bigint") {
|
|
51
|
-
return "integer";
|
|
52
|
-
}
|
|
53
|
-
if (typeof schemaValue === "number") {
|
|
54
|
-
return Number.isInteger(schemaValue) ? "integer" : "number";
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
function convertSchemaRecursive(subschema) {
|
|
59
|
-
let subschemaDescription = "";
|
|
60
|
-
let subschemaEnum = [];
|
|
61
|
-
let subschemaNumrange = [null, null];
|
|
62
|
-
let subschemaValue = subschema;
|
|
63
|
-
if (isTupleMetadataArray(subschema)) {
|
|
64
|
-
for (const item of subschema) {
|
|
65
|
-
if (!item) {
|
|
66
|
-
subschemaValue = item;
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (typeof item === "string") {
|
|
70
|
-
subschemaDescription = item;
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (isStringArray(item) && item.length >= 2) {
|
|
74
|
-
subschemaEnum = item;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (isNumericRangeArray(item)) {
|
|
78
|
-
subschemaNumrange = item;
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
subschemaValue = item;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if ((Array.isArray(subschemaValue) && isTupleMetadataArray(subschemaValue)) ||
|
|
85
|
-
(Array.isArray(subschemaValue) && subschemaValue.length === 0)) {
|
|
86
|
-
if (subschemaEnum.length > 0) {
|
|
87
|
-
subschemaValue = JSON_STRING;
|
|
88
|
-
}
|
|
89
|
-
const [nr0, nr1] = subschemaNumrange;
|
|
90
|
-
if (nr0 !== null || nr1 !== null) {
|
|
91
|
-
if ((typeof nr0 === "number" && !Number.isInteger(nr0)) || (typeof nr1 === "number" && !Number.isInteger(nr1))) {
|
|
92
|
-
subschemaValue = JSON_NUMBER;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
subschemaValue = JSON_INTEGER;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const result = {};
|
|
100
|
-
if (isRecord(subschemaValue)) {
|
|
101
|
-
result.type = "object";
|
|
102
|
-
if (subschemaDescription) {
|
|
103
|
-
result.description = subschemaDescription;
|
|
104
|
-
}
|
|
105
|
-
result.additionalProperties = false;
|
|
106
|
-
const keys = Object.keys(subschemaValue);
|
|
107
|
-
result.required = keys;
|
|
108
|
-
const properties = {};
|
|
109
|
-
for (const [key, value] of Object.entries(subschemaValue)) {
|
|
110
|
-
if (typeof value === "string") {
|
|
111
|
-
properties[key] = { type: "string", description: value };
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
properties[key] = convertSchemaRecursive(value);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
result.properties = properties;
|
|
118
|
-
}
|
|
119
|
-
else if (Array.isArray(subschemaValue)) {
|
|
120
|
-
if (subschemaValue.length >= 2 && isStringArray(subschemaValue)) {
|
|
121
|
-
result.type = "string";
|
|
122
|
-
subschemaEnum = subschemaValue;
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
result.type = "array";
|
|
126
|
-
if (subschemaDescription) {
|
|
127
|
-
result.description = subschemaDescription;
|
|
128
|
-
}
|
|
129
|
-
if (subschemaNumrange[0] !== null) {
|
|
130
|
-
result.minItems = subschemaNumrange[0];
|
|
131
|
-
}
|
|
132
|
-
if (subschemaNumrange[1] !== null) {
|
|
133
|
-
result.maxItems = subschemaNumrange[1];
|
|
134
|
-
}
|
|
135
|
-
const arrayExemplar = subschemaValue[0];
|
|
136
|
-
if (typeof arrayExemplar === "string") {
|
|
137
|
-
result.items = { type: "string", description: arrayExemplar };
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
result.items = convertSchemaRecursive(arrayExemplar);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
const primitiveType = inferPrimitiveType(subschemaValue);
|
|
146
|
-
if (!primitiveType) {
|
|
147
|
-
throw new Error(`Unrecognized type for schema value: ${String(subschemaValue)}`);
|
|
148
|
-
}
|
|
149
|
-
result.type = primitiveType;
|
|
150
|
-
if (subschemaDescription) {
|
|
151
|
-
result.description = subschemaDescription;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (subschemaEnum.length) {
|
|
155
|
-
result.enum = subschemaEnum;
|
|
156
|
-
}
|
|
157
|
-
if (result.type === "integer" || result.type === "number") {
|
|
158
|
-
if (subschemaNumrange[0] !== null) {
|
|
159
|
-
result.minimum = subschemaNumrange[0];
|
|
160
|
-
}
|
|
161
|
-
if (subschemaNumrange[1] !== null) {
|
|
162
|
-
result.maximum = subschemaNumrange[1];
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return result;
|
|
166
|
-
}
|
|
167
|
-
export function JSONSchemaFormat(schema, options = {}) {
|
|
168
|
-
const result = {
|
|
169
|
-
format: {
|
|
170
|
-
type: "json_schema",
|
|
171
|
-
strict: true,
|
|
172
|
-
schema: { type: "object", properties: {}, required: [], additionalProperties: false },
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
if (options.name) {
|
|
176
|
-
result.format.name = options.name;
|
|
177
|
-
}
|
|
178
|
-
if (options.description) {
|
|
179
|
-
result.format.description = options.description;
|
|
180
|
-
}
|
|
181
|
-
let converted = convertSchemaRecursive(schema);
|
|
182
|
-
if (converted.type !== "object") {
|
|
183
|
-
const wrapperName = options.name || "schema";
|
|
184
|
-
converted = {
|
|
185
|
-
type: "object",
|
|
186
|
-
required: [wrapperName],
|
|
187
|
-
additionalProperties: false,
|
|
188
|
-
properties: {
|
|
189
|
-
[wrapperName]: converted,
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
result.format.schema = converted;
|
|
194
|
-
return result;
|
|
195
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED