typia 7.0.0-dev.20241115 → 7.0.0-dev.20241122
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 +3 -3
- package/lib/executable/TypiaSetupWizard.js +1 -1
- package/lib/executable/TypiaSetupWizard.js.map +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/internal/_llmApplicationFinalize.d.ts +1 -1
- package/lib/internal/_llmApplicationFinalize.js +14 -6
- package/lib/internal/_llmApplicationFinalize.js.map +1 -1
- package/lib/llm.d.ts +4 -3
- package/lib/programmers/llm/LlmApplicationProgrammer.js +149 -104
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.d.ts +7 -2
- package/lib/programmers/llm/LlmSchemaProgrammer.js +40 -12
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
- package/lib/transformers/features/llm/LlmSchemaTransformer.js +13 -2
- package/lib/transformers/features/llm/LlmSchemaTransformer.js.map +1 -1
- package/package.json +37 -36
- package/src/executable/TypiaSetupWizard.ts +1 -1
- package/src/internal/_llmApplicationFinalize.ts +25 -6
- package/src/llm.ts +6 -6
- package/src/programmers/llm/LlmApplicationProgrammer.ts +175 -155
- package/src/programmers/llm/LlmSchemaProgrammer.ts +80 -17
- package/src/transformers/features/llm/LlmSchemaTransformer.ts +40 -6
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { ILlmApplication } from "@samchon/openapi";
|
|
1
|
+
import { IChatGptSchema, ILlmApplication, OpenApi } from "@samchon/openapi";
|
|
2
|
+
import { ChatGptConverter } from "@samchon/openapi/lib/converters/ChatGptConverter";
|
|
3
|
+
import { GeminiConverter } from "@samchon/openapi/lib/converters/GeminiConverter";
|
|
4
|
+
import { LlmConverterV3 } from "@samchon/openapi/lib/converters/LlmConverterV3";
|
|
5
|
+
import { LlmConverterV3_1 } from "@samchon/openapi/lib/converters/LlmConverterV3_1";
|
|
2
6
|
import { ILlmFunction } from "@samchon/openapi/lib/structures/ILlmFunction";
|
|
3
7
|
|
|
4
8
|
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
5
9
|
|
|
6
|
-
import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
|
|
7
10
|
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
8
11
|
import { MetadataFunction } from "../../schemas/metadata/MetadataFunction";
|
|
9
12
|
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
|
|
10
13
|
|
|
14
|
+
import { IJsonApplication } from "../../module";
|
|
15
|
+
import { JsonApplicationProgrammer } from "../json/JsonApplicationProgrammer";
|
|
11
16
|
import { LlmSchemaProgrammer } from "./LlmSchemaProgrammer";
|
|
12
17
|
|
|
13
18
|
export namespace LlmApplicationProgrammer {
|
|
@@ -101,175 +106,190 @@ export namespace LlmApplicationProgrammer {
|
|
|
101
106
|
if (errors.length)
|
|
102
107
|
throw new Error("Failed to write LLM application: " + errors.join("\n"));
|
|
103
108
|
|
|
104
|
-
const
|
|
109
|
+
const application: IJsonApplication<"3.1"> =
|
|
110
|
+
JsonApplicationProgrammer.write({
|
|
111
|
+
version: "3.1",
|
|
112
|
+
metadata: props.metadata,
|
|
113
|
+
});
|
|
105
114
|
return {
|
|
106
115
|
model: props.model,
|
|
107
|
-
functions:
|
|
108
|
-
|
|
109
|
-
(p) =>
|
|
110
|
-
p.value.functions.length === 1 &&
|
|
111
|
-
p.value.size() === 1 &&
|
|
112
|
-
p.key.isSoleLiteral(),
|
|
113
|
-
)
|
|
114
|
-
.filter(
|
|
115
|
-
(p) => p.jsDocTags.find((tag) => tag.name === "hidden") === undefined,
|
|
116
|
-
)
|
|
117
|
-
.map((p) =>
|
|
118
|
-
writeFunction({
|
|
119
|
-
model: props.model,
|
|
120
|
-
name: p.key.getSoleLiteral()!,
|
|
121
|
-
function: p.value.functions[0]!,
|
|
122
|
-
description: p.description,
|
|
123
|
-
jsDocTags: p.jsDocTags,
|
|
124
|
-
}),
|
|
125
|
-
),
|
|
126
|
-
options: {
|
|
127
|
-
separate: null,
|
|
128
|
-
recursive: props.model === "chatgpt" ? undefined : (3 as any),
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const writeFunction = <Model extends ILlmApplication.Model>(props: {
|
|
134
|
-
model: Model;
|
|
135
|
-
name: string;
|
|
136
|
-
function: MetadataFunction;
|
|
137
|
-
description: string | null;
|
|
138
|
-
jsDocTags: IJsDocTagInfo[];
|
|
139
|
-
}): ILlmFunction<ILlmApplication.ModelSchema[Model]> => {
|
|
140
|
-
const deprecated: boolean = props.jsDocTags.some(
|
|
141
|
-
(tag) => tag.name === "deprecated",
|
|
142
|
-
);
|
|
143
|
-
const tags: string[] = props.jsDocTags
|
|
144
|
-
.map((tag) =>
|
|
145
|
-
tag.name === "tag"
|
|
146
|
-
? (tag.text?.filter((elem) => elem.kind === "text") ?? [])
|
|
147
|
-
: [],
|
|
148
|
-
)
|
|
149
|
-
.flat()
|
|
150
|
-
.map((elem) => elem.text)
|
|
151
|
-
.map((str) => str.trim().split(" ")[0] ?? "")
|
|
152
|
-
.filter((str) => !!str.length);
|
|
153
|
-
return {
|
|
154
|
-
name: props.name,
|
|
155
|
-
parameters: props.function.parameters.map((p) => {
|
|
156
|
-
const jsDocTagDescription: string | null = writeDescriptionFromJsDocTag(
|
|
157
|
-
{
|
|
158
|
-
jsDocTags: p.jsDocTags,
|
|
159
|
-
name: "param",
|
|
160
|
-
parameter: p.name,
|
|
161
|
-
},
|
|
162
|
-
);
|
|
163
|
-
return writeSchema({
|
|
116
|
+
functions: application.functions.map((func) =>
|
|
117
|
+
writeFunction({
|
|
164
118
|
model: props.model,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
jsDocTags: props.jsDocTags,
|
|
182
|
-
name: "returns",
|
|
183
|
-
}),
|
|
184
|
-
jsDocTags: [],
|
|
185
|
-
})
|
|
186
|
-
: undefined,
|
|
187
|
-
description: props.description ?? undefined,
|
|
188
|
-
deprecated: deprecated || undefined,
|
|
189
|
-
tags: tags.length ? tags : undefined,
|
|
119
|
+
components: application.components,
|
|
120
|
+
function: func,
|
|
121
|
+
}),
|
|
122
|
+
),
|
|
123
|
+
options: (props.model === "chatgpt"
|
|
124
|
+
? ({
|
|
125
|
+
separate: null,
|
|
126
|
+
reference: false,
|
|
127
|
+
constraint: false,
|
|
128
|
+
} satisfies ILlmApplication.IOptions<"chatgpt">)
|
|
129
|
+
: ({
|
|
130
|
+
separate: null,
|
|
131
|
+
recursive: props.model === "chatgpt" ? undefined : (3 as any),
|
|
132
|
+
} satisfies ILlmApplication.ICommonOptions<
|
|
133
|
+
Exclude<Model, "chatgpt">
|
|
134
|
+
>)) as ILlmApplication.IOptions<Model>,
|
|
190
135
|
};
|
|
191
136
|
};
|
|
192
137
|
|
|
193
|
-
const
|
|
138
|
+
const writeFunction = <Model extends ILlmApplication.Model>(props: {
|
|
194
139
|
model: Model;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const explicit: Pick<
|
|
202
|
-
ILlmApplication.ModelSchema[Model],
|
|
203
|
-
"title" | "description"
|
|
204
|
-
> = writeDescription({
|
|
140
|
+
components: OpenApi.IComponents;
|
|
141
|
+
function: IJsonApplication.IFunction<OpenApi.IJsonSchema>;
|
|
142
|
+
}): ILlmFunction<ILlmApplication.ModelParameters[Model]> => {
|
|
143
|
+
const parameters: ILlmApplication.ModelParameters[Model] =
|
|
144
|
+
writeParameters(props);
|
|
145
|
+
const output: ILlmApplication.ModelSchema[Model] | null = writeOutput({
|
|
205
146
|
model: props.model,
|
|
206
|
-
|
|
207
|
-
|
|
147
|
+
parameters,
|
|
148
|
+
components: props.components,
|
|
149
|
+
schema: props.function.output?.schema ?? null,
|
|
208
150
|
});
|
|
151
|
+
if (
|
|
152
|
+
output &&
|
|
153
|
+
output.description === undefined &&
|
|
154
|
+
!!props.function.output?.description?.length
|
|
155
|
+
)
|
|
156
|
+
output.description = props.function.output.description;
|
|
209
157
|
return {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
158
|
+
name: props.function.name,
|
|
159
|
+
parameters,
|
|
160
|
+
output: (output ?? undefined) as
|
|
161
|
+
| ILlmApplication.ModelParameters[Model]["properties"][string]
|
|
162
|
+
| undefined,
|
|
163
|
+
description: (() => {
|
|
164
|
+
if (
|
|
165
|
+
!props.function.summary?.length ||
|
|
166
|
+
!props.function.description?.length
|
|
167
|
+
)
|
|
168
|
+
return props.function.summary || props.function.description;
|
|
169
|
+
const summary: string = props.function.summary.endsWith(".")
|
|
170
|
+
? props.function.summary.slice(0, -1)
|
|
171
|
+
: props.function.summary;
|
|
172
|
+
return props.function.description.startsWith(summary)
|
|
173
|
+
? props.function.description
|
|
174
|
+
: summary + ".\n\n" + props.function.description;
|
|
175
|
+
})(),
|
|
176
|
+
deprecated: props.function.deprecated,
|
|
177
|
+
tags: props.function.tags,
|
|
178
|
+
strict: true,
|
|
214
179
|
};
|
|
215
180
|
};
|
|
216
181
|
|
|
217
|
-
const
|
|
182
|
+
const writeParameters = <Model extends ILlmApplication.Model>(props: {
|
|
218
183
|
model: Model;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}):
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
)
|
|
234
|
-
|
|
184
|
+
components: OpenApi.IComponents;
|
|
185
|
+
function: IJsonApplication.IFunction<OpenApi.IJsonSchema>;
|
|
186
|
+
}): ILlmApplication.ModelParameters[Model] => {
|
|
187
|
+
const schema: OpenApi.IJsonSchema.IObject = {
|
|
188
|
+
type: "object",
|
|
189
|
+
properties: Object.fromEntries(
|
|
190
|
+
props.function.parameters.map((p) => [
|
|
191
|
+
p.name,
|
|
192
|
+
{
|
|
193
|
+
...p.schema,
|
|
194
|
+
title: p.title ?? p.schema.title,
|
|
195
|
+
description: p.description ?? p.schema.description,
|
|
196
|
+
},
|
|
197
|
+
]),
|
|
198
|
+
),
|
|
199
|
+
required: props.function.parameters
|
|
200
|
+
.filter((p) => p.required)
|
|
201
|
+
.map((p) => p.name),
|
|
202
|
+
additionalProperties: false,
|
|
203
|
+
};
|
|
204
|
+
const parameters: ILlmApplication.ModelParameters[Model] | null = (() => {
|
|
205
|
+
if (props.model === "chatgpt")
|
|
206
|
+
return ChatGptConverter.parameters({
|
|
207
|
+
options: DEFAULT_CHATGPT_OPTION,
|
|
208
|
+
components: props.components,
|
|
209
|
+
schema,
|
|
210
|
+
});
|
|
211
|
+
else if (props.model === "gemini")
|
|
212
|
+
return GeminiConverter.parameters({
|
|
213
|
+
recursive: DEFAULT_V3_OPTIONS.recursive,
|
|
214
|
+
components: props.components,
|
|
215
|
+
schema,
|
|
216
|
+
}) as ILlmApplication.ModelParameters[Model] | null;
|
|
217
|
+
else if (props.model === "3.0")
|
|
218
|
+
return LlmConverterV3.parameters({
|
|
219
|
+
recursive: DEFAULT_V3_OPTIONS.recursive,
|
|
220
|
+
components: props.components,
|
|
221
|
+
schema,
|
|
222
|
+
}) as ILlmApplication.ModelParameters[Model] | null;
|
|
223
|
+
else if (props.model === "3.1")
|
|
224
|
+
return LlmConverterV3_1.parameters({
|
|
225
|
+
recursive: DEFAULT_V3_OPTIONS.recursive,
|
|
226
|
+
components: props.components,
|
|
227
|
+
schema,
|
|
228
|
+
}) as ILlmApplication.ModelParameters[Model] | null;
|
|
229
|
+
else return null;
|
|
235
230
|
})();
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
} as any;
|
|
231
|
+
if (parameters === null)
|
|
232
|
+
throw new Error("Failed to write LLM application parameters.");
|
|
233
|
+
return parameters;
|
|
240
234
|
};
|
|
241
235
|
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
236
|
+
const writeOutput = <Model extends ILlmApplication.Model>(props: {
|
|
237
|
+
model: Model;
|
|
238
|
+
parameters: ILlmApplication.ModelParameters[Model];
|
|
239
|
+
components: OpenApi.IComponents;
|
|
240
|
+
schema: OpenApi.IJsonSchema | null;
|
|
241
|
+
}): ILlmApplication.ModelSchema[Model] | null => {
|
|
242
|
+
if (props.schema === null) return null;
|
|
243
|
+
const output: ILlmApplication.ModelSchema[Model] | null = (() => {
|
|
244
|
+
if (props.model === "chatgpt") {
|
|
245
|
+
const $defs =
|
|
246
|
+
(props.parameters as IChatGptSchema.IParameters).$defs ?? {};
|
|
247
|
+
const output: IChatGptSchema | null = ChatGptConverter.schema({
|
|
248
|
+
options: DEFAULT_CHATGPT_OPTION,
|
|
249
|
+
components: props.components,
|
|
250
|
+
$defs,
|
|
251
|
+
schema: props.schema,
|
|
252
|
+
});
|
|
253
|
+
if (
|
|
254
|
+
output !== null &&
|
|
255
|
+
(props.parameters as IChatGptSchema.IParameters).$defs ===
|
|
256
|
+
undefined &&
|
|
257
|
+
Object.keys($defs).length !== 0
|
|
258
|
+
)
|
|
259
|
+
(props.parameters as IChatGptSchema.IParameters).$defs = $defs;
|
|
260
|
+
return output;
|
|
261
|
+
} else if (props.model === "gemini")
|
|
262
|
+
return GeminiConverter.schema({
|
|
263
|
+
recursive: DEFAULT_V3_OPTIONS.recursive,
|
|
264
|
+
components: props.components,
|
|
265
|
+
schema: props.schema,
|
|
266
|
+
}) as ILlmApplication.ModelSchema[Model] | null;
|
|
267
|
+
else if (props.model === "3.0")
|
|
268
|
+
return LlmConverterV3.schema({
|
|
269
|
+
recursive: DEFAULT_V3_OPTIONS.recursive,
|
|
270
|
+
components: props.components,
|
|
271
|
+
schema: props.schema,
|
|
272
|
+
}) as ILlmApplication.ModelSchema[Model] | null;
|
|
273
|
+
else if (props.model === "3.1")
|
|
274
|
+
return LlmConverterV3_1.schema({
|
|
275
|
+
recursive: DEFAULT_V3_OPTIONS.recursive,
|
|
276
|
+
components: props.components,
|
|
277
|
+
schema: props.schema,
|
|
278
|
+
}) as ILlmApplication.ModelSchema[Model] | null;
|
|
279
|
+
else return null;
|
|
280
|
+
})();
|
|
281
|
+
if (output === null)
|
|
282
|
+
throw new Error("Failed to write LLM application output.");
|
|
283
|
+
return output;
|
|
260
284
|
};
|
|
261
|
-
|
|
262
|
-
const getJsDocTexts = (props: {
|
|
263
|
-
jsDocTags: IJsDocTagInfo[];
|
|
264
|
-
name: string;
|
|
265
|
-
}): string[] =>
|
|
266
|
-
props.jsDocTags
|
|
267
|
-
.filter(
|
|
268
|
-
(tag) =>
|
|
269
|
-
tag.name === props.name &&
|
|
270
|
-
tag.text &&
|
|
271
|
-
tag.text.find((elem) => elem.kind === "text" && elem.text.length) !==
|
|
272
|
-
undefined,
|
|
273
|
-
)
|
|
274
|
-
.map((tag) => tag.text!.find((elem) => elem.kind === "text")!.text);
|
|
275
285
|
}
|
|
286
|
+
|
|
287
|
+
const DEFAULT_CHATGPT_OPTION: ILlmApplication.IChatGptOptions = {
|
|
288
|
+
separate: null,
|
|
289
|
+
reference: false,
|
|
290
|
+
constraint: false,
|
|
291
|
+
};
|
|
292
|
+
const DEFAULT_V3_OPTIONS = {
|
|
293
|
+
separate: null,
|
|
294
|
+
recursive: 3,
|
|
295
|
+
} satisfies ILlmApplication.ICommonOptions<"3.0">;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
IChatGptSchema,
|
|
3
|
+
IHttpLlmApplication,
|
|
4
|
+
ILlmApplication,
|
|
5
|
+
OpenApi,
|
|
6
|
+
} from "@samchon/openapi";
|
|
7
|
+
import { ChatGptConverter } from "@samchon/openapi/lib/converters/ChatGptConverter";
|
|
8
|
+
import { GeminiConverter } from "@samchon/openapi/lib/converters/GeminiConverter";
|
|
9
|
+
import { LlmConverterV3 } from "@samchon/openapi/lib/converters/LlmConverterV3";
|
|
10
|
+
import { LlmConverterV3_1 } from "@samchon/openapi/lib/converters/LlmConverterV3_1";
|
|
3
11
|
|
|
4
12
|
import { IJsonSchemaCollection } from "../../schemas/json/IJsonSchemaCollection";
|
|
5
13
|
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
@@ -13,25 +21,42 @@ import { json_schema_string } from "../internal/json_schema_string";
|
|
|
13
21
|
import { JsonSchemasProgrammer } from "../json/JsonSchemasProgrammer";
|
|
14
22
|
|
|
15
23
|
export namespace LlmSchemaProgrammer {
|
|
24
|
+
export interface IOutput<Model extends ILlmApplication.Model> {
|
|
25
|
+
model: Model;
|
|
26
|
+
schema: ILlmApplication.ModelSchema[Model];
|
|
27
|
+
$defs: Record<string, IChatGptSchema>;
|
|
28
|
+
}
|
|
16
29
|
export const write = <Model extends ILlmApplication.Model>(props: {
|
|
17
30
|
model: Model;
|
|
18
31
|
metadata: Metadata;
|
|
19
|
-
}):
|
|
32
|
+
}): IOutput<Model> => {
|
|
20
33
|
const collection: IJsonSchemaCollection<"3.1"> =
|
|
21
34
|
JsonSchemasProgrammer.write({
|
|
22
35
|
version: "3.1",
|
|
23
36
|
metadatas: [props.metadata],
|
|
24
37
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
|
|
39
|
+
const $defs: Record<string, IChatGptSchema> = {};
|
|
40
|
+
const schema: ILlmApplication.ModelSchema[Model] | null = CASTERS[
|
|
41
|
+
props.model
|
|
42
|
+
]({
|
|
43
|
+
options: {
|
|
30
44
|
recursive: 3,
|
|
31
|
-
|
|
45
|
+
reference: false,
|
|
46
|
+
constraint: false,
|
|
47
|
+
} satisfies Omit<ILlmApplication.IChatGptOptions, "separate"> &
|
|
48
|
+
Omit<ILlmApplication.ICommonOptions<any>, "separate"> as any,
|
|
49
|
+
components: collection.components,
|
|
50
|
+
schema: collection.schemas[0]!,
|
|
51
|
+
$defs,
|
|
52
|
+
}) as ILlmApplication.ModelSchema[Model] | null;
|
|
32
53
|
if (schema === null)
|
|
33
54
|
throw new Error("Failed to convert JSON schema to LLM schema.");
|
|
34
|
-
return
|
|
55
|
+
return {
|
|
56
|
+
model: props.model,
|
|
57
|
+
$defs,
|
|
58
|
+
schema,
|
|
59
|
+
};
|
|
35
60
|
};
|
|
36
61
|
|
|
37
62
|
export const validate =
|
|
@@ -64,13 +89,6 @@ export namespace LlmSchemaProgrammer {
|
|
|
64
89
|
output.push(`LLM schema does not support ${native.name} type.`);
|
|
65
90
|
if (model === "gemini" && size(metadata) > 1)
|
|
66
91
|
output.push("Gemini model does not support the union type.");
|
|
67
|
-
// if (
|
|
68
|
-
// metadata.aliases.some((a) => a.type.recursive) ||
|
|
69
|
-
// metadata.arrays.some((a) => a.type.recursive) ||
|
|
70
|
-
// metadata.objects.some((o) => o.type.recursive) ||
|
|
71
|
-
// metadata.tuples.some((t) => t.type.recursive)
|
|
72
|
-
// )
|
|
73
|
-
// output.push("LLM schema does not support recursive type.");
|
|
74
92
|
return output;
|
|
75
93
|
};
|
|
76
94
|
}
|
|
@@ -112,3 +130,48 @@ const size = (metadata: Metadata): number =>
|
|
|
112
130
|
}).length,
|
|
113
131
|
)
|
|
114
132
|
.reduce((a, b) => a + b, 0);
|
|
133
|
+
|
|
134
|
+
const CASTERS = {
|
|
135
|
+
"3.0": (props: {
|
|
136
|
+
components: OpenApi.IComponents;
|
|
137
|
+
schema: OpenApi.IJsonSchema;
|
|
138
|
+
options: IHttpLlmApplication.IOptions<"3.0">;
|
|
139
|
+
}) =>
|
|
140
|
+
LlmConverterV3.schema({
|
|
141
|
+
components: props.components,
|
|
142
|
+
schema: props.schema,
|
|
143
|
+
recursive: props.options.recursive,
|
|
144
|
+
}),
|
|
145
|
+
"3.1": (props: {
|
|
146
|
+
components: OpenApi.IComponents;
|
|
147
|
+
schema: OpenApi.IJsonSchema;
|
|
148
|
+
options: IHttpLlmApplication.IOptions<"3.1">;
|
|
149
|
+
}) =>
|
|
150
|
+
LlmConverterV3_1.schema({
|
|
151
|
+
components: props.components,
|
|
152
|
+
schema: props.schema,
|
|
153
|
+
recursive: props.options.recursive,
|
|
154
|
+
}),
|
|
155
|
+
chatgpt: (props: {
|
|
156
|
+
components: OpenApi.IComponents;
|
|
157
|
+
schema: OpenApi.IJsonSchema;
|
|
158
|
+
$defs: Record<string, IChatGptSchema>;
|
|
159
|
+
options: Omit<IHttpLlmApplication.IChatGptOptions, "separate">;
|
|
160
|
+
}) =>
|
|
161
|
+
ChatGptConverter.schema({
|
|
162
|
+
components: props.components,
|
|
163
|
+
schema: props.schema,
|
|
164
|
+
$defs: props.$defs,
|
|
165
|
+
options: props.options,
|
|
166
|
+
}),
|
|
167
|
+
gemini: (props: {
|
|
168
|
+
components: OpenApi.IComponents;
|
|
169
|
+
schema: OpenApi.IJsonSchema;
|
|
170
|
+
options: IHttpLlmApplication.IOptions<"gemini">;
|
|
171
|
+
}) =>
|
|
172
|
+
GeminiConverter.schema({
|
|
173
|
+
components: props.components,
|
|
174
|
+
schema: props.schema,
|
|
175
|
+
recursive: props.options.recursive,
|
|
176
|
+
}),
|
|
177
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ILlmApplication } from "@samchon/openapi";
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
|
|
4
|
+
import { IdentifierFactory } from "../../../factories/IdentifierFactory";
|
|
4
5
|
import { LiteralFactory } from "../../../factories/LiteralFactory";
|
|
5
6
|
import { MetadataCollection } from "../../../factories/MetadataCollection";
|
|
6
7
|
import { MetadataFactory } from "../../../factories/MetadataFactory";
|
|
@@ -66,12 +67,45 @@ export namespace LlmSchemaTransformer {
|
|
|
66
67
|
});
|
|
67
68
|
|
|
68
69
|
// GENERATE LLM SCHEMA
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const out: LlmSchemaProgrammer.IOutput<any> = LlmSchemaProgrammer.write({
|
|
71
|
+
model,
|
|
72
|
+
metadata: result.data,
|
|
73
|
+
});
|
|
74
|
+
if (Object.keys(out.$defs).length === 0)
|
|
75
|
+
return LiteralFactory.write(out.schema);
|
|
76
|
+
return ts.factory.createCallExpression(
|
|
77
|
+
ts.factory.createArrowFunction(
|
|
78
|
+
undefined,
|
|
79
|
+
undefined,
|
|
80
|
+
[
|
|
81
|
+
IdentifierFactory.parameter(
|
|
82
|
+
"$defs",
|
|
83
|
+
ts.factory.createTypeReferenceNode("Record<string, unknown>"),
|
|
84
|
+
undefined,
|
|
85
|
+
),
|
|
86
|
+
],
|
|
87
|
+
undefined,
|
|
88
|
+
undefined,
|
|
89
|
+
ts.factory.createBlock(
|
|
90
|
+
[
|
|
91
|
+
ts.factory.createExpressionStatement(
|
|
92
|
+
ts.factory.createCallExpression(
|
|
93
|
+
ts.factory.createIdentifier("Object.assign"),
|
|
94
|
+
undefined,
|
|
95
|
+
[
|
|
96
|
+
ts.factory.createIdentifier("$defs"),
|
|
97
|
+
LiteralFactory.write(out.$defs),
|
|
98
|
+
],
|
|
99
|
+
),
|
|
100
|
+
),
|
|
101
|
+
ts.factory.createReturnStatement(LiteralFactory.write(out.schema)),
|
|
102
|
+
],
|
|
103
|
+
true,
|
|
104
|
+
),
|
|
105
|
+
),
|
|
106
|
+
undefined,
|
|
107
|
+
[props.expression.arguments[0]!],
|
|
108
|
+
);
|
|
75
109
|
};
|
|
76
110
|
|
|
77
111
|
const get_parameter =
|