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,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IChatGptSchema,
|
|
3
|
-
ILlmSchema,
|
|
4
|
-
ILlmSchemaV3,
|
|
5
|
-
IOpenApiSchemaError,
|
|
6
|
-
IResult,
|
|
7
|
-
} from "@samchon/openapi";
|
|
1
|
+
import { ILlmSchema, IOpenApiSchemaError, IResult } from "@samchon/openapi";
|
|
8
2
|
import { LlmSchemaComposer } from "@samchon/openapi/lib/composers/LlmSchemaComposer";
|
|
9
3
|
|
|
10
4
|
import { IJsonSchemaCollection } from "../../schemas/json/IJsonSchemaCollection";
|
|
@@ -21,34 +15,29 @@ import { json_schema_string } from "../internal/json_schema_string";
|
|
|
21
15
|
import { JsonSchemasProgrammer } from "../json/JsonSchemasProgrammer";
|
|
22
16
|
|
|
23
17
|
export namespace LlmSchemaProgrammer {
|
|
24
|
-
export interface IOutput
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
$defs: Record<string, ILlmSchema.ModelSchema[Model]>;
|
|
18
|
+
export interface IOutput {
|
|
19
|
+
schema: ILlmSchema;
|
|
20
|
+
$defs: Record<string, ILlmSchema>;
|
|
28
21
|
}
|
|
29
22
|
|
|
30
|
-
export const write =
|
|
31
|
-
model: Model;
|
|
23
|
+
export const write = (props: {
|
|
32
24
|
metadata: Metadata;
|
|
33
|
-
config?: Partial<ILlmSchema.
|
|
34
|
-
}): IOutput
|
|
25
|
+
config?: Partial<ILlmSchema.IConfig>;
|
|
26
|
+
}): IOutput => {
|
|
35
27
|
const collection: IJsonSchemaCollection<"3.1"> =
|
|
36
28
|
JsonSchemasProgrammer.write({
|
|
37
29
|
version: "3.1",
|
|
38
30
|
metadatas: [props.metadata],
|
|
39
31
|
});
|
|
40
32
|
|
|
41
|
-
const $defs: Record<string, ILlmSchema
|
|
42
|
-
const result: IResult<ILlmSchema
|
|
43
|
-
LlmSchemaComposer.schema(
|
|
44
|
-
config:
|
|
45
|
-
...LlmSchemaComposer.defaultConfig(props.model),
|
|
46
|
-
...props.config,
|
|
47
|
-
} as any,
|
|
33
|
+
const $defs: Record<string, ILlmSchema> = {};
|
|
34
|
+
const result: IResult<ILlmSchema, IOpenApiSchemaError> =
|
|
35
|
+
LlmSchemaComposer.schema({
|
|
36
|
+
config: LlmSchemaComposer.getConfig(props.config),
|
|
48
37
|
components: collection.components,
|
|
49
38
|
schema: collection.schemas[0]!,
|
|
50
|
-
$defs
|
|
51
|
-
})
|
|
39
|
+
$defs,
|
|
40
|
+
});
|
|
52
41
|
if (result.success === false)
|
|
53
42
|
throw new TransformerError({
|
|
54
43
|
code: "typia.llm.schema",
|
|
@@ -59,92 +48,64 @@ export namespace LlmSchemaProgrammer {
|
|
|
59
48
|
.join("\n"),
|
|
60
49
|
});
|
|
61
50
|
return {
|
|
62
|
-
model: props.model,
|
|
63
51
|
$defs,
|
|
64
52
|
schema: result.value,
|
|
65
53
|
};
|
|
66
54
|
};
|
|
67
55
|
|
|
68
|
-
export const validate =
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
(metadata: Metadata): string[] => {
|
|
74
|
-
const output: string[] = [];
|
|
56
|
+
export const validate = (props: {
|
|
57
|
+
config?: Partial<ILlmSchema.IConfig>;
|
|
58
|
+
metadata: Metadata;
|
|
59
|
+
}): string[] => {
|
|
60
|
+
const output: string[] = [];
|
|
75
61
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
),
|
|
85
|
-
)
|
|
62
|
+
// no additionalProperties in OpenAI strict mode
|
|
63
|
+
const config: ILlmSchema.IConfig = LlmSchemaComposer.getConfig(
|
|
64
|
+
props.config,
|
|
65
|
+
);
|
|
66
|
+
if (
|
|
67
|
+
config.strict === true &&
|
|
68
|
+
props.metadata.objects.some((o) =>
|
|
69
|
+
o.type.properties.some(
|
|
70
|
+
(p) => p.key.isSoleLiteral() === false && p.value.size() !== 0,
|
|
71
|
+
),
|
|
86
72
|
)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
);
|
|
73
|
+
)
|
|
74
|
+
output.push(`Strict mode does not allow dynamic property in object.`);
|
|
90
75
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
metadata.objects.some((o) =>
|
|
97
|
-
o.type.properties.some((p) => p.value.isRequired() === false),
|
|
98
|
-
)
|
|
76
|
+
// OpenAI strict mode even does not support the optional property
|
|
77
|
+
if (
|
|
78
|
+
config.strict === true &&
|
|
79
|
+
props.metadata.objects.some((o) =>
|
|
80
|
+
o.type.properties.some((p) => p.value.isRequired() === false),
|
|
99
81
|
)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
// no recursive rule of Gemini and V3
|
|
105
|
-
if (
|
|
106
|
-
props.model === "3.0" &&
|
|
107
|
-
((props.config as ILlmSchemaV3.IConfig | undefined)?.recursive ===
|
|
108
|
-
false ||
|
|
109
|
-
(props.config as ILlmSchemaV3.IConfig | undefined)?.recursive === 0)
|
|
110
|
-
) {
|
|
111
|
-
if (metadata.objects.some((o) => o.type.recursive))
|
|
112
|
-
output.push(
|
|
113
|
-
`LLM schema of "${props.model}" does not support recursive object.`,
|
|
114
|
-
);
|
|
115
|
-
if (metadata.arrays.some((a) => a.type.recursive))
|
|
116
|
-
output.push(
|
|
117
|
-
`LLM schema of "${props.model}" does not support recursive array.`,
|
|
118
|
-
);
|
|
119
|
-
}
|
|
82
|
+
)
|
|
83
|
+
output.push(`Strict mode does not support optional property in object.`);
|
|
120
84
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
85
|
+
// just JSON rule
|
|
86
|
+
if (
|
|
87
|
+
props.metadata.atomics.some((a) => a.type === "bigint") ||
|
|
88
|
+
props.metadata.constants.some((c) => c.type === "bigint")
|
|
89
|
+
)
|
|
90
|
+
output.push("LLM schema does not support bigint type.");
|
|
91
|
+
if (props.metadata.tuples.length !== 0)
|
|
92
|
+
output.push("LLM schema does not support tuple type.");
|
|
93
|
+
if (props.metadata.arrays.some((a) => a.type.value.isRequired() === false))
|
|
94
|
+
output.push("LLM schema does not support undefined type in array.");
|
|
95
|
+
if (props.metadata.maps.length)
|
|
96
|
+
output.push("LLM schema does not support Map type.");
|
|
97
|
+
if (props.metadata.sets.length)
|
|
98
|
+
output.push("LLM schema does not support Set type.");
|
|
99
|
+
for (const native of props.metadata.natives)
|
|
127
100
|
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
101
|
+
AtomicPredicator.native(native.name) === false &&
|
|
102
|
+
native.name !== "Date" &&
|
|
103
|
+
native.name !== "Blob" &&
|
|
104
|
+
native.name !== "File"
|
|
132
105
|
)
|
|
133
|
-
output.push(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (metadata.sets.length)
|
|
137
|
-
output.push("LLM schema does not support Set type.");
|
|
138
|
-
for (const native of metadata.natives)
|
|
139
|
-
if (
|
|
140
|
-
AtomicPredicator.native(native.name) === false &&
|
|
141
|
-
native.name !== "Date" &&
|
|
142
|
-
native.name !== "Blob" &&
|
|
143
|
-
native.name !== "File"
|
|
144
|
-
)
|
|
145
|
-
output.push(`LLM schema does not support ${native.name} type.`);
|
|
146
|
-
return output;
|
|
147
|
-
};
|
|
106
|
+
output.push(`LLM schema does not support ${native.name} type.`);
|
|
107
|
+
return output;
|
|
108
|
+
};
|
|
148
109
|
}
|
|
149
110
|
|
|
150
111
|
const size = (metadata: Metadata): number =>
|
|
@@ -11,6 +11,7 @@ export class MetadataProperty {
|
|
|
11
11
|
public readonly value: Metadata;
|
|
12
12
|
public readonly description: string | null;
|
|
13
13
|
public readonly jsDocTags: IJsDocTagInfo[];
|
|
14
|
+
public readonly mutability?: "readonly" | null | undefined;
|
|
14
15
|
|
|
15
16
|
public of_protobuf_?: IProtobufProperty;
|
|
16
17
|
|
|
@@ -23,6 +24,7 @@ export class MetadataProperty {
|
|
|
23
24
|
this.value = props.value;
|
|
24
25
|
this.description = props.description;
|
|
25
26
|
this.jsDocTags = props.jsDocTags;
|
|
27
|
+
this.mutability = props.mutability;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
/** @internal */
|
|
@@ -39,6 +41,7 @@ export class MetadataProperty {
|
|
|
39
41
|
value: Metadata.from(property.value, dict),
|
|
40
42
|
description: property.description,
|
|
41
43
|
jsDocTags: property.jsDocTags.slice(),
|
|
44
|
+
mutability: property.mutability,
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -48,6 +51,7 @@ export class MetadataProperty {
|
|
|
48
51
|
value: this.value.toJSON(),
|
|
49
52
|
description: this.description,
|
|
50
53
|
jsDocTags: this.jsDocTags,
|
|
54
|
+
mutability: this.mutability,
|
|
51
55
|
};
|
|
52
56
|
}
|
|
53
57
|
}
|
|
@@ -10,7 +10,7 @@ import { StatementFactory } from "../../../factories/StatementFactory";
|
|
|
10
10
|
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
11
11
|
|
|
12
12
|
import { LlmApplicationProgrammer } from "../../../programmers/llm/LlmApplicationProgrammer";
|
|
13
|
-
import {
|
|
13
|
+
import { LlmMetadataFactory } from "../../../programmers/llm/LlmMetadataFactory";
|
|
14
14
|
|
|
15
15
|
import { ValidationPipe } from "../../../typings/ValidationPipe";
|
|
16
16
|
|
|
@@ -28,14 +28,10 @@ export namespace LlmApplicationTransformer {
|
|
|
28
28
|
props.context.importer.type({
|
|
29
29
|
file: "@samchon/openapi",
|
|
30
30
|
name: "ILlmApplication",
|
|
31
|
-
arguments: [
|
|
32
|
-
ts.factory.createLiteralTypeNode(
|
|
33
|
-
ts.factory.createStringLiteral(dec.application.model),
|
|
34
|
-
),
|
|
35
|
-
],
|
|
31
|
+
arguments: [dec.node],
|
|
36
32
|
}),
|
|
37
33
|
);
|
|
38
|
-
if (
|
|
34
|
+
if (props.expression.arguments?.[0] === undefined) return literal;
|
|
39
35
|
return ExpressionFactory.selfCall(
|
|
40
36
|
ts.factory.createBlock(
|
|
41
37
|
[
|
|
@@ -49,7 +45,6 @@ export namespace LlmApplicationTransformer {
|
|
|
49
45
|
value: ts.factory.createIdentifier("application"),
|
|
50
46
|
argument: props.expression.arguments[0]!,
|
|
51
47
|
equals: dec.config?.equals,
|
|
52
|
-
model: dec.application.model,
|
|
53
48
|
}),
|
|
54
49
|
),
|
|
55
50
|
ts.factory.createReturnStatement(
|
|
@@ -66,7 +61,7 @@ export namespace LlmApplicationTransformer {
|
|
|
66
61
|
method: string,
|
|
67
62
|
props: ITransformProps,
|
|
68
63
|
): {
|
|
69
|
-
application: ILlmApplication
|
|
64
|
+
application: ILlmApplication;
|
|
70
65
|
type: ts.Type;
|
|
71
66
|
node: ts.TypeNode;
|
|
72
67
|
config:
|
|
@@ -87,22 +82,16 @@ export namespace LlmApplicationTransformer {
|
|
|
87
82
|
if (ts.isTypeNode(top) === false) return null;
|
|
88
83
|
|
|
89
84
|
// GET TYPE
|
|
90
|
-
const model: ILlmSchema.Model = LlmModelPredicator.getModel({
|
|
91
|
-
checker: props.context.checker,
|
|
92
|
-
method,
|
|
93
|
-
node: props.expression.typeArguments[1],
|
|
94
|
-
});
|
|
95
85
|
const config:
|
|
96
86
|
| Partial<
|
|
97
87
|
ILlmSchema.IConfig & {
|
|
98
88
|
equals: boolean;
|
|
99
89
|
}
|
|
100
90
|
>
|
|
101
|
-
| undefined =
|
|
91
|
+
| undefined = LlmMetadataFactory.getConfig({
|
|
102
92
|
context: props.context,
|
|
103
93
|
method,
|
|
104
|
-
|
|
105
|
-
node: props.expression.typeArguments[2],
|
|
94
|
+
node: props.expression.typeArguments[1],
|
|
106
95
|
});
|
|
107
96
|
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
108
97
|
|
|
@@ -119,10 +108,12 @@ export namespace LlmApplicationTransformer {
|
|
|
119
108
|
functional: true,
|
|
120
109
|
validate:
|
|
121
110
|
validate === true
|
|
122
|
-
?
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
111
|
+
? (metadata, explore) =>
|
|
112
|
+
LlmApplicationProgrammer.validate({
|
|
113
|
+
config,
|
|
114
|
+
metadata,
|
|
115
|
+
explore,
|
|
116
|
+
})
|
|
126
117
|
: undefined,
|
|
127
118
|
},
|
|
128
119
|
collection: new MetadataCollection({
|
|
@@ -142,7 +133,6 @@ export namespace LlmApplicationTransformer {
|
|
|
142
133
|
// GENERATE LLM APPLICATION
|
|
143
134
|
return {
|
|
144
135
|
application: LlmApplicationProgrammer.write({
|
|
145
|
-
model,
|
|
146
136
|
context: props.context,
|
|
147
137
|
modulo: props.modulo,
|
|
148
138
|
metadata: analyze(false),
|
|
@@ -160,7 +150,6 @@ export namespace LlmApplicationTransformer {
|
|
|
160
150
|
value: ts.Expression;
|
|
161
151
|
argument: ts.Expression;
|
|
162
152
|
equals?: boolean;
|
|
163
|
-
model: ILlmSchema.Model;
|
|
164
153
|
}) => {
|
|
165
154
|
const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
|
|
166
155
|
ts.factory.createIdentifier("Partial"),
|
|
@@ -175,13 +164,9 @@ export namespace LlmApplicationTransformer {
|
|
|
175
164
|
undefined,
|
|
176
165
|
ts.factory.createQualifiedName(
|
|
177
166
|
ts.factory.createIdentifier("ILlmApplication"),
|
|
178
|
-
ts.factory.createIdentifier("
|
|
167
|
+
ts.factory.createIdentifier("IConfig"),
|
|
179
168
|
),
|
|
180
|
-
|
|
181
|
-
ts.factory.createLiteralTypeNode(
|
|
182
|
-
ts.factory.createStringLiteral(props.model),
|
|
183
|
-
),
|
|
184
|
-
],
|
|
169
|
+
undefined,
|
|
185
170
|
false,
|
|
186
171
|
),
|
|
187
172
|
ts.factory.createUnionTypeNode([
|
|
@@ -28,11 +28,6 @@ export namespace LlmControllerTransformer {
|
|
|
28
28
|
props.context.importer.type({
|
|
29
29
|
file: "@samchon/openapi",
|
|
30
30
|
name: "ILlmApplication",
|
|
31
|
-
arguments: [
|
|
32
|
-
ts.factory.createLiteralTypeNode(
|
|
33
|
-
ts.factory.createStringLiteral(dec.application.model),
|
|
34
|
-
),
|
|
35
|
-
],
|
|
36
31
|
}),
|
|
37
32
|
);
|
|
38
33
|
const value: ts.Expression = ts.factory.createObjectLiteralExpression(
|
|
@@ -68,7 +63,6 @@ export namespace LlmControllerTransformer {
|
|
|
68
63
|
value: ts.factory.createIdentifier("application"),
|
|
69
64
|
argument: props.expression.arguments[2]!,
|
|
70
65
|
equals: dec.config?.equals,
|
|
71
|
-
model: dec.application.model,
|
|
72
66
|
}),
|
|
73
67
|
),
|
|
74
68
|
]
|
|
@@ -80,12 +74,7 @@ export namespace LlmControllerTransformer {
|
|
|
80
74
|
props.context.importer.type({
|
|
81
75
|
file: "@samchon/openapi",
|
|
82
76
|
name: "ILlmController",
|
|
83
|
-
arguments: [
|
|
84
|
-
ts.factory.createLiteralTypeNode(
|
|
85
|
-
ts.factory.createStringLiteral(dec.application.model),
|
|
86
|
-
),
|
|
87
|
-
dec.node,
|
|
88
|
-
],
|
|
77
|
+
arguments: [dec.node],
|
|
89
78
|
}),
|
|
90
79
|
);
|
|
91
80
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { ILlmFunction } from "@samchon/openapi/lib/structures/ILlmFunction";
|
|
3
2
|
import ts from "typescript";
|
|
4
3
|
|
|
5
4
|
import { LiteralFactory } from "../../../factories/LiteralFactory";
|
|
@@ -8,7 +7,7 @@ import { MetadataFactory } from "../../../factories/MetadataFactory";
|
|
|
8
7
|
|
|
9
8
|
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
10
9
|
|
|
11
|
-
import {
|
|
10
|
+
import { LlmMetadataFactory } from "../../../programmers/llm/LlmMetadataFactory";
|
|
12
11
|
import { LlmParametersProgrammer } from "../../../programmers/llm/LlmParametersProgrammer";
|
|
13
12
|
|
|
14
13
|
import { ValidationPipe } from "../../../typings/ValidationPipe";
|
|
@@ -31,16 +30,10 @@ export namespace LlmParametersTransformer {
|
|
|
31
30
|
if (ts.isTypeNode(top) === false) return props.expression;
|
|
32
31
|
|
|
33
32
|
// GET TYPE
|
|
34
|
-
const
|
|
35
|
-
checker: props.context.checker,
|
|
36
|
-
method: "parameters",
|
|
37
|
-
node: props.expression.typeArguments[1],
|
|
38
|
-
});
|
|
39
|
-
const config: Partial<ILlmSchema.IConfig> = LlmModelPredicator.getConfig({
|
|
33
|
+
const config: Partial<ILlmSchema.IConfig> = LlmMetadataFactory.getConfig({
|
|
40
34
|
context: props.context,
|
|
41
35
|
method: "parameters",
|
|
42
|
-
|
|
43
|
-
node: props.expression.typeArguments[2],
|
|
36
|
+
node: props.expression.typeArguments[1],
|
|
44
37
|
}) as Partial<ILlmSchema.IConfig>;
|
|
45
38
|
|
|
46
39
|
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
@@ -57,10 +50,12 @@ export namespace LlmParametersTransformer {
|
|
|
57
50
|
constant: true,
|
|
58
51
|
validate:
|
|
59
52
|
validate === true
|
|
60
|
-
?
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
? (metadata, explore) =>
|
|
54
|
+
LlmParametersProgrammer.validate({
|
|
55
|
+
config,
|
|
56
|
+
metadata,
|
|
57
|
+
explore,
|
|
58
|
+
})
|
|
64
59
|
: undefined,
|
|
65
60
|
},
|
|
66
61
|
collection: new MetadataCollection({
|
|
@@ -78,8 +73,7 @@ export namespace LlmParametersTransformer {
|
|
|
78
73
|
analyze(true);
|
|
79
74
|
|
|
80
75
|
// GENERATE LLM SCHEMA
|
|
81
|
-
const out:
|
|
82
|
-
model,
|
|
76
|
+
const out: ILlmSchema.IParameters = LlmParametersProgrammer.write({
|
|
83
77
|
metadata: analyze(false),
|
|
84
78
|
config,
|
|
85
79
|
});
|
|
@@ -91,11 +85,6 @@ export namespace LlmParametersTransformer {
|
|
|
91
85
|
ts.factory.createIdentifier("ILlmSchema"),
|
|
92
86
|
ts.factory.createIdentifier("IParameters"),
|
|
93
87
|
),
|
|
94
|
-
arguments: [
|
|
95
|
-
ts.factory.createLiteralTypeNode(
|
|
96
|
-
ts.factory.createStringLiteral(model),
|
|
97
|
-
),
|
|
98
|
-
],
|
|
99
88
|
}),
|
|
100
89
|
);
|
|
101
90
|
};
|
|
@@ -8,7 +8,7 @@ import { MetadataFactory } from "../../../factories/MetadataFactory";
|
|
|
8
8
|
|
|
9
9
|
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { LlmMetadataFactory } from "../../../programmers/llm/LlmMetadataFactory";
|
|
12
12
|
import { LlmSchemaProgrammer } from "../../../programmers/llm/LlmSchemaProgrammer";
|
|
13
13
|
|
|
14
14
|
import { ValidationPipe } from "../../../typings/ValidationPipe";
|
|
@@ -31,16 +31,10 @@ export namespace LlmSchemaTransformer {
|
|
|
31
31
|
if (ts.isTypeNode(top) === false) return props.expression;
|
|
32
32
|
|
|
33
33
|
// GET TYPE
|
|
34
|
-
const
|
|
35
|
-
checker: props.context.checker,
|
|
36
|
-
method: "schema",
|
|
37
|
-
node: props.expression.typeArguments[1],
|
|
38
|
-
});
|
|
39
|
-
const config: Partial<ILlmSchema.IConfig> = LlmModelPredicator.getConfig({
|
|
34
|
+
const config: Partial<ILlmSchema.IConfig> = LlmMetadataFactory.getConfig({
|
|
40
35
|
context: props.context,
|
|
41
36
|
method: "schema",
|
|
42
|
-
|
|
43
|
-
node: props.expression.typeArguments[2],
|
|
37
|
+
node: props.expression.typeArguments[1],
|
|
44
38
|
}) as Partial<ILlmSchema.IConfig>;
|
|
45
39
|
|
|
46
40
|
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
@@ -57,10 +51,11 @@ export namespace LlmSchemaTransformer {
|
|
|
57
51
|
escape: true,
|
|
58
52
|
validate:
|
|
59
53
|
validate === true
|
|
60
|
-
?
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
? (metadata: Metadata) =>
|
|
55
|
+
LlmSchemaProgrammer.validate({
|
|
56
|
+
config,
|
|
57
|
+
metadata,
|
|
58
|
+
})
|
|
64
59
|
: undefined,
|
|
65
60
|
},
|
|
66
61
|
collection: new MetadataCollection({
|
|
@@ -78,17 +73,13 @@ export namespace LlmSchemaTransformer {
|
|
|
78
73
|
analyze(true);
|
|
79
74
|
|
|
80
75
|
// GENERATE LLM SCHEMA
|
|
81
|
-
const out: LlmSchemaProgrammer.IOutput
|
|
82
|
-
model,
|
|
76
|
+
const out: LlmSchemaProgrammer.IOutput = LlmSchemaProgrammer.write({
|
|
83
77
|
metadata: analyze(false),
|
|
84
78
|
config,
|
|
85
79
|
});
|
|
86
80
|
const schemaTypeNode = props.context.importer.type({
|
|
87
81
|
file: "@samchon/openapi",
|
|
88
82
|
name: "ILlmSchema",
|
|
89
|
-
arguments: [
|
|
90
|
-
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(model)),
|
|
91
|
-
],
|
|
92
83
|
});
|
|
93
84
|
const literal = ts.factory.createAsExpression(
|
|
94
85
|
LiteralFactory.write(out.schema),
|
|
@@ -101,24 +92,10 @@ export namespace LlmSchemaTransformer {
|
|
|
101
92
|
undefined,
|
|
102
93
|
[
|
|
103
94
|
IdentifierFactory.parameter(
|
|
104
|
-
"
|
|
105
|
-
ts.factory.
|
|
106
|
-
ts.factory.
|
|
107
|
-
|
|
108
|
-
ts.factory.createIdentifier("$defs"),
|
|
109
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
110
|
-
ts.factory.createUnionTypeNode([
|
|
111
|
-
ts.factory.createTypeReferenceNode("Record", [
|
|
112
|
-
ts.factory.createKeywordTypeNode(
|
|
113
|
-
ts.SyntaxKind.StringKeyword,
|
|
114
|
-
),
|
|
115
|
-
schemaTypeNode,
|
|
116
|
-
]),
|
|
117
|
-
ts.factory.createKeywordTypeNode(
|
|
118
|
-
ts.SyntaxKind.UndefinedKeyword,
|
|
119
|
-
),
|
|
120
|
-
]),
|
|
121
|
-
),
|
|
95
|
+
"$defs",
|
|
96
|
+
ts.factory.createTypeReferenceNode("Record", [
|
|
97
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
98
|
+
schemaTypeNode,
|
|
122
99
|
]),
|
|
123
100
|
undefined,
|
|
124
101
|
),
|
|
@@ -127,35 +104,22 @@ export namespace LlmSchemaTransformer {
|
|
|
127
104
|
undefined,
|
|
128
105
|
ts.factory.createBlock(
|
|
129
106
|
[
|
|
130
|
-
ts.factory.
|
|
131
|
-
ts.factory.
|
|
132
|
-
ts.factory.createIdentifier("
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
"$defs",
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
"$defs",
|
|
147
|
-
),
|
|
148
|
-
ts.factory.createAsExpression(
|
|
149
|
-
LiteralFactory.write(out.$defs),
|
|
150
|
-
ts.factory.createTypeReferenceNode("Record", [
|
|
151
|
-
ts.factory.createKeywordTypeNode(
|
|
152
|
-
ts.SyntaxKind.StringKeyword,
|
|
153
|
-
),
|
|
154
|
-
schemaTypeNode,
|
|
155
|
-
]),
|
|
156
|
-
),
|
|
157
|
-
],
|
|
158
|
-
),
|
|
107
|
+
ts.factory.createExpressionStatement(
|
|
108
|
+
ts.factory.createCallExpression(
|
|
109
|
+
ts.factory.createIdentifier("Object.assign"),
|
|
110
|
+
undefined,
|
|
111
|
+
[
|
|
112
|
+
ts.factory.createIdentifier("$defs"),
|
|
113
|
+
ts.factory.createAsExpression(
|
|
114
|
+
LiteralFactory.write(out.$defs),
|
|
115
|
+
ts.factory.createTypeReferenceNode("Record", [
|
|
116
|
+
ts.factory.createKeywordTypeNode(
|
|
117
|
+
ts.SyntaxKind.StringKeyword,
|
|
118
|
+
),
|
|
119
|
+
schemaTypeNode,
|
|
120
|
+
]),
|
|
121
|
+
),
|
|
122
|
+
],
|
|
159
123
|
),
|
|
160
124
|
),
|
|
161
125
|
ts.factory.createReturnStatement(literal),
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LlmModelPredicator.js","sourceRoot":"","sources":["../../../src/programmers/llm/LlmModelPredicator.ts"],"names":[],"mappings":";;;;;;AACA,wFAAqF;AACrF,4DAA4B;AAE5B,2EAAwE;AACxE,qEAAkE;AAMlE,0EAAuE;AAIvE,IAAiB,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