typia 10.0.2 → 11.0.0
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 +14 -10
- package/lib/factories/internal/metadata/emplace_metadata_object.js +11 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.mjs +11 -0
- package/lib/index.mjs +2 -2
- package/lib/internal/_createStandardSchema.d.mts +1 -1
- package/lib/internal/_createStandardSchema.d.ts +1 -1
- package/lib/internal/_createStandardSchema.js.map +1 -1
- package/lib/internal/_llmApplicationFinalize.d.mts +2 -2
- package/lib/internal/_llmApplicationFinalize.d.ts +2 -2
- package/lib/internal/_llmApplicationFinalize.js +9 -10
- package/lib/internal/_llmApplicationFinalize.js.map +1 -1
- package/lib/internal/_llmApplicationFinalize.mjs +12 -13
- package/lib/llm.d.mts +20 -199
- package/lib/llm.d.ts +20 -199
- package/lib/llm.js.map +1 -1
- package/lib/misc.d.mts +3 -3
- package/lib/misc.d.ts +3 -3
- package/lib/misc.js.map +1 -1
- package/lib/module.d.mts +2 -2
- package/lib/module.d.ts +2 -2
- package/lib/programmers/internal/json_schema_object.js +1 -0
- package/lib/programmers/internal/json_schema_object.js.map +1 -1
- package/lib/programmers/internal/json_schema_object.mjs +1 -0
- package/lib/programmers/llm/LlmApplicationProgrammer.d.mts +8 -8
- package/lib/programmers/llm/LlmApplicationProgrammer.d.ts +8 -8
- package/lib/programmers/llm/LlmApplicationProgrammer.js +58 -64
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.mjs +63 -68
- package/lib/programmers/llm/{LlmModelPredicator.d.mts → LlmMetadataFactory.d.mts} +2 -8
- package/lib/programmers/llm/{LlmModelPredicator.d.ts → LlmMetadataFactory.d.ts} +2 -8
- package/lib/programmers/llm/{LlmModelPredicator.js → LlmMetadataFactory.js} +6 -37
- package/lib/programmers/llm/LlmMetadataFactory.js.map +1 -0
- package/lib/programmers/llm/{LlmModelPredicator.mjs → LlmMetadataFactory.mjs} +6 -34
- package/lib/programmers/llm/LlmMetadataFactory.mjs.map +1 -0
- package/lib/programmers/llm/LlmParametersProgrammer.d.mts +8 -8
- package/lib/programmers/llm/LlmParametersProgrammer.d.ts +8 -8
- package/lib/programmers/llm/LlmParametersProgrammer.js +10 -10
- package/lib/programmers/llm/LlmParametersProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmParametersProgrammer.mjs +10 -13
- package/lib/programmers/llm/LlmSchemaProgrammer.d.mts +10 -12
- package/lib/programmers/llm/LlmSchemaProgrammer.d.ts +10 -12
- package/lib/programmers/llm/LlmSchemaProgrammer.js +21 -33
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.mjs +21 -37
- package/lib/schemas/metadata/IMetadataProperty.d.mts +1 -0
- package/lib/schemas/metadata/IMetadataProperty.d.ts +1 -0
- package/lib/schemas/metadata/MetadataProperty.d.mts +1 -0
- package/lib/schemas/metadata/MetadataProperty.d.ts +1 -0
- package/lib/schemas/metadata/MetadataProperty.js +3 -0
- package/lib/schemas/metadata/MetadataProperty.js.map +1 -1
- package/lib/schemas/metadata/MetadataProperty.mjs +4 -0
- package/lib/transformers/features/llm/LlmApplicationTransformer.d.mts +0 -2
- package/lib/transformers/features/llm/LlmApplicationTransformer.d.ts +0 -2
- package/lib/transformers/features/llm/LlmApplicationTransformer.js +9 -20
- package/lib/transformers/features/llm/LlmApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/llm/LlmApplicationTransformer.mjs +9 -20
- package/lib/transformers/features/llm/LlmControllerTransformer.js +1 -8
- package/lib/transformers/features/llm/LlmControllerTransformer.js.map +1 -1
- package/lib/transformers/features/llm/LlmControllerTransformer.mjs +1 -8
- package/lib/transformers/features/llm/LlmParametersTransformer.js +6 -15
- package/lib/transformers/features/llm/LlmParametersTransformer.js.map +1 -1
- package/lib/transformers/features/llm/LlmParametersTransformer.mjs +6 -15
- package/lib/transformers/features/llm/LlmSchemaTransformer.js +11 -26
- package/lib/transformers/features/llm/LlmSchemaTransformer.js.map +1 -1
- package/lib/transformers/features/llm/LlmSchemaTransformer.mjs +11 -26
- package/package.json +4 -3
- package/src/factories/internal/metadata/emplace_metadata_object.ts +16 -0
- package/src/internal/_createStandardSchema.ts +2 -2
- package/src/internal/_llmApplicationFinalize.ts +18 -25
- package/src/llm.ts +28 -221
- package/src/misc.ts +9 -9
- package/src/module.ts +2 -2
- package/src/programmers/internal/json_schema_object.ts +1 -0
- package/src/programmers/llm/LlmApplicationProgrammer.ts +139 -151
- package/src/programmers/llm/{LlmModelPredicator.ts → LlmMetadataFactory.ts} +4 -42
- package/src/programmers/llm/LlmParametersProgrammer.ts +34 -41
- package/src/programmers/llm/LlmSchemaProgrammer.ts +59 -98
- package/src/schemas/metadata/IMetadataProperty.ts +1 -0
- package/src/schemas/metadata/MetadataProperty.ts +4 -0
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +14 -29
- package/src/transformers/features/llm/LlmControllerTransformer.ts +1 -12
- package/src/transformers/features/llm/LlmParametersTransformer.ts +10 -21
- package/src/transformers/features/llm/LlmSchemaTransformer.ts +29 -65
- package/lib/programmers/llm/LlmModelPredicator.js.map +0 -1
- package/lib/programmers/llm/LlmModelPredicator.mjs.map +0 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ChatGptTypeChecker,
|
|
3
|
-
IChatGptSchema,
|
|
4
2
|
ILlmApplication,
|
|
5
3
|
ILlmSchema,
|
|
6
4
|
IOpenApiSchemaError,
|
|
7
5
|
IResult,
|
|
6
|
+
LlmTypeChecker,
|
|
8
7
|
OpenApi,
|
|
9
8
|
} from "@samchon/openapi";
|
|
10
9
|
import { LlmSchemaComposer } from "@samchon/openapi/lib/composers/LlmSchemaComposer";
|
|
@@ -28,90 +27,89 @@ import { JsonApplicationProgrammer } from "../json/JsonApplicationProgrammer";
|
|
|
28
27
|
import { LlmSchemaProgrammer } from "./LlmSchemaProgrammer";
|
|
29
28
|
|
|
30
29
|
export namespace LlmApplicationProgrammer {
|
|
31
|
-
export const validate =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
metadata.functions
|
|
49
|
-
)
|
|
50
|
-
return validateFunction(explore.property, metadata.functions[0]!);
|
|
51
|
-
else return LlmSchemaProgrammer.validate(props)(metadata);
|
|
52
|
-
|
|
53
|
-
const output: string[] = [];
|
|
54
|
-
const validity: boolean =
|
|
55
|
-
metadata.size() === 1 &&
|
|
56
|
-
metadata.objects.length === 1 &&
|
|
57
|
-
metadata.isRequired() === true &&
|
|
58
|
-
metadata.nullable === false;
|
|
59
|
-
if (validity === false)
|
|
60
|
-
output.push(
|
|
61
|
-
"LLM application's generic argument must be a class/interface type.",
|
|
30
|
+
export const validate = (props: {
|
|
31
|
+
config?: Partial<ILlmSchema.IConfig>;
|
|
32
|
+
metadata: Metadata;
|
|
33
|
+
explore: MetadataFactory.IExplore;
|
|
34
|
+
}): string[] => {
|
|
35
|
+
const top: Metadata = props.metadata;
|
|
36
|
+
if (props.explore.top === false)
|
|
37
|
+
if (
|
|
38
|
+
props.explore.object === top?.objects[0]?.type &&
|
|
39
|
+
typeof props.explore.property === "string" &&
|
|
40
|
+
props.metadata.size() === 1 &&
|
|
41
|
+
props.metadata.nullable === false &&
|
|
42
|
+
props.metadata.isRequired() === true &&
|
|
43
|
+
props.metadata.functions.length === 1
|
|
44
|
+
)
|
|
45
|
+
return validateFunction(
|
|
46
|
+
props.explore.property,
|
|
47
|
+
props.metadata.functions[0]!,
|
|
62
48
|
);
|
|
49
|
+
else return LlmSchemaProgrammer.validate(props);
|
|
63
50
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (value.functions.length) {
|
|
75
|
-
least ||= true;
|
|
76
|
-
if (validity === false) {
|
|
77
|
-
if (value.functions.length !== 1 || value.size() !== 1)
|
|
78
|
-
output.push(
|
|
79
|
-
`LLM application's function (${name}) type does not allow union type.`,
|
|
80
|
-
);
|
|
81
|
-
if (value.isRequired() === false)
|
|
82
|
-
output.push(
|
|
83
|
-
`LLM application's function (${name}) type must be required.`,
|
|
84
|
-
);
|
|
85
|
-
if (value.nullable === true)
|
|
86
|
-
output.push(
|
|
87
|
-
`LLM application's function (${name}) type must not be nullable.`,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
51
|
+
const output: string[] = [];
|
|
52
|
+
const validity: boolean =
|
|
53
|
+
props.metadata.size() === 1 &&
|
|
54
|
+
props.metadata.objects.length === 1 &&
|
|
55
|
+
props.metadata.isRequired() === true &&
|
|
56
|
+
props.metadata.nullable === false;
|
|
57
|
+
if (validity === false)
|
|
58
|
+
output.push(
|
|
59
|
+
"LLM application's generic argument must be a class/interface type.",
|
|
60
|
+
);
|
|
90
61
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
62
|
+
const object: MetadataObjectType | undefined =
|
|
63
|
+
props.metadata.objects[0]?.type;
|
|
64
|
+
if (object !== undefined) {
|
|
65
|
+
if (object.properties.some((p) => p.key.isSoleLiteral() === false))
|
|
66
|
+
output.push(
|
|
67
|
+
"LLM application does not allow dynamic keys on class/interface type.",
|
|
68
|
+
);
|
|
69
|
+
let least: boolean = false;
|
|
70
|
+
for (const p of object.properties) {
|
|
71
|
+
const name: string = JSON.stringify(p.key.getSoleLiteral()!);
|
|
72
|
+
const value: Metadata = p.value;
|
|
73
|
+
if (value.functions.length) {
|
|
74
|
+
least ||= true;
|
|
75
|
+
if (validity === false) {
|
|
76
|
+
if (value.functions.length !== 1 || value.size() !== 1)
|
|
77
|
+
output.push(
|
|
78
|
+
`LLM application's function (${name}) type does not allow union type.`,
|
|
79
|
+
);
|
|
80
|
+
if (value.isRequired() === false)
|
|
81
|
+
output.push(
|
|
82
|
+
`LLM application's function (${name}) type must be required.`,
|
|
83
|
+
);
|
|
84
|
+
if (value.nullable === true)
|
|
103
85
|
output.push(
|
|
104
|
-
`LLM application's function (${name})
|
|
86
|
+
`LLM application's function (${name}) type must not be nullable.`,
|
|
105
87
|
);
|
|
106
88
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
89
|
+
|
|
90
|
+
const description: string | undefined = concatDescription(
|
|
91
|
+
JsonApplicationProgrammer.writeDescription({
|
|
92
|
+
description:
|
|
93
|
+
p.description ??
|
|
94
|
+
p.jsDocTags.find((tag) => tag.name === "description")?.text?.[0]
|
|
95
|
+
?.text ??
|
|
96
|
+
null,
|
|
97
|
+
jsDocTags: p.jsDocTags,
|
|
98
|
+
kind: "summary",
|
|
99
|
+
}),
|
|
111
100
|
);
|
|
101
|
+
if (description !== undefined && description.length > 1_024)
|
|
102
|
+
output.push(
|
|
103
|
+
`LLM application's function (${name}) description must not exceed 1,024 characters.`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
112
106
|
}
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
if (least === false)
|
|
108
|
+
output.push(
|
|
109
|
+
"LLM application's target type must have at least a function type.",
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return output;
|
|
115
113
|
};
|
|
116
114
|
|
|
117
115
|
const validateFunction = (name: string, func: MetadataFunction): string[] => {
|
|
@@ -155,18 +153,17 @@ export namespace LlmApplicationProgrammer {
|
|
|
155
153
|
return output;
|
|
156
154
|
};
|
|
157
155
|
|
|
158
|
-
export const write =
|
|
159
|
-
model: Model;
|
|
156
|
+
export const write = (props: {
|
|
160
157
|
context: ITypiaContext;
|
|
161
158
|
modulo: ts.LeftHandSideExpression;
|
|
162
159
|
metadata: Metadata;
|
|
163
160
|
config?: Partial<
|
|
164
|
-
ILlmSchema.
|
|
161
|
+
ILlmSchema.IConfig & {
|
|
165
162
|
equals: boolean;
|
|
166
163
|
}
|
|
167
164
|
>;
|
|
168
165
|
name?: string;
|
|
169
|
-
}): ILlmApplication
|
|
166
|
+
}): ILlmApplication => {
|
|
170
167
|
const metadata: Metadata = Metadata.unalias(props.metadata);
|
|
171
168
|
const functionParameters: Record<string, MetadataParameter> =
|
|
172
169
|
Object.fromEntries(
|
|
@@ -198,10 +195,9 @@ export namespace LlmApplicationProgrammer {
|
|
|
198
195
|
filter: (p) =>
|
|
199
196
|
p.jsDocTags.some((tag) => tag.name === "human") === false,
|
|
200
197
|
});
|
|
201
|
-
const functions: Array<ILlmFunction
|
|
202
|
-
|
|
198
|
+
const functions: Array<ILlmFunction | null> = application.functions.map(
|
|
199
|
+
(func) =>
|
|
203
200
|
writeFunction({
|
|
204
|
-
model: props.model,
|
|
205
201
|
context: props.context,
|
|
206
202
|
modulo: props.modulo,
|
|
207
203
|
className: props.name,
|
|
@@ -211,25 +207,23 @@ export namespace LlmApplicationProgrammer {
|
|
|
211
207
|
errors: errorMessages,
|
|
212
208
|
parameter: functionParameters[func.name] ?? null,
|
|
213
209
|
}),
|
|
214
|
-
|
|
210
|
+
);
|
|
215
211
|
if (functions.some((func) => func === null))
|
|
216
212
|
throw new Error(
|
|
217
213
|
"Failed to write LLM application:\n\n" +
|
|
218
214
|
errorMessages.map((str) => ` - ${str}`).join("\n"),
|
|
219
215
|
);
|
|
220
216
|
return {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
...LlmSchemaComposer.defaultConfig(props.model),
|
|
224
|
-
...props.config,
|
|
217
|
+
config: {
|
|
218
|
+
...LlmSchemaComposer.getConfig(props.config),
|
|
225
219
|
separate: null,
|
|
220
|
+
validate: null,
|
|
226
221
|
},
|
|
227
|
-
functions: functions
|
|
222
|
+
functions: functions.filter((f) => f !== null),
|
|
228
223
|
};
|
|
229
224
|
};
|
|
230
225
|
|
|
231
|
-
const writeFunction =
|
|
232
|
-
model: Model;
|
|
226
|
+
const writeFunction = (props: {
|
|
233
227
|
context: ITypiaContext;
|
|
234
228
|
modulo: ts.LeftHandSideExpression;
|
|
235
229
|
components: OpenApi.IComponents;
|
|
@@ -239,37 +233,34 @@ export namespace LlmApplicationProgrammer {
|
|
|
239
233
|
className?: string;
|
|
240
234
|
config:
|
|
241
235
|
| Partial<
|
|
242
|
-
ILlmSchema.
|
|
236
|
+
ILlmSchema.IConfig & {
|
|
243
237
|
equals: boolean;
|
|
244
238
|
}
|
|
245
239
|
>
|
|
246
240
|
| undefined;
|
|
247
|
-
}): ILlmFunction
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
241
|
+
}): ILlmFunction | null => {
|
|
242
|
+
const config: ILlmSchema.IConfig = LlmSchemaComposer.getConfig(
|
|
243
|
+
props.config,
|
|
244
|
+
);
|
|
245
|
+
const parameters: ILlmSchema.IParameters | null = writeParameters({
|
|
246
|
+
...props,
|
|
247
|
+
config,
|
|
248
|
+
accessor: `$input.${props.function.name}.parameters`,
|
|
249
|
+
});
|
|
253
250
|
if (parameters === null) return null;
|
|
254
|
-
const output: ILlmSchema
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
});
|
|
251
|
+
const output: ILlmSchema | null | undefined = writeOutput({
|
|
252
|
+
parameters,
|
|
253
|
+
config,
|
|
254
|
+
components: props.components,
|
|
255
|
+
schema: props.function.output?.schema ?? null,
|
|
256
|
+
errors: props.errors,
|
|
257
|
+
accessor: `$input.${props.function.name}.output`,
|
|
258
|
+
});
|
|
263
259
|
if (output === null) return null;
|
|
264
260
|
|
|
265
|
-
const isReference = (
|
|
266
|
-
schema: unknown,
|
|
267
|
-
): schema is IChatGptSchema.IReference =>
|
|
268
|
-
ChatGptTypeChecker.isReference(schema as any);
|
|
269
261
|
if (
|
|
270
262
|
output &&
|
|
271
|
-
|
|
272
|
-
isReference(output) === false &&
|
|
263
|
+
LlmTypeChecker.isReference(output) === false &&
|
|
273
264
|
output.description === undefined &&
|
|
274
265
|
!!props.function.output?.description?.length
|
|
275
266
|
)
|
|
@@ -277,9 +268,7 @@ export namespace LlmApplicationProgrammer {
|
|
|
277
268
|
return {
|
|
278
269
|
name: props.function.name,
|
|
279
270
|
parameters,
|
|
280
|
-
output:
|
|
281
|
-
| ILlmSchema.ModelSchema[Model]
|
|
282
|
-
| undefined,
|
|
271
|
+
output: output ?? undefined,
|
|
283
272
|
description: (() => {
|
|
284
273
|
if (
|
|
285
274
|
!props.function.summary?.length ||
|
|
@@ -306,35 +295,34 @@ export namespace LlmApplicationProgrammer {
|
|
|
306
295
|
};
|
|
307
296
|
};
|
|
308
297
|
|
|
309
|
-
const writeParameters =
|
|
310
|
-
model: Model;
|
|
298
|
+
const writeParameters = (props: {
|
|
311
299
|
components: OpenApi.IComponents;
|
|
312
300
|
function: IJsonSchemaApplication.IFunction<OpenApi.IJsonSchema>;
|
|
313
301
|
errors: string[];
|
|
314
302
|
accessor: string;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
303
|
+
config: ILlmSchema.IConfig;
|
|
304
|
+
}): ILlmSchema.IParameters | null => {
|
|
305
|
+
const schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference =
|
|
306
|
+
(props.function.parameters[0]?.schema as
|
|
307
|
+
| OpenApi.IJsonSchema.IObject
|
|
308
|
+
| OpenApi.IJsonSchema.IReference) ?? {
|
|
309
|
+
type: "object",
|
|
310
|
+
properties: {},
|
|
311
|
+
additionalProperties: false,
|
|
312
|
+
required: [],
|
|
313
|
+
};
|
|
314
|
+
const result: IResult<ILlmSchema.IParameters, IOpenApiSchemaError> =
|
|
315
|
+
LlmSchemaComposer.parameters({
|
|
316
|
+
config: props.config,
|
|
317
|
+
components: props.components,
|
|
318
|
+
schema: {
|
|
319
|
+
...schema,
|
|
320
|
+
title: schema.title ?? props.function.parameters[0]?.title,
|
|
321
|
+
description:
|
|
322
|
+
schema.description ?? props.function.parameters[0]?.description,
|
|
323
|
+
},
|
|
324
|
+
accessor: props.accessor,
|
|
325
|
+
});
|
|
338
326
|
if (result.success === false) {
|
|
339
327
|
props.errors.push(
|
|
340
328
|
...result.error.reasons.map((r) => ` - ${r.accessor}: ${r.message}`),
|
|
@@ -344,23 +332,23 @@ export namespace LlmApplicationProgrammer {
|
|
|
344
332
|
return result.value;
|
|
345
333
|
};
|
|
346
334
|
|
|
347
|
-
const writeOutput =
|
|
348
|
-
|
|
349
|
-
parameters: ILlmSchema.ModelParameters[Model];
|
|
335
|
+
const writeOutput = (props: {
|
|
336
|
+
parameters: ILlmSchema.IParameters;
|
|
350
337
|
components: OpenApi.IComponents;
|
|
338
|
+
config: ILlmSchema.IConfig;
|
|
351
339
|
schema: OpenApi.IJsonSchema | null;
|
|
352
340
|
errors: string[];
|
|
353
341
|
accessor: string;
|
|
354
|
-
}): ILlmSchema
|
|
342
|
+
}): ILlmSchema | null | undefined => {
|
|
355
343
|
if (props.schema === null) return undefined;
|
|
356
|
-
const result: IResult<ILlmSchema
|
|
357
|
-
LlmSchemaComposer.schema(
|
|
358
|
-
config:
|
|
344
|
+
const result: IResult<ILlmSchema, IOpenApiSchemaError> =
|
|
345
|
+
LlmSchemaComposer.schema({
|
|
346
|
+
config: props.config,
|
|
359
347
|
components: props.components,
|
|
360
348
|
schema: props.schema,
|
|
361
349
|
$defs: (props.parameters as any).$defs,
|
|
362
350
|
accessor: props.accessor,
|
|
363
|
-
})
|
|
351
|
+
});
|
|
364
352
|
if (result.success === false) {
|
|
365
353
|
props.errors.push(
|
|
366
354
|
...result.error.reasons.map((r) => ` - ${r.accessor}: ${r.message}`),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { LlmSchemaComposer } from "@samchon/openapi/lib/composers/LlmSchemaComposer";
|
|
3
2
|
import ts from "typescript";
|
|
4
3
|
|
|
5
4
|
import { MetadataCollection } from "../../factories/MetadataCollection";
|
|
@@ -13,20 +12,20 @@ import { TransformerError } from "../../transformers/TransformerError";
|
|
|
13
12
|
|
|
14
13
|
import { ValidationPipe } from "../../typings/ValidationPipe";
|
|
15
14
|
|
|
16
|
-
export namespace
|
|
15
|
+
export namespace LlmMetadataFactory {
|
|
17
16
|
export const getConfig = (props: {
|
|
18
17
|
context: ITypiaContext;
|
|
19
18
|
method: string;
|
|
20
|
-
model: ILlmSchema.Model;
|
|
21
19
|
node: ts.TypeNode | undefined;
|
|
22
20
|
}):
|
|
23
21
|
| Partial<
|
|
24
|
-
ILlmSchema.
|
|
22
|
+
ILlmSchema.IConfig & {
|
|
25
23
|
equals: boolean;
|
|
26
24
|
}
|
|
27
25
|
>
|
|
28
26
|
| undefined => {
|
|
29
27
|
if (props.node === undefined) return undefined;
|
|
28
|
+
|
|
30
29
|
const type: ts.Type = props.context.checker.getTypeFromTypeNode(props.node);
|
|
31
30
|
const collection: MetadataCollection = new MetadataCollection();
|
|
32
31
|
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
|
|
@@ -79,7 +78,7 @@ export namespace LlmModelPredicator {
|
|
|
79
78
|
code: `typia.llm.${props.method}`,
|
|
80
79
|
message: `Invalid generic argument "Config". It must be a literal object type. Do not allow variable type.`,
|
|
81
80
|
});
|
|
82
|
-
const config: Partial<ILlmSchema.
|
|
81
|
+
const config: Partial<ILlmSchema.IConfig> = {};
|
|
83
82
|
for (const prop of obj.type.properties) {
|
|
84
83
|
const key: string = prop.key.getSoleLiteral()!;
|
|
85
84
|
const value: boolean | bigint | number | string =
|
|
@@ -93,41 +92,4 @@ export namespace LlmModelPredicator {
|
|
|
93
92
|
}
|
|
94
93
|
return config;
|
|
95
94
|
};
|
|
96
|
-
|
|
97
|
-
export const getModel = (props: {
|
|
98
|
-
checker: ts.TypeChecker;
|
|
99
|
-
method: string;
|
|
100
|
-
node: ts.TypeNode | undefined;
|
|
101
|
-
}): ILlmSchema.Model => {
|
|
102
|
-
if (props.node === undefined)
|
|
103
|
-
throw new TransformerError({
|
|
104
|
-
code: `typia.llm.${props.method}`,
|
|
105
|
-
message: `generic argument "Model" must be specified.`,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// CHECK LITERAL TYPE
|
|
109
|
-
const type: ts.Type = props.checker.getTypeFromTypeNode(props.node);
|
|
110
|
-
if (
|
|
111
|
-
!type.isLiteral() &&
|
|
112
|
-
(type.getFlags() & ts.TypeFlags.BooleanLiteral) === 0
|
|
113
|
-
)
|
|
114
|
-
throw new TransformerError({
|
|
115
|
-
code: `typia.llm.${props.method}`,
|
|
116
|
-
message: `generic argument "Model" must be constant.`,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// GET VALUE AND VALIDATE IT
|
|
120
|
-
const value = type.isLiteral()
|
|
121
|
-
? type.value
|
|
122
|
-
: props.checker.typeToString(type);
|
|
123
|
-
if (
|
|
124
|
-
typeof value !== "string" ||
|
|
125
|
-
LlmSchemaComposer.defaultConfig(value as "3.0") === undefined
|
|
126
|
-
)
|
|
127
|
-
throw new TransformerError({
|
|
128
|
-
code: "typia.llm.schema",
|
|
129
|
-
message: `invalid value on generic argument "Model".`,
|
|
130
|
-
});
|
|
131
|
-
return value as ILlmSchema.Model;
|
|
132
|
-
};
|
|
133
95
|
}
|
|
@@ -18,11 +18,10 @@ import { JsonSchemasProgrammer } from "../json/JsonSchemasProgrammer";
|
|
|
18
18
|
import { LlmSchemaProgrammer } from "./LlmSchemaProgrammer";
|
|
19
19
|
|
|
20
20
|
export namespace LlmParametersProgrammer {
|
|
21
|
-
export const write =
|
|
22
|
-
model: Model;
|
|
21
|
+
export const write = (props: {
|
|
23
22
|
metadata: Metadata;
|
|
24
|
-
config?: Partial<ILlmSchema.
|
|
25
|
-
}): ILlmSchema.
|
|
23
|
+
config?: Partial<ILlmSchema.IConfig>;
|
|
24
|
+
}): ILlmSchema.IParameters => {
|
|
26
25
|
const collection: IJsonSchemaCollection<"3.1"> =
|
|
27
26
|
JsonSchemasProgrammer.write({
|
|
28
27
|
version: "3.1",
|
|
@@ -39,17 +38,12 @@ export namespace LlmParametersProgrammer {
|
|
|
39
38
|
throw new Error("Unreachable code. Failed to find the object schema.");
|
|
40
39
|
})();
|
|
41
40
|
|
|
42
|
-
const result: IResult<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
...props.config,
|
|
49
|
-
} as any,
|
|
50
|
-
components: collection.components,
|
|
51
|
-
schema,
|
|
52
|
-
}) as IResult<ILlmSchema.ModelParameters[Model], IOpenApiSchemaError>;
|
|
41
|
+
const result: IResult<ILlmSchema.IParameters, IOpenApiSchemaError> =
|
|
42
|
+
LlmSchemaComposer.parameters({
|
|
43
|
+
config: LlmSchemaComposer.getConfig(props.config),
|
|
44
|
+
components: collection.components,
|
|
45
|
+
schema,
|
|
46
|
+
});
|
|
53
47
|
if (result.success === false)
|
|
54
48
|
throw new TransformerError({
|
|
55
49
|
code: "typia.llm.parameters",
|
|
@@ -62,32 +56,31 @@ export namespace LlmParametersProgrammer {
|
|
|
62
56
|
return result.value;
|
|
63
57
|
};
|
|
64
58
|
|
|
65
|
-
export const validate =
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
(p) => p.key.isSoleLiteral() === false,
|
|
81
|
-
)
|
|
59
|
+
export const validate = (props: {
|
|
60
|
+
config?: Partial<ILlmSchema.IConfig>;
|
|
61
|
+
metadata: Metadata;
|
|
62
|
+
explore: MetadataFactory.IExplore;
|
|
63
|
+
}): string[] => {
|
|
64
|
+
const output: string[] = [];
|
|
65
|
+
if (props.explore.top === true) {
|
|
66
|
+
if (props.metadata.objects.length === 0)
|
|
67
|
+
output.push("LLM parameters must be an object type.");
|
|
68
|
+
else if (props.metadata.objects.length !== 1 || props.metadata.size() > 1)
|
|
69
|
+
output.push("LLM parameters must be a single object type.");
|
|
70
|
+
else {
|
|
71
|
+
if (
|
|
72
|
+
props.metadata.objects[0]!.type.properties.some(
|
|
73
|
+
(p) => p.key.isSoleLiteral() === false,
|
|
82
74
|
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
75
|
+
)
|
|
76
|
+
output.push("LLM parameters must not have dynamic keys.");
|
|
77
|
+
if (props.metadata.nullable)
|
|
78
|
+
output.push("LLM parameters must be a non-nullable object type.");
|
|
79
|
+
if (props.metadata.isRequired() === false)
|
|
80
|
+
output.push("LLM parameters must be a non-undefined object type.");
|
|
89
81
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
}
|
|
83
|
+
output.push(...LlmSchemaProgrammer.validate(props));
|
|
84
|
+
return output;
|
|
85
|
+
};
|
|
93
86
|
}
|