typia 7.0.0-dev.20241023 → 7.0.0-dev.20241111
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/lib/factories/MetadataCollection.js +8 -8
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/internal/_llmApplicationFinalize.d.ts +1 -1
- package/lib/internal/_llmApplicationFinalize.js +5 -3
- package/lib/internal/_llmApplicationFinalize.js.map +1 -1
- package/lib/llm.d.ts +8 -4
- package/lib/llm.js.map +1 -1
- package/lib/programmers/internal/json_schema_array.js +9 -6
- package/lib/programmers/internal/json_schema_array.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.d.ts +5 -2
- package/lib/programmers/llm/LlmApplicationProgrammer.js +12 -6
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.d.ts +6 -3
- package/lib/programmers/llm/LlmSchemaProgrammer.js +72 -38
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
- package/lib/transformers/features/llm/LlmApplicationTransformer.js +42 -2
- package/lib/transformers/features/llm/LlmApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/llm/LlmSchemaTransformer.js +42 -2
- package/lib/transformers/features/llm/LlmSchemaTransformer.js.map +1 -1
- package/package.json +2 -2
- package/src/factories/MetadataCollection.ts +8 -8
- package/src/internal/_llmApplicationFinalize.ts +8 -7
- package/src/llm.ts +18 -6
- package/src/programmers/internal/json_schema_array.ts +9 -5
- package/src/programmers/llm/LlmApplicationProgrammer.ts +33 -18
- package/src/programmers/llm/LlmSchemaProgrammer.ts +61 -40
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +53 -2
- package/src/transformers/features/llm/LlmSchemaTransformer.ts +54 -3
|
@@ -28,6 +28,19 @@ export namespace LlmApplicationTransformer {
|
|
|
28
28
|
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
29
29
|
if (ts.isTypeNode(top) === false) return props.expression;
|
|
30
30
|
|
|
31
|
+
// GET MODEL
|
|
32
|
+
const model: ILlmApplication.Model = get_parameter<ILlmApplication.Model>({
|
|
33
|
+
checker: props.context.checker,
|
|
34
|
+
name: "Model",
|
|
35
|
+
is: (value) =>
|
|
36
|
+
value === "3.1" ||
|
|
37
|
+
value === "3.0" ||
|
|
38
|
+
value === "chatgpt" ||
|
|
39
|
+
value === "gemini",
|
|
40
|
+
cast: (value) => value as ILlmApplication.Model,
|
|
41
|
+
default: () => "3.1",
|
|
42
|
+
})(props.expression.typeArguments[1]);
|
|
43
|
+
|
|
31
44
|
// GET TYPE
|
|
32
45
|
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
33
46
|
const collection: MetadataCollection = new MetadataCollection({
|
|
@@ -42,7 +55,7 @@ export namespace LlmApplicationTransformer {
|
|
|
42
55
|
constant: true,
|
|
43
56
|
absorb: false,
|
|
44
57
|
functional: true,
|
|
45
|
-
validate: LlmApplicationProgrammer.validate(),
|
|
58
|
+
validate: LlmApplicationProgrammer.validate(model),
|
|
46
59
|
},
|
|
47
60
|
collection,
|
|
48
61
|
type,
|
|
@@ -54,7 +67,11 @@ export namespace LlmApplicationTransformer {
|
|
|
54
67
|
});
|
|
55
68
|
|
|
56
69
|
// GENERATE LLM APPLICATION
|
|
57
|
-
const schema: ILlmApplication =
|
|
70
|
+
const schema: ILlmApplication<ILlmApplication.Model> =
|
|
71
|
+
LlmApplicationProgrammer.write({
|
|
72
|
+
model,
|
|
73
|
+
metadata: result.data,
|
|
74
|
+
});
|
|
58
75
|
const literal: ts.Expression = LiteralFactory.write(schema);
|
|
59
76
|
if (!props.expression.arguments?.[0]) return literal;
|
|
60
77
|
|
|
@@ -83,4 +100,38 @@ export namespace LlmApplicationTransformer {
|
|
|
83
100
|
),
|
|
84
101
|
);
|
|
85
102
|
};
|
|
103
|
+
|
|
104
|
+
const get_parameter =
|
|
105
|
+
<Value>(props: {
|
|
106
|
+
checker: ts.TypeChecker;
|
|
107
|
+
name: string;
|
|
108
|
+
is: (value: string) => boolean;
|
|
109
|
+
cast: (value: string) => Value;
|
|
110
|
+
default: () => Value;
|
|
111
|
+
}) =>
|
|
112
|
+
(node: ts.TypeNode | undefined): Value => {
|
|
113
|
+
if (!node) return props.default();
|
|
114
|
+
|
|
115
|
+
// CHECK LITERAL TYPE
|
|
116
|
+
const type: ts.Type = props.checker.getTypeFromTypeNode(node);
|
|
117
|
+
if (
|
|
118
|
+
!type.isLiteral() &&
|
|
119
|
+
(type.getFlags() & ts.TypeFlags.BooleanLiteral) === 0
|
|
120
|
+
)
|
|
121
|
+
throw new TransformerError({
|
|
122
|
+
code: "typia.llm.application",
|
|
123
|
+
message: `generic argument "${props.name}" must be constant.`,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// GET VALUE AND VALIDATE IT
|
|
127
|
+
const value = type.isLiteral()
|
|
128
|
+
? type.value
|
|
129
|
+
: props.checker.typeToString(type);
|
|
130
|
+
if (typeof value !== "string" || props.is(value) === false)
|
|
131
|
+
throw new TransformerError({
|
|
132
|
+
code: "typia.llm.application",
|
|
133
|
+
message: `invalid value on generic argument "${props.name}".`,
|
|
134
|
+
});
|
|
135
|
+
return props.cast(value);
|
|
136
|
+
};
|
|
86
137
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ILlmApplication } from "@samchon/openapi";
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
|
|
4
4
|
import { LiteralFactory } from "../../../factories/LiteralFactory";
|
|
@@ -28,6 +28,19 @@ export namespace LlmSchemaTransformer {
|
|
|
28
28
|
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
29
29
|
if (ts.isTypeNode(top) === false) return props.expression;
|
|
30
30
|
|
|
31
|
+
// GET MODEL
|
|
32
|
+
const model: ILlmApplication.Model = get_parameter<ILlmApplication.Model>({
|
|
33
|
+
checker: props.context.checker,
|
|
34
|
+
name: "Model",
|
|
35
|
+
is: (value) =>
|
|
36
|
+
value === "3.1" ||
|
|
37
|
+
value === "3.0" ||
|
|
38
|
+
value === "chatgpt" ||
|
|
39
|
+
value === "gemini",
|
|
40
|
+
cast: (value) => value as ILlmApplication.Model,
|
|
41
|
+
default: () => "3.1",
|
|
42
|
+
})(props.expression.typeArguments[1]);
|
|
43
|
+
|
|
31
44
|
// GET TYPE
|
|
32
45
|
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
33
46
|
const collection: MetadataCollection = new MetadataCollection({
|
|
@@ -41,7 +54,7 @@ export namespace LlmSchemaTransformer {
|
|
|
41
54
|
escape: true,
|
|
42
55
|
constant: true,
|
|
43
56
|
absorb: false,
|
|
44
|
-
validate: LlmSchemaProgrammer.validate,
|
|
57
|
+
validate: LlmSchemaProgrammer.validate(model),
|
|
45
58
|
},
|
|
46
59
|
collection,
|
|
47
60
|
type,
|
|
@@ -53,7 +66,45 @@ export namespace LlmSchemaTransformer {
|
|
|
53
66
|
});
|
|
54
67
|
|
|
55
68
|
// GENERATE LLM SCHEMA
|
|
56
|
-
const schema:
|
|
69
|
+
const schema: ILlmApplication.ModelSchema[ILlmApplication.Model] =
|
|
70
|
+
LlmSchemaProgrammer.write({
|
|
71
|
+
model,
|
|
72
|
+
metadata: result.data,
|
|
73
|
+
});
|
|
57
74
|
return LiteralFactory.write(schema);
|
|
58
75
|
};
|
|
76
|
+
|
|
77
|
+
const get_parameter =
|
|
78
|
+
<Value>(props: {
|
|
79
|
+
checker: ts.TypeChecker;
|
|
80
|
+
name: string;
|
|
81
|
+
is: (value: string) => boolean;
|
|
82
|
+
cast: (value: string) => Value;
|
|
83
|
+
default: () => Value;
|
|
84
|
+
}) =>
|
|
85
|
+
(node: ts.TypeNode | undefined): Value => {
|
|
86
|
+
if (!node) return props.default();
|
|
87
|
+
|
|
88
|
+
// CHECK LITERAL TYPE
|
|
89
|
+
const type: ts.Type = props.checker.getTypeFromTypeNode(node);
|
|
90
|
+
if (
|
|
91
|
+
!type.isLiteral() &&
|
|
92
|
+
(type.getFlags() & ts.TypeFlags.BooleanLiteral) === 0
|
|
93
|
+
)
|
|
94
|
+
throw new TransformerError({
|
|
95
|
+
code: "typia.llm.schema",
|
|
96
|
+
message: `generic argument "${props.name}" must be constant.`,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// GET VALUE AND VALIDATE IT
|
|
100
|
+
const value = type.isLiteral()
|
|
101
|
+
? type.value
|
|
102
|
+
: props.checker.typeToString(type);
|
|
103
|
+
if (typeof value !== "string" || props.is(value) === false)
|
|
104
|
+
throw new TransformerError({
|
|
105
|
+
code: "typia.llm.schema",
|
|
106
|
+
message: `invalid value on generic argument "${props.name}".`,
|
|
107
|
+
});
|
|
108
|
+
return props.cast(value);
|
|
109
|
+
};
|
|
59
110
|
}
|