typia 9.7.2 → 10.0.0-dev.20251107
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/LICENSE +21 -21
- package/README.md +153 -153
- package/lib/factories/ProtobufFactory.js +1 -1
- package/lib/factories/ProtobufFactory.mjs +1 -1
- package/lib/programmers/internal/json_schema_station.d.mts +2 -2
- package/lib/programmers/internal/json_schema_station.d.ts +2 -2
- package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
- package/package.json +121 -121
- package/src/AssertionGuard.ts +41 -41
- package/src/CamelCase.ts +75 -75
- package/src/IRandomGenerator.ts +337 -337
- package/src/IReadableURLSearchParams.ts +9 -9
- package/src/PascalCase.ts +71 -71
- package/src/Primitive.ts +90 -90
- package/src/Resolved.ts +72 -72
- package/src/SnakeCase.ts +127 -127
- package/src/TypeGuardError.ts +216 -216
- package/src/factories/MetadataCollection.ts +270 -270
- package/src/factories/MetadataCommentTagFactory.ts +632 -632
- package/src/factories/MetadataFactory.ts +402 -402
- package/src/factories/ProtobufFactory.ts +873 -873
- package/src/functional.ts +705 -705
- package/src/http.ts +972 -972
- package/src/internal/_ProtobufReader.ts +188 -188
- package/src/internal/_ProtobufSizer.ts +137 -137
- package/src/internal/_ProtobufWriter.ts +135 -135
- package/src/internal/_jsonStringifyString.ts +42 -42
- package/src/json.ts +643 -643
- package/src/llm.ts +615 -615
- package/src/misc.ts +594 -594
- package/src/module.ts +889 -889
- package/src/notations.ts +751 -751
- package/src/programmers/FeatureProgrammer.ts +605 -605
- package/src/programmers/ImportProgrammer.ts +179 -179
- package/src/programmers/RandomProgrammer.ts +1195 -1195
- package/src/programmers/helpers/ProtobufWire.ts +34 -34
- package/src/programmers/internal/check_array_length.ts +43 -43
- package/src/programmers/internal/check_bigint.ts +46 -46
- package/src/programmers/internal/check_dynamic_key.ts +197 -197
- package/src/programmers/internal/check_dynamic_properties.ts +231 -231
- package/src/programmers/internal/check_everything.ts +21 -21
- package/src/programmers/internal/check_native.ts +23 -23
- package/src/programmers/internal/check_number.ts +108 -108
- package/src/programmers/internal/check_object.ts +72 -72
- package/src/programmers/internal/check_string.ts +46 -46
- package/src/programmers/internal/check_template.ts +46 -46
- package/src/programmers/internal/check_union_array_like.ts +331 -331
- package/src/programmers/internal/decode_union_object.ts +110 -110
- package/src/programmers/internal/feature_object_entries.ts +59 -59
- package/src/programmers/internal/json_schema_escaped.ts +78 -78
- package/src/programmers/internal/json_schema_object.ts +150 -150
- package/src/programmers/internal/json_schema_station.ts +2 -2
- package/src/programmers/internal/metadata_to_pattern.ts +40 -40
- package/src/programmers/internal/postfix_of_tuple.ts +3 -3
- package/src/programmers/internal/prune_object_properties.ts +69 -69
- package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
- package/src/programmers/internal/stringify_native.ts +5 -5
- package/src/programmers/internal/stringify_regular_properties.ts +77 -77
- package/src/programmers/internal/template_to_pattern.ts +21 -21
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
- package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
- package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
- package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
- package/src/protobuf.ts +820 -820
- package/src/reflect.ts +46 -46
- package/src/schemas/json/IJsonApplication.ts +77 -77
- package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
- package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
- package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
- package/src/schemas/metadata/Metadata.ts +669 -669
- package/src/schemas/metadata/MetadataAliasType.ts +57 -57
- package/src/schemas/metadata/MetadataApplication.ts +40 -40
- package/src/schemas/metadata/MetadataArray.ts +47 -47
- package/src/schemas/metadata/MetadataArrayType.ts +51 -51
- package/src/schemas/metadata/MetadataAtomic.ts +85 -85
- package/src/schemas/metadata/MetadataEscaped.ts +45 -45
- package/src/schemas/metadata/MetadataFunction.ts +45 -45
- package/src/schemas/metadata/MetadataObject.ts +46 -46
- package/src/schemas/metadata/MetadataObjectType.ts +137 -137
- package/src/schemas/metadata/MetadataParameter.ts +52 -52
- package/src/schemas/metadata/MetadataProperty.ts +53 -53
- package/src/schemas/metadata/MetadataTemplate.ts +78 -78
- package/src/schemas/metadata/MetadataTuple.ts +28 -28
- package/src/schemas/metadata/MetadataTupleType.ts +61 -61
- package/src/tags/Constant.ts +47 -47
- package/src/tags/ContentMediaType.ts +27 -27
- package/src/tags/Default.ts +52 -52
- package/src/tags/Example.ts +56 -56
- package/src/tags/Examples.ts +56 -56
- package/src/tags/ExclusiveMaximum.ts +44 -44
- package/src/tags/ExclusiveMinimum.ts +44 -44
- package/src/tags/Format.ts +78 -78
- package/src/tags/JsonSchemaPlugin.ts +36 -36
- package/src/tags/MaxItems.ts +31 -31
- package/src/tags/MaxLength.ts +25 -25
- package/src/tags/Maximum.ts +39 -39
- package/src/tags/MinItems.ts +31 -31
- package/src/tags/MinLength.ts +25 -25
- package/src/tags/Minimum.ts +39 -39
- package/src/tags/MultipleOf.ts +42 -42
- package/src/tags/Pattern.ts +49 -49
- package/src/tags/Sequence.ts +37 -37
- package/src/tags/TagBase.ts +102 -102
- package/src/tags/Type.ts +64 -64
- package/src/tags/UniqueItems.ts +34 -34
- package/src/tags/internal/FormatCheatSheet.ts +71 -71
- package/src/transformers/ITransformOptions.ts +70 -70
- package/src/transformers/ImportTransformer.ts +253 -253
- package/src/transformers/NoTransformConfigurationError.ts +16 -16
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
- package/src/typings/Equal.ts +18 -18
package/src/llm.ts
CHANGED
|
@@ -1,615 +1,615 @@
|
|
|
1
|
-
import { ILlmApplication, ILlmController, ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
|
-
import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* > You must configure the generic argument `Class`.
|
|
7
|
-
*
|
|
8
|
-
* TypeScript functions to LLM function calling controller.
|
|
9
|
-
*
|
|
10
|
-
* Creates a controller of LLM (Large Language Model) function calling from a
|
|
11
|
-
* TypeScript class or interface type containing the target functions to be
|
|
12
|
-
* called by the LLM function calling feature. The returned controller contains
|
|
13
|
-
* not only the {@link application} of
|
|
14
|
-
* {@link ILlmFunction function calling schemas}, but also the
|
|
15
|
-
* {@link ILlmController.execute executor} of the functions.
|
|
16
|
-
*
|
|
17
|
-
* If you put the returned {@link ILlmController} to the LLM provider like
|
|
18
|
-
* [OpenAI (ChatGPT)](https://openai.com/), the LLM will automatically select
|
|
19
|
-
* the proper function and fill its arguments from the conversation (maybe
|
|
20
|
-
* chatting text) with user (human). And you can actually call the function by
|
|
21
|
-
* using {@link ILlmController.execute} property. This is the concept of the LLM
|
|
22
|
-
* function calling.
|
|
23
|
-
*
|
|
24
|
-
* Here is an example of using `typia.llm.controller()` function for AI agent
|
|
25
|
-
* development of performing such AI function calling to mobile API classes
|
|
26
|
-
* through this `typia` and external `@agentica` libraries.
|
|
27
|
-
*
|
|
28
|
-
* ```typescript
|
|
29
|
-
* import { Agentica } from "@agentica/core";
|
|
30
|
-
* import typia from "typia";
|
|
31
|
-
*
|
|
32
|
-
* const agentica = new Agentica({
|
|
33
|
-
* model: "chatgpt",
|
|
34
|
-
* vendor: {
|
|
35
|
-
* api: new OpenAI({ apiKey: "********" }),
|
|
36
|
-
* model: "gpt-4o-mini",
|
|
37
|
-
* },
|
|
38
|
-
* controllers: [
|
|
39
|
-
* typia.llm.controller<ReactNativeFileSystem, "chatgpt">(
|
|
40
|
-
* "filesystem",
|
|
41
|
-
* new ReactNativeFileSystem(),
|
|
42
|
-
* ),
|
|
43
|
-
* typia.llm.controller<ReactNativeGallery, "chatgpt">(
|
|
44
|
-
* "gallery",
|
|
45
|
-
* new ReactNativeGallery(),
|
|
46
|
-
* ),
|
|
47
|
-
* ],
|
|
48
|
-
* });
|
|
49
|
-
* await agentica.conversate(
|
|
50
|
-
* "Organize photo collection and sort them into appropriate folders.",
|
|
51
|
-
* );
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* Here is the list of available `Model` types with their corresponding LLM
|
|
55
|
-
* schema. Reading the following list, and determine the `Model` type
|
|
56
|
-
* considering the characteristics of the target LLM provider.
|
|
57
|
-
*
|
|
58
|
-
* - LLM provider schemas
|
|
59
|
-
*
|
|
60
|
-
* - `chatgpt`:
|
|
61
|
-
* [`IChatGptSchema`](https://samchon.github.io/openapi/api/types/IChatGptSchema-1.html)
|
|
62
|
-
* - `claude`:
|
|
63
|
-
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
64
|
-
* - `deepseek`:
|
|
65
|
-
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
66
|
-
* - `gemini`:
|
|
67
|
-
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
68
|
-
* - `llama`:
|
|
69
|
-
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
70
|
-
* - Middle layer schemas
|
|
71
|
-
*
|
|
72
|
-
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
73
|
-
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
74
|
-
*
|
|
75
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
76
|
-
* @template Class Target class or interface type collecting the functions to
|
|
77
|
-
* call
|
|
78
|
-
* @template Model LLM schema model
|
|
79
|
-
* @template Config Configuration of LLM schema composition
|
|
80
|
-
* @param name Identifier name of the controller
|
|
81
|
-
* @param execute Executor instance
|
|
82
|
-
* @param options Options for the LLM application construction
|
|
83
|
-
* @returns Controller of LLM function calling
|
|
84
|
-
* @reference https://wrtnlabs.io/agentica/docs/core/controller/typescript/
|
|
85
|
-
*/
|
|
86
|
-
export function controller(
|
|
87
|
-
name: string,
|
|
88
|
-
execute: object,
|
|
89
|
-
options?: Partial<
|
|
90
|
-
Pick<ILlmApplication.IOptions<any, any>, "separate" | "validate">
|
|
91
|
-
>,
|
|
92
|
-
): never;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* TypeScript functions to LLM function calling controller.
|
|
96
|
-
*
|
|
97
|
-
* Creates a controller of LLM (Large Language Model) function calling from a
|
|
98
|
-
* TypeScript class or interface type containing the target functions to be
|
|
99
|
-
* called by the LLM function calling feature. The returned controller contains
|
|
100
|
-
* not only the {@link application} of
|
|
101
|
-
* {@link ILlmFunction function calling schemas}, but also the
|
|
102
|
-
* {@link ILlmController.execute executor} of the functions.
|
|
103
|
-
*
|
|
104
|
-
* If you put the returned {@link ILlmController} to the LLM provider like
|
|
105
|
-
* [OpenAI (ChatGPT)](https://openai.com/), the LLM will automatically select
|
|
106
|
-
* the proper function and fill its arguments from the conversation (maybe
|
|
107
|
-
* chatting text) with user (human). And you can actually call the function by
|
|
108
|
-
* using {@link ILlmController.execute} property. This is the concept of the LLM
|
|
109
|
-
* function calling.
|
|
110
|
-
*
|
|
111
|
-
* Here is an example of using `typia.llm.controller()` function for AI agent
|
|
112
|
-
* development of performing such AI function calling to mobile API classes
|
|
113
|
-
* through this `typia` and external `@agentica` libraries.
|
|
114
|
-
*
|
|
115
|
-
* ```typescript
|
|
116
|
-
* import { Agentica } from "@agentica/core";
|
|
117
|
-
* import typia from "typia";
|
|
118
|
-
*
|
|
119
|
-
* const agentica = new Agentica({
|
|
120
|
-
* model: "chatgpt",
|
|
121
|
-
* vendor: {
|
|
122
|
-
* api: new OpenAI({ apiKey: "********" }),
|
|
123
|
-
* model: "gpt-4o-mini",
|
|
124
|
-
* },
|
|
125
|
-
* controllers: [
|
|
126
|
-
* typia.llm.controller<ReactNativeFileSystem, "chatgpt">(
|
|
127
|
-
* "filesystem",
|
|
128
|
-
* new ReactNativeFileSystem(),
|
|
129
|
-
* ),
|
|
130
|
-
* typia.llm.controller<ReactNativeGallery, "chatgpt">(
|
|
131
|
-
* "gallery",
|
|
132
|
-
* new ReactNativeGallery(),
|
|
133
|
-
* ),
|
|
134
|
-
* ],
|
|
135
|
-
* });
|
|
136
|
-
* await agentica.conversate(
|
|
137
|
-
* "Organize photo collection and sort them into appropriate folders.",
|
|
138
|
-
* );
|
|
139
|
-
* ```
|
|
140
|
-
*
|
|
141
|
-
* Here is the list of available `Model` types with their corresponding LLM
|
|
142
|
-
* schema. Reading the following list, and determine the `Model` type
|
|
143
|
-
* considering the characteristics of the target LLM provider.
|
|
144
|
-
*
|
|
145
|
-
* - LLM provider schemas
|
|
146
|
-
*
|
|
147
|
-
* - `chatgpt`:
|
|
148
|
-
* [`IChatGptSchema`](https://samchon.github.io/openapi/api/types/IChatGptSchema-1.html)
|
|
149
|
-
* - `claude`:
|
|
150
|
-
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
151
|
-
* - `deepseek`:
|
|
152
|
-
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
153
|
-
* - `gemini`:
|
|
154
|
-
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
155
|
-
* - `llama`:
|
|
156
|
-
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
157
|
-
* - Middle layer schemas
|
|
158
|
-
*
|
|
159
|
-
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
160
|
-
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
161
|
-
*
|
|
162
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
163
|
-
* @template Class Target class or interface type collecting the functions to
|
|
164
|
-
* call
|
|
165
|
-
* @template Model LLM schema model
|
|
166
|
-
* @template Config Configuration of LLM schema composition
|
|
167
|
-
* @param name Identifier name of the controller
|
|
168
|
-
* @param execute Executor instance
|
|
169
|
-
* @param options Options for the LLM application construction
|
|
170
|
-
* @returns Controller of LLM function calling
|
|
171
|
-
* @reference https://wrtnlabs.io/agentica/docs/core/controller/typescript/
|
|
172
|
-
*/
|
|
173
|
-
export function controller<
|
|
174
|
-
Class extends Record<string, any>,
|
|
175
|
-
Model extends ILlmSchema.Model,
|
|
176
|
-
Config extends Partial<
|
|
177
|
-
ILlmSchema.ModelConfig[Model] & {
|
|
178
|
-
/**
|
|
179
|
-
* Whether to disallow superfluous properties or not.
|
|
180
|
-
*
|
|
181
|
-
* If configure as `true`, {@link validateEquals} function would be used
|
|
182
|
-
* for validation feedback, which is more strict than {@link validate}
|
|
183
|
-
* function.
|
|
184
|
-
*
|
|
185
|
-
* @default false
|
|
186
|
-
*/
|
|
187
|
-
equals: boolean;
|
|
188
|
-
}
|
|
189
|
-
> = {},
|
|
190
|
-
>(
|
|
191
|
-
name: string,
|
|
192
|
-
execute: Class,
|
|
193
|
-
options?: Partial<
|
|
194
|
-
Pick<ILlmApplication.IOptions<Model, Class>, "separate" | "validate">
|
|
195
|
-
>,
|
|
196
|
-
): ILlmController<Model>;
|
|
197
|
-
|
|
198
|
-
/** @internal */
|
|
199
|
-
export function controller(..._args: any[]): never {
|
|
200
|
-
NoTransformConfigurationError("llm.controller");
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* > You must configure the generic argument `Class`.
|
|
205
|
-
*
|
|
206
|
-
* TypeScript functions to LLM function calling application.
|
|
207
|
-
*
|
|
208
|
-
* Creates an application of LLM (Large Language Model) function calling
|
|
209
|
-
* application from a TypeScript class or interface type containing the target
|
|
210
|
-
* functions to be called by the LLM function calling feature.
|
|
211
|
-
*
|
|
212
|
-
* If you put the returned {@link ILlmApplication.functions} objects to the LLM
|
|
213
|
-
* provider like [OpenAI (ChatGPT)](https://openai.com/), the LLM will
|
|
214
|
-
* automatically select the proper function and fill its arguments from the
|
|
215
|
-
* conversation (maybe chatting text) with user (human). This is the concept of
|
|
216
|
-
* the LLM function calling.
|
|
217
|
-
*
|
|
218
|
-
* By the way, there can be some parameters (or their nested properties) which
|
|
219
|
-
* must be composed by human, not by LLM. File uploading feature or some
|
|
220
|
-
* sensitive information like security keys (password) are the examples. In that
|
|
221
|
-
* case, you can separate the function parameters to both LLM and human sides by
|
|
222
|
-
* configuring the {@link ILlmApplication.IOptions.separate} property. The
|
|
223
|
-
* separated parameters are assigned to the {@link ILlmFunction.separated}
|
|
224
|
-
* property.
|
|
225
|
-
*
|
|
226
|
-
* For reference, the actual function call execution is not by LLM, but by you.
|
|
227
|
-
* When the LLM selects the proper function and fills the arguments, you just
|
|
228
|
-
* call the function with the LLM prepared arguments. And then informs the
|
|
229
|
-
* return value to the LLM by system prompt. The LLM will continue the next
|
|
230
|
-
* conversation based on the return value.
|
|
231
|
-
*
|
|
232
|
-
* Additionally, if you've configured {@link ILlmApplication.IOptions.separate},
|
|
233
|
-
* so that the parameters are separated to human and LLM sides, you can merge
|
|
234
|
-
* these human and LLM sides' parameters into one through
|
|
235
|
-
* {@link HttpLlm.mergeParameters} before the actual LLM function call
|
|
236
|
-
* execution.
|
|
237
|
-
*
|
|
238
|
-
* Here is the list of available `Model` types with their corresponding LLM
|
|
239
|
-
* schema. Reading the following list, and determine the `Model` type
|
|
240
|
-
* considering the characteristics of the target LLM provider.
|
|
241
|
-
*
|
|
242
|
-
* - LLM provider schemas
|
|
243
|
-
*
|
|
244
|
-
* - `chatgpt`:
|
|
245
|
-
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
246
|
-
* - `claude`:
|
|
247
|
-
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
248
|
-
* - `deepseek`:
|
|
249
|
-
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
250
|
-
* - `gemini`:
|
|
251
|
-
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
252
|
-
* - `llama`:
|
|
253
|
-
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
254
|
-
* - Middle layer schemas
|
|
255
|
-
*
|
|
256
|
-
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
257
|
-
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
258
|
-
*
|
|
259
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
260
|
-
* @template Class Target class or interface type collecting the functions to
|
|
261
|
-
* call
|
|
262
|
-
* @template Model LLM schema model
|
|
263
|
-
* @template Config Configuration of LLM schema composition
|
|
264
|
-
* @param options Options for the LLM application construction
|
|
265
|
-
* @returns Application of LLM function calling schemas
|
|
266
|
-
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
267
|
-
*/
|
|
268
|
-
export function application(
|
|
269
|
-
options?: Partial<
|
|
270
|
-
Pick<ILlmApplication.IOptions<any, any>, "separate" | "validate">
|
|
271
|
-
>,
|
|
272
|
-
): never;
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* TypeScript functions to LLM function calling application.
|
|
276
|
-
*
|
|
277
|
-
* Creates an application of LLM (Large Language Model) function calling
|
|
278
|
-
* application from a TypeScript class or interface type containing the target
|
|
279
|
-
* functions to be called by the LLM function calling feature.
|
|
280
|
-
*
|
|
281
|
-
* If you put the returned {@link ILlmApplication.functions} objects to the LLM
|
|
282
|
-
* provider like [OpenAI (ChatGPT)](https://openai.com/), the LLM will
|
|
283
|
-
* automatically select the proper function and fill its arguments from the
|
|
284
|
-
* conversation (maybe chatting text) with user (human). This is the concept of
|
|
285
|
-
* the LLM function calling.
|
|
286
|
-
*
|
|
287
|
-
* By the way, there can be some parameters (or their nested properties) which
|
|
288
|
-
* must be composed by human, not by LLM. File uploading feature or some
|
|
289
|
-
* sensitive information like security keys (password) are the examples. In that
|
|
290
|
-
* case, you can separate the function parameters to both LLM and human sides by
|
|
291
|
-
* configuring the {@link ILlmApplication.IOptions.separate} property. The
|
|
292
|
-
* separated parameters are assigned to the {@link ILlmFunction.separated}
|
|
293
|
-
* property.
|
|
294
|
-
*
|
|
295
|
-
* For reference, the actual function call execution is not by LLM, but by you.
|
|
296
|
-
* When the LLM selects the proper function and fills the arguments, you just
|
|
297
|
-
* call the function with the LLM prepared arguments. And then informs the
|
|
298
|
-
* return value to the LLM by system prompt. The LLM will continue the next
|
|
299
|
-
* conversation based on the return value.
|
|
300
|
-
*
|
|
301
|
-
* Additionally, if you've configured {@link ILlmApplication.IOptions.separate},
|
|
302
|
-
* so that the parameters are separated to human and LLM sides, you can merge
|
|
303
|
-
* these human and LLM sides' parameters into one through
|
|
304
|
-
* {@link HttpLlm.mergeParameters} before the actual LLM function call
|
|
305
|
-
* execution.
|
|
306
|
-
*
|
|
307
|
-
* Here is the list of available `Model` types with their corresponding LLM
|
|
308
|
-
* schema. Reading the following list, and determine the `Model` type
|
|
309
|
-
* considering the characteristics of the target LLM provider.
|
|
310
|
-
*
|
|
311
|
-
* - LLM provider schemas
|
|
312
|
-
*
|
|
313
|
-
* - `chatgpt`:
|
|
314
|
-
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
315
|
-
* - `claude`:
|
|
316
|
-
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
317
|
-
* - `deepseek`:
|
|
318
|
-
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
319
|
-
* - `gemini`:
|
|
320
|
-
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
321
|
-
* - `llama`:
|
|
322
|
-
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
323
|
-
* - Middle layer schemas
|
|
324
|
-
*
|
|
325
|
-
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
326
|
-
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
327
|
-
*
|
|
328
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
329
|
-
* @template Class Target class or interface type collecting the functions to
|
|
330
|
-
* call
|
|
331
|
-
* @template Model LLM schema model
|
|
332
|
-
* @template Config Configuration of LLM schema composition
|
|
333
|
-
* @param options Options for the LLM application construction
|
|
334
|
-
* @returns Application of LLM function calling schemas
|
|
335
|
-
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
336
|
-
*/
|
|
337
|
-
export function application<
|
|
338
|
-
Class extends Record<string, any>,
|
|
339
|
-
Model extends ILlmSchema.Model,
|
|
340
|
-
Config extends Partial<
|
|
341
|
-
{
|
|
342
|
-
/**
|
|
343
|
-
* Whether to disallow superfluous properties or not.
|
|
344
|
-
*
|
|
345
|
-
* If configure as `true`, {@link validateEquals} function would be used
|
|
346
|
-
* for validation feedback, which is more strict than {@link validate}
|
|
347
|
-
* function.
|
|
348
|
-
*
|
|
349
|
-
* @default false
|
|
350
|
-
*/
|
|
351
|
-
equals: boolean;
|
|
352
|
-
} & ILlmSchema.ModelConfig[Model]
|
|
353
|
-
> = {},
|
|
354
|
-
>(
|
|
355
|
-
options?: Partial<
|
|
356
|
-
Pick<ILlmApplication.IOptions<Model, Class>, "separate" | "validate">
|
|
357
|
-
>,
|
|
358
|
-
): ILlmApplication<Model, Class>;
|
|
359
|
-
|
|
360
|
-
/** @internal */
|
|
361
|
-
export function application(): never {
|
|
362
|
-
NoTransformConfigurationError("llm.application");
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* > You must configure the generic argument `Parameters`.
|
|
367
|
-
*
|
|
368
|
-
* TypeScript parameters to LLM parameters schema.
|
|
369
|
-
*
|
|
370
|
-
* Creates an LLM (Large Language Model) parameters schema, a type metadata that
|
|
371
|
-
* is used in the [LLM function
|
|
372
|
-
* calling](https://platform.openai.com/docs/guides/function-calling) and [LLM
|
|
373
|
-
* structured
|
|
374
|
-
* outputs](https://platform.openai.com/docs/guides/structured-outputs), from a
|
|
375
|
-
* TypeScript parameters type.
|
|
376
|
-
*
|
|
377
|
-
* For references, LLM identifies only keyworded arguments, not positional
|
|
378
|
-
* arguments. Therefore, the TypeScript parameters type must be an object type,
|
|
379
|
-
* and its properties must be static. If dynamic properties are, it will be
|
|
380
|
-
* compilation error.
|
|
381
|
-
*
|
|
382
|
-
* Also, such parameters type can be utilized not only for the LLM function
|
|
383
|
-
* calling, but also for the LLM structured outputs. The LLM structured outputs
|
|
384
|
-
* is a feature that LLM (Large Language Model) can generate a structured
|
|
385
|
-
* output, not only a plain text, by filling the parameters from the
|
|
386
|
-
* conversation (maybe chatting text) with user (human).
|
|
387
|
-
*
|
|
388
|
-
* Here is the list of available `Model` types with their corresponding LLM
|
|
389
|
-
* schema. Reading the following list, and determine the `Model` type
|
|
390
|
-
* considering the characteristics of the target LLM provider.
|
|
391
|
-
*
|
|
392
|
-
* - LLM provider schemas
|
|
393
|
-
*
|
|
394
|
-
* - `chatgpt`:
|
|
395
|
-
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
396
|
-
* - `claude`:
|
|
397
|
-
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
398
|
-
* - `deepseek`:
|
|
399
|
-
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
400
|
-
* - `gemini`:
|
|
401
|
-
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
402
|
-
* - `llama`:
|
|
403
|
-
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
404
|
-
* - Middle layer schemas
|
|
405
|
-
*
|
|
406
|
-
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
407
|
-
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
408
|
-
*
|
|
409
|
-
* @template Parameters Target parameters type
|
|
410
|
-
* @template Model LLM schema model
|
|
411
|
-
* @template Config Configuration of LLM schema composition
|
|
412
|
-
* @returns LLM parameters schema
|
|
413
|
-
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
414
|
-
* @reference https://platform.openai.com/docs/guides/structured-outputs
|
|
415
|
-
*/
|
|
416
|
-
export function parameters(): never;
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* TypeScript parameters to LLM parameters schema.
|
|
420
|
-
*
|
|
421
|
-
* Creates an LLM (Large Language Model) parameters schema, a type metadata that
|
|
422
|
-
* is used in the [LLM function
|
|
423
|
-
* calling](https://platform.openai.com/docs/guides/function-calling) and [LLM
|
|
424
|
-
* structured
|
|
425
|
-
* outputs](https://platform.openai.com/docs/guides/structured-outputs), from a
|
|
426
|
-
* TypeScript parameters type.
|
|
427
|
-
*
|
|
428
|
-
* For references, LLM identifies only keyworded arguments, not positional
|
|
429
|
-
* arguments. Therefore, the TypeScript parameters type must be an object type,
|
|
430
|
-
* and its properties must be static. If dynamic properties are, it will be
|
|
431
|
-
* compilation error.
|
|
432
|
-
*
|
|
433
|
-
* Also, such parameters type can be utilized not only for the LLM function
|
|
434
|
-
* calling, but also for the LLM structured outputs. The LLM structured outputs
|
|
435
|
-
* is a feature that LLM (Large Language Model) can generate a structured
|
|
436
|
-
* output, not only a plain text, by filling the parameters from the
|
|
437
|
-
* conversation (maybe chatting text) with user (human).
|
|
438
|
-
*
|
|
439
|
-
* Here is the list of available `Model` types with their corresponding LLM
|
|
440
|
-
* schema. Reading the following list, and determine the `Model` type
|
|
441
|
-
* considering the characteristics of the target LLM provider.
|
|
442
|
-
*
|
|
443
|
-
* - LLM provider schemas
|
|
444
|
-
*
|
|
445
|
-
* - `chatgpt`:
|
|
446
|
-
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
447
|
-
* - `claude`:
|
|
448
|
-
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
449
|
-
* - `deepseek`:
|
|
450
|
-
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
451
|
-
* - `gemini`:
|
|
452
|
-
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
453
|
-
* - `llama`:
|
|
454
|
-
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
455
|
-
* - Middle layer schemas
|
|
456
|
-
*
|
|
457
|
-
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
458
|
-
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
459
|
-
*
|
|
460
|
-
* @template Parameters Target parameters type
|
|
461
|
-
* @template Model LLM schema model
|
|
462
|
-
* @template Config Configuration of LLM schema composition
|
|
463
|
-
* @returns LLM parameters schema
|
|
464
|
-
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
465
|
-
* @reference https://platform.openai.com/docs/guides/structured-outputs
|
|
466
|
-
*/
|
|
467
|
-
export function parameters<
|
|
468
|
-
Parameters extends Record<string, any>,
|
|
469
|
-
Model extends ILlmSchema.Model,
|
|
470
|
-
Config extends Partial<ILlmSchema.ModelConfig[Model]> = {},
|
|
471
|
-
>(): ILlmSchema.ModelParameters[Model];
|
|
472
|
-
|
|
473
|
-
/** @internal */
|
|
474
|
-
export function parameters(): never {
|
|
475
|
-
NoTransformConfigurationError("llm.parameters");
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
/**
|
|
479
|
-
* > You must configure the generic argument `T`.
|
|
480
|
-
*
|
|
481
|
-
* TypeScript type to LLM type schema.
|
|
482
|
-
*
|
|
483
|
-
* Creates an LLM (Large Language Model) type schema, a type metadata that is
|
|
484
|
-
* used in the [LLM function calling](@reference
|
|
485
|
-
* https://platform.openai.com/docs/guides/function-calling), from a TypeScript
|
|
486
|
-
* type.
|
|
487
|
-
*
|
|
488
|
-
* The returned {@link ILlmSchema} type will be specified by the `Model`
|
|
489
|
-
* argument, and here is the list of available `Model` types with their
|
|
490
|
-
* corresponding LLM schema. Reading the following list, and determine the
|
|
491
|
-
* `Model` type considering the characteristics of the target LLM provider.
|
|
492
|
-
*
|
|
493
|
-
* - LLM provider schemas
|
|
494
|
-
*
|
|
495
|
-
* - `chatgpt`:
|
|
496
|
-
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
497
|
-
* - `claude`:
|
|
498
|
-
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
499
|
-
* - `deepseek`:
|
|
500
|
-
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
501
|
-
* - `gemini`:
|
|
502
|
-
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
503
|
-
* - `llama`:
|
|
504
|
-
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
505
|
-
* - Middle layer schemas
|
|
506
|
-
*
|
|
507
|
-
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
508
|
-
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
509
|
-
*
|
|
510
|
-
* If you actually want to perform the LLM function calling with TypeScript
|
|
511
|
-
* functions, you can do it with the {@link application} function. Otherwise you
|
|
512
|
-
* hope to perform the structured output, {@link parameters} function is better.
|
|
513
|
-
* Let's enjoy the LLM function calling and structured output with the native
|
|
514
|
-
* TypeScript functions and types.
|
|
515
|
-
*
|
|
516
|
-
* > **What LLM function calling is?
|
|
517
|
-
*
|
|
518
|
-
* > LLM (Large Language Model) selects property function and fill the arguments,
|
|
519
|
-
* > but actual function call execution is not by LLM, but by you.
|
|
520
|
-
*
|
|
521
|
-
* > In nowadays, most LLM (Large Language Model) like OpenAI are supporting
|
|
522
|
-
* > "function calling" feature. The "function calling" means that LLM
|
|
523
|
-
* > automatically selects a proper function and compose parameter values from the
|
|
524
|
-
* > user's chatting text.
|
|
525
|
-
*
|
|
526
|
-
* > When LLM selects the proper function and its arguments, you just call the
|
|
527
|
-
* > function with the arguments. And then informs the return value to the LLM by
|
|
528
|
-
* > system prompt, LLM will continue the next conversation based on the return
|
|
529
|
-
* > value.
|
|
530
|
-
*
|
|
531
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
532
|
-
* @template T Target type
|
|
533
|
-
* @template Model LLM schema model
|
|
534
|
-
* @template Config Configuration of LLM schema composition
|
|
535
|
-
* @returns LLM schema
|
|
536
|
-
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
537
|
-
* @reference https://platform.openai.com/docs/guides/structured-outputs
|
|
538
|
-
*/
|
|
539
|
-
export function schema(): never;
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
* TypeScript type to LLM type schema.
|
|
543
|
-
*
|
|
544
|
-
* Creates an LLM (Large Language Model) type schema, a type metadata that is
|
|
545
|
-
* used in the [LLM function calling](@reference
|
|
546
|
-
* https://platform.openai.com/docs/guides/function-calling), from a TypeScript
|
|
547
|
-
* type.
|
|
548
|
-
*
|
|
549
|
-
* The returned {@link ILlmSchema} type will be specified by the `Model`
|
|
550
|
-
* argument, and here is the list of available `Model` types with their
|
|
551
|
-
* corresponding LLM schema:
|
|
552
|
-
*
|
|
553
|
-
* - LLM provider schemas
|
|
554
|
-
*
|
|
555
|
-
* - `chatgpt`:
|
|
556
|
-
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
557
|
-
* - `claude`:
|
|
558
|
-
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
559
|
-
* - `deepseek`:
|
|
560
|
-
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
561
|
-
* - `gemini`:
|
|
562
|
-
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
563
|
-
* - `llama`:
|
|
564
|
-
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
565
|
-
* - Middle layer schemas
|
|
566
|
-
*
|
|
567
|
-
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
568
|
-
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
569
|
-
*
|
|
570
|
-
* If you actually want to perform the LLM function calling with TypeScript
|
|
571
|
-
* functions, you can do it with the {@link application} function. Otherwise you
|
|
572
|
-
* hope to perform the structured output, {@link parameters} function is better.
|
|
573
|
-
* Let's enjoy the LLM function calling and structured output with the native
|
|
574
|
-
* TypeScript functions and types.
|
|
575
|
-
*
|
|
576
|
-
* > **What LLM function calling is?
|
|
577
|
-
*
|
|
578
|
-
* > LLM (Large Language Model) selects property function and fill the arguments,
|
|
579
|
-
* > but actual function call execution is not by LLM, but by you.
|
|
580
|
-
*
|
|
581
|
-
* > In nowadays, most LLM (Large Language Model) like OpenAI are supporting
|
|
582
|
-
* > "function calling" feature. The "function calling" means that LLM
|
|
583
|
-
* > automatically selects a proper function and compose parameter values from the
|
|
584
|
-
* > user's chatting text.
|
|
585
|
-
*
|
|
586
|
-
* > When LLM selects the proper function and its arguments, you just call the
|
|
587
|
-
* > function with the arguments. And then informs the return value to the LLM by
|
|
588
|
-
* > system prompt, LLM will continue the next conversation based on the return
|
|
589
|
-
* > value.
|
|
590
|
-
*
|
|
591
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
592
|
-
* @template T Target type
|
|
593
|
-
* @template Model LLM schema model
|
|
594
|
-
* @template Config Configuration of LLM schema composition
|
|
595
|
-
* @returns LLM schema
|
|
596
|
-
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
597
|
-
* @reference https://platform.openai.com/docs/guides/structured-outputs
|
|
598
|
-
*/
|
|
599
|
-
export function schema<
|
|
600
|
-
T,
|
|
601
|
-
Model extends ILlmSchema.Model,
|
|
602
|
-
Config extends Partial<ILlmSchema.ModelConfig[Model]> = {},
|
|
603
|
-
>(
|
|
604
|
-
...$defs: Extract<
|
|
605
|
-
ILlmSchema.ModelSchema[Model],
|
|
606
|
-
{ $ref: string }
|
|
607
|
-
> extends never
|
|
608
|
-
? []
|
|
609
|
-
: [Record<string, ILlmSchema.ModelSchema[Model]>]
|
|
610
|
-
): ILlmSchema.ModelSchema[Model];
|
|
611
|
-
|
|
612
|
-
/** @internal */
|
|
613
|
-
export function schema(): never {
|
|
614
|
-
NoTransformConfigurationError("llm.schema");
|
|
615
|
-
}
|
|
1
|
+
import { ILlmApplication, ILlmController, ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* > You must configure the generic argument `Class`.
|
|
7
|
+
*
|
|
8
|
+
* TypeScript functions to LLM function calling controller.
|
|
9
|
+
*
|
|
10
|
+
* Creates a controller of LLM (Large Language Model) function calling from a
|
|
11
|
+
* TypeScript class or interface type containing the target functions to be
|
|
12
|
+
* called by the LLM function calling feature. The returned controller contains
|
|
13
|
+
* not only the {@link application} of
|
|
14
|
+
* {@link ILlmFunction function calling schemas}, but also the
|
|
15
|
+
* {@link ILlmController.execute executor} of the functions.
|
|
16
|
+
*
|
|
17
|
+
* If you put the returned {@link ILlmController} to the LLM provider like
|
|
18
|
+
* [OpenAI (ChatGPT)](https://openai.com/), the LLM will automatically select
|
|
19
|
+
* the proper function and fill its arguments from the conversation (maybe
|
|
20
|
+
* chatting text) with user (human). And you can actually call the function by
|
|
21
|
+
* using {@link ILlmController.execute} property. This is the concept of the LLM
|
|
22
|
+
* function calling.
|
|
23
|
+
*
|
|
24
|
+
* Here is an example of using `typia.llm.controller()` function for AI agent
|
|
25
|
+
* development of performing such AI function calling to mobile API classes
|
|
26
|
+
* through this `typia` and external `@agentica` libraries.
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { Agentica } from "@agentica/core";
|
|
30
|
+
* import typia from "typia";
|
|
31
|
+
*
|
|
32
|
+
* const agentica = new Agentica({
|
|
33
|
+
* model: "chatgpt",
|
|
34
|
+
* vendor: {
|
|
35
|
+
* api: new OpenAI({ apiKey: "********" }),
|
|
36
|
+
* model: "gpt-4o-mini",
|
|
37
|
+
* },
|
|
38
|
+
* controllers: [
|
|
39
|
+
* typia.llm.controller<ReactNativeFileSystem, "chatgpt">(
|
|
40
|
+
* "filesystem",
|
|
41
|
+
* new ReactNativeFileSystem(),
|
|
42
|
+
* ),
|
|
43
|
+
* typia.llm.controller<ReactNativeGallery, "chatgpt">(
|
|
44
|
+
* "gallery",
|
|
45
|
+
* new ReactNativeGallery(),
|
|
46
|
+
* ),
|
|
47
|
+
* ],
|
|
48
|
+
* });
|
|
49
|
+
* await agentica.conversate(
|
|
50
|
+
* "Organize photo collection and sort them into appropriate folders.",
|
|
51
|
+
* );
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* Here is the list of available `Model` types with their corresponding LLM
|
|
55
|
+
* schema. Reading the following list, and determine the `Model` type
|
|
56
|
+
* considering the characteristics of the target LLM provider.
|
|
57
|
+
*
|
|
58
|
+
* - LLM provider schemas
|
|
59
|
+
*
|
|
60
|
+
* - `chatgpt`:
|
|
61
|
+
* [`IChatGptSchema`](https://samchon.github.io/openapi/api/types/IChatGptSchema-1.html)
|
|
62
|
+
* - `claude`:
|
|
63
|
+
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
64
|
+
* - `deepseek`:
|
|
65
|
+
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
66
|
+
* - `gemini`:
|
|
67
|
+
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
68
|
+
* - `llama`:
|
|
69
|
+
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
70
|
+
* - Middle layer schemas
|
|
71
|
+
*
|
|
72
|
+
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
73
|
+
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
74
|
+
*
|
|
75
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
76
|
+
* @template Class Target class or interface type collecting the functions to
|
|
77
|
+
* call
|
|
78
|
+
* @template Model LLM schema model
|
|
79
|
+
* @template Config Configuration of LLM schema composition
|
|
80
|
+
* @param name Identifier name of the controller
|
|
81
|
+
* @param execute Executor instance
|
|
82
|
+
* @param options Options for the LLM application construction
|
|
83
|
+
* @returns Controller of LLM function calling
|
|
84
|
+
* @reference https://wrtnlabs.io/agentica/docs/core/controller/typescript/
|
|
85
|
+
*/
|
|
86
|
+
export function controller(
|
|
87
|
+
name: string,
|
|
88
|
+
execute: object,
|
|
89
|
+
options?: Partial<
|
|
90
|
+
Pick<ILlmApplication.IOptions<any, any>, "separate" | "validate">
|
|
91
|
+
>,
|
|
92
|
+
): never;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* TypeScript functions to LLM function calling controller.
|
|
96
|
+
*
|
|
97
|
+
* Creates a controller of LLM (Large Language Model) function calling from a
|
|
98
|
+
* TypeScript class or interface type containing the target functions to be
|
|
99
|
+
* called by the LLM function calling feature. The returned controller contains
|
|
100
|
+
* not only the {@link application} of
|
|
101
|
+
* {@link ILlmFunction function calling schemas}, but also the
|
|
102
|
+
* {@link ILlmController.execute executor} of the functions.
|
|
103
|
+
*
|
|
104
|
+
* If you put the returned {@link ILlmController} to the LLM provider like
|
|
105
|
+
* [OpenAI (ChatGPT)](https://openai.com/), the LLM will automatically select
|
|
106
|
+
* the proper function and fill its arguments from the conversation (maybe
|
|
107
|
+
* chatting text) with user (human). And you can actually call the function by
|
|
108
|
+
* using {@link ILlmController.execute} property. This is the concept of the LLM
|
|
109
|
+
* function calling.
|
|
110
|
+
*
|
|
111
|
+
* Here is an example of using `typia.llm.controller()` function for AI agent
|
|
112
|
+
* development of performing such AI function calling to mobile API classes
|
|
113
|
+
* through this `typia` and external `@agentica` libraries.
|
|
114
|
+
*
|
|
115
|
+
* ```typescript
|
|
116
|
+
* import { Agentica } from "@agentica/core";
|
|
117
|
+
* import typia from "typia";
|
|
118
|
+
*
|
|
119
|
+
* const agentica = new Agentica({
|
|
120
|
+
* model: "chatgpt",
|
|
121
|
+
* vendor: {
|
|
122
|
+
* api: new OpenAI({ apiKey: "********" }),
|
|
123
|
+
* model: "gpt-4o-mini",
|
|
124
|
+
* },
|
|
125
|
+
* controllers: [
|
|
126
|
+
* typia.llm.controller<ReactNativeFileSystem, "chatgpt">(
|
|
127
|
+
* "filesystem",
|
|
128
|
+
* new ReactNativeFileSystem(),
|
|
129
|
+
* ),
|
|
130
|
+
* typia.llm.controller<ReactNativeGallery, "chatgpt">(
|
|
131
|
+
* "gallery",
|
|
132
|
+
* new ReactNativeGallery(),
|
|
133
|
+
* ),
|
|
134
|
+
* ],
|
|
135
|
+
* });
|
|
136
|
+
* await agentica.conversate(
|
|
137
|
+
* "Organize photo collection and sort them into appropriate folders.",
|
|
138
|
+
* );
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* Here is the list of available `Model` types with their corresponding LLM
|
|
142
|
+
* schema. Reading the following list, and determine the `Model` type
|
|
143
|
+
* considering the characteristics of the target LLM provider.
|
|
144
|
+
*
|
|
145
|
+
* - LLM provider schemas
|
|
146
|
+
*
|
|
147
|
+
* - `chatgpt`:
|
|
148
|
+
* [`IChatGptSchema`](https://samchon.github.io/openapi/api/types/IChatGptSchema-1.html)
|
|
149
|
+
* - `claude`:
|
|
150
|
+
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
151
|
+
* - `deepseek`:
|
|
152
|
+
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
153
|
+
* - `gemini`:
|
|
154
|
+
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
155
|
+
* - `llama`:
|
|
156
|
+
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
157
|
+
* - Middle layer schemas
|
|
158
|
+
*
|
|
159
|
+
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
160
|
+
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
161
|
+
*
|
|
162
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
163
|
+
* @template Class Target class or interface type collecting the functions to
|
|
164
|
+
* call
|
|
165
|
+
* @template Model LLM schema model
|
|
166
|
+
* @template Config Configuration of LLM schema composition
|
|
167
|
+
* @param name Identifier name of the controller
|
|
168
|
+
* @param execute Executor instance
|
|
169
|
+
* @param options Options for the LLM application construction
|
|
170
|
+
* @returns Controller of LLM function calling
|
|
171
|
+
* @reference https://wrtnlabs.io/agentica/docs/core/controller/typescript/
|
|
172
|
+
*/
|
|
173
|
+
export function controller<
|
|
174
|
+
Class extends Record<string, any>,
|
|
175
|
+
Model extends ILlmSchema.Model,
|
|
176
|
+
Config extends Partial<
|
|
177
|
+
ILlmSchema.ModelConfig[Model] & {
|
|
178
|
+
/**
|
|
179
|
+
* Whether to disallow superfluous properties or not.
|
|
180
|
+
*
|
|
181
|
+
* If configure as `true`, {@link validateEquals} function would be used
|
|
182
|
+
* for validation feedback, which is more strict than {@link validate}
|
|
183
|
+
* function.
|
|
184
|
+
*
|
|
185
|
+
* @default false
|
|
186
|
+
*/
|
|
187
|
+
equals: boolean;
|
|
188
|
+
}
|
|
189
|
+
> = {},
|
|
190
|
+
>(
|
|
191
|
+
name: string,
|
|
192
|
+
execute: Class,
|
|
193
|
+
options?: Partial<
|
|
194
|
+
Pick<ILlmApplication.IOptions<Model, Class>, "separate" | "validate">
|
|
195
|
+
>,
|
|
196
|
+
): ILlmController<Model>;
|
|
197
|
+
|
|
198
|
+
/** @internal */
|
|
199
|
+
export function controller(..._args: any[]): never {
|
|
200
|
+
NoTransformConfigurationError("llm.controller");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* > You must configure the generic argument `Class`.
|
|
205
|
+
*
|
|
206
|
+
* TypeScript functions to LLM function calling application.
|
|
207
|
+
*
|
|
208
|
+
* Creates an application of LLM (Large Language Model) function calling
|
|
209
|
+
* application from a TypeScript class or interface type containing the target
|
|
210
|
+
* functions to be called by the LLM function calling feature.
|
|
211
|
+
*
|
|
212
|
+
* If you put the returned {@link ILlmApplication.functions} objects to the LLM
|
|
213
|
+
* provider like [OpenAI (ChatGPT)](https://openai.com/), the LLM will
|
|
214
|
+
* automatically select the proper function and fill its arguments from the
|
|
215
|
+
* conversation (maybe chatting text) with user (human). This is the concept of
|
|
216
|
+
* the LLM function calling.
|
|
217
|
+
*
|
|
218
|
+
* By the way, there can be some parameters (or their nested properties) which
|
|
219
|
+
* must be composed by human, not by LLM. File uploading feature or some
|
|
220
|
+
* sensitive information like security keys (password) are the examples. In that
|
|
221
|
+
* case, you can separate the function parameters to both LLM and human sides by
|
|
222
|
+
* configuring the {@link ILlmApplication.IOptions.separate} property. The
|
|
223
|
+
* separated parameters are assigned to the {@link ILlmFunction.separated}
|
|
224
|
+
* property.
|
|
225
|
+
*
|
|
226
|
+
* For reference, the actual function call execution is not by LLM, but by you.
|
|
227
|
+
* When the LLM selects the proper function and fills the arguments, you just
|
|
228
|
+
* call the function with the LLM prepared arguments. And then informs the
|
|
229
|
+
* return value to the LLM by system prompt. The LLM will continue the next
|
|
230
|
+
* conversation based on the return value.
|
|
231
|
+
*
|
|
232
|
+
* Additionally, if you've configured {@link ILlmApplication.IOptions.separate},
|
|
233
|
+
* so that the parameters are separated to human and LLM sides, you can merge
|
|
234
|
+
* these human and LLM sides' parameters into one through
|
|
235
|
+
* {@link HttpLlm.mergeParameters} before the actual LLM function call
|
|
236
|
+
* execution.
|
|
237
|
+
*
|
|
238
|
+
* Here is the list of available `Model` types with their corresponding LLM
|
|
239
|
+
* schema. Reading the following list, and determine the `Model` type
|
|
240
|
+
* considering the characteristics of the target LLM provider.
|
|
241
|
+
*
|
|
242
|
+
* - LLM provider schemas
|
|
243
|
+
*
|
|
244
|
+
* - `chatgpt`:
|
|
245
|
+
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
246
|
+
* - `claude`:
|
|
247
|
+
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
248
|
+
* - `deepseek`:
|
|
249
|
+
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
250
|
+
* - `gemini`:
|
|
251
|
+
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
252
|
+
* - `llama`:
|
|
253
|
+
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
254
|
+
* - Middle layer schemas
|
|
255
|
+
*
|
|
256
|
+
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
257
|
+
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
258
|
+
*
|
|
259
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
260
|
+
* @template Class Target class or interface type collecting the functions to
|
|
261
|
+
* call
|
|
262
|
+
* @template Model LLM schema model
|
|
263
|
+
* @template Config Configuration of LLM schema composition
|
|
264
|
+
* @param options Options for the LLM application construction
|
|
265
|
+
* @returns Application of LLM function calling schemas
|
|
266
|
+
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
267
|
+
*/
|
|
268
|
+
export function application(
|
|
269
|
+
options?: Partial<
|
|
270
|
+
Pick<ILlmApplication.IOptions<any, any>, "separate" | "validate">
|
|
271
|
+
>,
|
|
272
|
+
): never;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* TypeScript functions to LLM function calling application.
|
|
276
|
+
*
|
|
277
|
+
* Creates an application of LLM (Large Language Model) function calling
|
|
278
|
+
* application from a TypeScript class or interface type containing the target
|
|
279
|
+
* functions to be called by the LLM function calling feature.
|
|
280
|
+
*
|
|
281
|
+
* If you put the returned {@link ILlmApplication.functions} objects to the LLM
|
|
282
|
+
* provider like [OpenAI (ChatGPT)](https://openai.com/), the LLM will
|
|
283
|
+
* automatically select the proper function and fill its arguments from the
|
|
284
|
+
* conversation (maybe chatting text) with user (human). This is the concept of
|
|
285
|
+
* the LLM function calling.
|
|
286
|
+
*
|
|
287
|
+
* By the way, there can be some parameters (or their nested properties) which
|
|
288
|
+
* must be composed by human, not by LLM. File uploading feature or some
|
|
289
|
+
* sensitive information like security keys (password) are the examples. In that
|
|
290
|
+
* case, you can separate the function parameters to both LLM and human sides by
|
|
291
|
+
* configuring the {@link ILlmApplication.IOptions.separate} property. The
|
|
292
|
+
* separated parameters are assigned to the {@link ILlmFunction.separated}
|
|
293
|
+
* property.
|
|
294
|
+
*
|
|
295
|
+
* For reference, the actual function call execution is not by LLM, but by you.
|
|
296
|
+
* When the LLM selects the proper function and fills the arguments, you just
|
|
297
|
+
* call the function with the LLM prepared arguments. And then informs the
|
|
298
|
+
* return value to the LLM by system prompt. The LLM will continue the next
|
|
299
|
+
* conversation based on the return value.
|
|
300
|
+
*
|
|
301
|
+
* Additionally, if you've configured {@link ILlmApplication.IOptions.separate},
|
|
302
|
+
* so that the parameters are separated to human and LLM sides, you can merge
|
|
303
|
+
* these human and LLM sides' parameters into one through
|
|
304
|
+
* {@link HttpLlm.mergeParameters} before the actual LLM function call
|
|
305
|
+
* execution.
|
|
306
|
+
*
|
|
307
|
+
* Here is the list of available `Model` types with their corresponding LLM
|
|
308
|
+
* schema. Reading the following list, and determine the `Model` type
|
|
309
|
+
* considering the characteristics of the target LLM provider.
|
|
310
|
+
*
|
|
311
|
+
* - LLM provider schemas
|
|
312
|
+
*
|
|
313
|
+
* - `chatgpt`:
|
|
314
|
+
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
315
|
+
* - `claude`:
|
|
316
|
+
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
317
|
+
* - `deepseek`:
|
|
318
|
+
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
319
|
+
* - `gemini`:
|
|
320
|
+
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
321
|
+
* - `llama`:
|
|
322
|
+
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
323
|
+
* - Middle layer schemas
|
|
324
|
+
*
|
|
325
|
+
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
326
|
+
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
327
|
+
*
|
|
328
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
329
|
+
* @template Class Target class or interface type collecting the functions to
|
|
330
|
+
* call
|
|
331
|
+
* @template Model LLM schema model
|
|
332
|
+
* @template Config Configuration of LLM schema composition
|
|
333
|
+
* @param options Options for the LLM application construction
|
|
334
|
+
* @returns Application of LLM function calling schemas
|
|
335
|
+
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
336
|
+
*/
|
|
337
|
+
export function application<
|
|
338
|
+
Class extends Record<string, any>,
|
|
339
|
+
Model extends ILlmSchema.Model,
|
|
340
|
+
Config extends Partial<
|
|
341
|
+
{
|
|
342
|
+
/**
|
|
343
|
+
* Whether to disallow superfluous properties or not.
|
|
344
|
+
*
|
|
345
|
+
* If configure as `true`, {@link validateEquals} function would be used
|
|
346
|
+
* for validation feedback, which is more strict than {@link validate}
|
|
347
|
+
* function.
|
|
348
|
+
*
|
|
349
|
+
* @default false
|
|
350
|
+
*/
|
|
351
|
+
equals: boolean;
|
|
352
|
+
} & ILlmSchema.ModelConfig[Model]
|
|
353
|
+
> = {},
|
|
354
|
+
>(
|
|
355
|
+
options?: Partial<
|
|
356
|
+
Pick<ILlmApplication.IOptions<Model, Class>, "separate" | "validate">
|
|
357
|
+
>,
|
|
358
|
+
): ILlmApplication<Model, Class>;
|
|
359
|
+
|
|
360
|
+
/** @internal */
|
|
361
|
+
export function application(): never {
|
|
362
|
+
NoTransformConfigurationError("llm.application");
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* > You must configure the generic argument `Parameters`.
|
|
367
|
+
*
|
|
368
|
+
* TypeScript parameters to LLM parameters schema.
|
|
369
|
+
*
|
|
370
|
+
* Creates an LLM (Large Language Model) parameters schema, a type metadata that
|
|
371
|
+
* is used in the [LLM function
|
|
372
|
+
* calling](https://platform.openai.com/docs/guides/function-calling) and [LLM
|
|
373
|
+
* structured
|
|
374
|
+
* outputs](https://platform.openai.com/docs/guides/structured-outputs), from a
|
|
375
|
+
* TypeScript parameters type.
|
|
376
|
+
*
|
|
377
|
+
* For references, LLM identifies only keyworded arguments, not positional
|
|
378
|
+
* arguments. Therefore, the TypeScript parameters type must be an object type,
|
|
379
|
+
* and its properties must be static. If dynamic properties are, it will be
|
|
380
|
+
* compilation error.
|
|
381
|
+
*
|
|
382
|
+
* Also, such parameters type can be utilized not only for the LLM function
|
|
383
|
+
* calling, but also for the LLM structured outputs. The LLM structured outputs
|
|
384
|
+
* is a feature that LLM (Large Language Model) can generate a structured
|
|
385
|
+
* output, not only a plain text, by filling the parameters from the
|
|
386
|
+
* conversation (maybe chatting text) with user (human).
|
|
387
|
+
*
|
|
388
|
+
* Here is the list of available `Model` types with their corresponding LLM
|
|
389
|
+
* schema. Reading the following list, and determine the `Model` type
|
|
390
|
+
* considering the characteristics of the target LLM provider.
|
|
391
|
+
*
|
|
392
|
+
* - LLM provider schemas
|
|
393
|
+
*
|
|
394
|
+
* - `chatgpt`:
|
|
395
|
+
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
396
|
+
* - `claude`:
|
|
397
|
+
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
398
|
+
* - `deepseek`:
|
|
399
|
+
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
400
|
+
* - `gemini`:
|
|
401
|
+
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
402
|
+
* - `llama`:
|
|
403
|
+
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
404
|
+
* - Middle layer schemas
|
|
405
|
+
*
|
|
406
|
+
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
407
|
+
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
408
|
+
*
|
|
409
|
+
* @template Parameters Target parameters type
|
|
410
|
+
* @template Model LLM schema model
|
|
411
|
+
* @template Config Configuration of LLM schema composition
|
|
412
|
+
* @returns LLM parameters schema
|
|
413
|
+
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
414
|
+
* @reference https://platform.openai.com/docs/guides/structured-outputs
|
|
415
|
+
*/
|
|
416
|
+
export function parameters(): never;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* TypeScript parameters to LLM parameters schema.
|
|
420
|
+
*
|
|
421
|
+
* Creates an LLM (Large Language Model) parameters schema, a type metadata that
|
|
422
|
+
* is used in the [LLM function
|
|
423
|
+
* calling](https://platform.openai.com/docs/guides/function-calling) and [LLM
|
|
424
|
+
* structured
|
|
425
|
+
* outputs](https://platform.openai.com/docs/guides/structured-outputs), from a
|
|
426
|
+
* TypeScript parameters type.
|
|
427
|
+
*
|
|
428
|
+
* For references, LLM identifies only keyworded arguments, not positional
|
|
429
|
+
* arguments. Therefore, the TypeScript parameters type must be an object type,
|
|
430
|
+
* and its properties must be static. If dynamic properties are, it will be
|
|
431
|
+
* compilation error.
|
|
432
|
+
*
|
|
433
|
+
* Also, such parameters type can be utilized not only for the LLM function
|
|
434
|
+
* calling, but also for the LLM structured outputs. The LLM structured outputs
|
|
435
|
+
* is a feature that LLM (Large Language Model) can generate a structured
|
|
436
|
+
* output, not only a plain text, by filling the parameters from the
|
|
437
|
+
* conversation (maybe chatting text) with user (human).
|
|
438
|
+
*
|
|
439
|
+
* Here is the list of available `Model` types with their corresponding LLM
|
|
440
|
+
* schema. Reading the following list, and determine the `Model` type
|
|
441
|
+
* considering the characteristics of the target LLM provider.
|
|
442
|
+
*
|
|
443
|
+
* - LLM provider schemas
|
|
444
|
+
*
|
|
445
|
+
* - `chatgpt`:
|
|
446
|
+
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
447
|
+
* - `claude`:
|
|
448
|
+
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
449
|
+
* - `deepseek`:
|
|
450
|
+
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
451
|
+
* - `gemini`:
|
|
452
|
+
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
453
|
+
* - `llama`:
|
|
454
|
+
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
455
|
+
* - Middle layer schemas
|
|
456
|
+
*
|
|
457
|
+
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
458
|
+
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
459
|
+
*
|
|
460
|
+
* @template Parameters Target parameters type
|
|
461
|
+
* @template Model LLM schema model
|
|
462
|
+
* @template Config Configuration of LLM schema composition
|
|
463
|
+
* @returns LLM parameters schema
|
|
464
|
+
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
465
|
+
* @reference https://platform.openai.com/docs/guides/structured-outputs
|
|
466
|
+
*/
|
|
467
|
+
export function parameters<
|
|
468
|
+
Parameters extends Record<string, any>,
|
|
469
|
+
Model extends ILlmSchema.Model,
|
|
470
|
+
Config extends Partial<ILlmSchema.ModelConfig[Model]> = {},
|
|
471
|
+
>(): ILlmSchema.ModelParameters[Model];
|
|
472
|
+
|
|
473
|
+
/** @internal */
|
|
474
|
+
export function parameters(): never {
|
|
475
|
+
NoTransformConfigurationError("llm.parameters");
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* > You must configure the generic argument `T`.
|
|
480
|
+
*
|
|
481
|
+
* TypeScript type to LLM type schema.
|
|
482
|
+
*
|
|
483
|
+
* Creates an LLM (Large Language Model) type schema, a type metadata that is
|
|
484
|
+
* used in the [LLM function calling](@reference
|
|
485
|
+
* https://platform.openai.com/docs/guides/function-calling), from a TypeScript
|
|
486
|
+
* type.
|
|
487
|
+
*
|
|
488
|
+
* The returned {@link ILlmSchema} type will be specified by the `Model`
|
|
489
|
+
* argument, and here is the list of available `Model` types with their
|
|
490
|
+
* corresponding LLM schema. Reading the following list, and determine the
|
|
491
|
+
* `Model` type considering the characteristics of the target LLM provider.
|
|
492
|
+
*
|
|
493
|
+
* - LLM provider schemas
|
|
494
|
+
*
|
|
495
|
+
* - `chatgpt`:
|
|
496
|
+
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
497
|
+
* - `claude`:
|
|
498
|
+
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
499
|
+
* - `deepseek`:
|
|
500
|
+
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
501
|
+
* - `gemini`:
|
|
502
|
+
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
503
|
+
* - `llama`:
|
|
504
|
+
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
505
|
+
* - Middle layer schemas
|
|
506
|
+
*
|
|
507
|
+
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
508
|
+
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
509
|
+
*
|
|
510
|
+
* If you actually want to perform the LLM function calling with TypeScript
|
|
511
|
+
* functions, you can do it with the {@link application} function. Otherwise you
|
|
512
|
+
* hope to perform the structured output, {@link parameters} function is better.
|
|
513
|
+
* Let's enjoy the LLM function calling and structured output with the native
|
|
514
|
+
* TypeScript functions and types.
|
|
515
|
+
*
|
|
516
|
+
* > **What LLM function calling is?
|
|
517
|
+
*
|
|
518
|
+
* > LLM (Large Language Model) selects property function and fill the arguments,
|
|
519
|
+
* > but actual function call execution is not by LLM, but by you.
|
|
520
|
+
*
|
|
521
|
+
* > In nowadays, most LLM (Large Language Model) like OpenAI are supporting
|
|
522
|
+
* > "function calling" feature. The "function calling" means that LLM
|
|
523
|
+
* > automatically selects a proper function and compose parameter values from the
|
|
524
|
+
* > user's chatting text.
|
|
525
|
+
*
|
|
526
|
+
* > When LLM selects the proper function and its arguments, you just call the
|
|
527
|
+
* > function with the arguments. And then informs the return value to the LLM by
|
|
528
|
+
* > system prompt, LLM will continue the next conversation based on the return
|
|
529
|
+
* > value.
|
|
530
|
+
*
|
|
531
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
532
|
+
* @template T Target type
|
|
533
|
+
* @template Model LLM schema model
|
|
534
|
+
* @template Config Configuration of LLM schema composition
|
|
535
|
+
* @returns LLM schema
|
|
536
|
+
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
537
|
+
* @reference https://platform.openai.com/docs/guides/structured-outputs
|
|
538
|
+
*/
|
|
539
|
+
export function schema(): never;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* TypeScript type to LLM type schema.
|
|
543
|
+
*
|
|
544
|
+
* Creates an LLM (Large Language Model) type schema, a type metadata that is
|
|
545
|
+
* used in the [LLM function calling](@reference
|
|
546
|
+
* https://platform.openai.com/docs/guides/function-calling), from a TypeScript
|
|
547
|
+
* type.
|
|
548
|
+
*
|
|
549
|
+
* The returned {@link ILlmSchema} type will be specified by the `Model`
|
|
550
|
+
* argument, and here is the list of available `Model` types with their
|
|
551
|
+
* corresponding LLM schema:
|
|
552
|
+
*
|
|
553
|
+
* - LLM provider schemas
|
|
554
|
+
*
|
|
555
|
+
* - `chatgpt`:
|
|
556
|
+
* [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
|
|
557
|
+
* - `claude`:
|
|
558
|
+
* [`IClaudeSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
559
|
+
* - `deepseek`:
|
|
560
|
+
* [`IDeepSeekSchema`](https://samchon.github.io/openapi/api/types/IClaudeSchema-1.html)
|
|
561
|
+
* - `gemini`:
|
|
562
|
+
* [`IGeminiSchema`](https://samchon.github.io/openapi/api/types/IGeminiSchema-1.html)
|
|
563
|
+
* - `llama`:
|
|
564
|
+
* [`ILlamaSchema`](https://samchon.github.io/openapi/api/types/ILlamaSchema-1.html)
|
|
565
|
+
* - Middle layer schemas
|
|
566
|
+
*
|
|
567
|
+
* - `3.0`: [`ILlmSchemaV3`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3-1.html)
|
|
568
|
+
* - `3.1`: [`ILlmSchemaV3_1`](https://samchon.github.io/openapi/api/types/ILlmSchemaV3_1-1.html)
|
|
569
|
+
*
|
|
570
|
+
* If you actually want to perform the LLM function calling with TypeScript
|
|
571
|
+
* functions, you can do it with the {@link application} function. Otherwise you
|
|
572
|
+
* hope to perform the structured output, {@link parameters} function is better.
|
|
573
|
+
* Let's enjoy the LLM function calling and structured output with the native
|
|
574
|
+
* TypeScript functions and types.
|
|
575
|
+
*
|
|
576
|
+
* > **What LLM function calling is?
|
|
577
|
+
*
|
|
578
|
+
* > LLM (Large Language Model) selects property function and fill the arguments,
|
|
579
|
+
* > but actual function call execution is not by LLM, but by you.
|
|
580
|
+
*
|
|
581
|
+
* > In nowadays, most LLM (Large Language Model) like OpenAI are supporting
|
|
582
|
+
* > "function calling" feature. The "function calling" means that LLM
|
|
583
|
+
* > automatically selects a proper function and compose parameter values from the
|
|
584
|
+
* > user's chatting text.
|
|
585
|
+
*
|
|
586
|
+
* > When LLM selects the proper function and its arguments, you just call the
|
|
587
|
+
* > function with the arguments. And then informs the return value to the LLM by
|
|
588
|
+
* > system prompt, LLM will continue the next conversation based on the return
|
|
589
|
+
* > value.
|
|
590
|
+
*
|
|
591
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
592
|
+
* @template T Target type
|
|
593
|
+
* @template Model LLM schema model
|
|
594
|
+
* @template Config Configuration of LLM schema composition
|
|
595
|
+
* @returns LLM schema
|
|
596
|
+
* @reference https://platform.openai.com/docs/guides/function-calling
|
|
597
|
+
* @reference https://platform.openai.com/docs/guides/structured-outputs
|
|
598
|
+
*/
|
|
599
|
+
export function schema<
|
|
600
|
+
T,
|
|
601
|
+
Model extends ILlmSchema.Model,
|
|
602
|
+
Config extends Partial<ILlmSchema.ModelConfig[Model]> = {},
|
|
603
|
+
>(
|
|
604
|
+
...$defs: Extract<
|
|
605
|
+
ILlmSchema.ModelSchema[Model],
|
|
606
|
+
{ $ref: string }
|
|
607
|
+
> extends never
|
|
608
|
+
? []
|
|
609
|
+
: [Record<string, ILlmSchema.ModelSchema[Model]>]
|
|
610
|
+
): ILlmSchema.ModelSchema[Model];
|
|
611
|
+
|
|
612
|
+
/** @internal */
|
|
613
|
+
export function schema(): never {
|
|
614
|
+
NoTransformConfigurationError("llm.schema");
|
|
615
|
+
}
|