Skip to content

Commit

Permalink
Fix #1486: object alias type case in LLM. (#1487)
Browse files Browse the repository at this point in the history
* Fix #1486: object alias type case in LLM.

* Fix JSON schema problem
  • Loading branch information
samchon authored Feb 4, 2025
1 parent 34f8d7a commit b7ddefa
Show file tree
Hide file tree
Showing 32 changed files with 556 additions and 454 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "7.6.1",
"version": "7.6.2",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Check out the document in the [website](https://typia.io/docs/):
- [`application()` function](https://typia.io/docs/llm/application/)
- [`parameters()` function](https://typia.io/docs/llm/parameters/)
- [`schema()` function](https://typia.io/docs/llm/schema/)
- [A.I. Chatbot](https://typia.io/docs/llm/chat/)
- [Super AI Chatbot](https://typia.io/docs/llm/chat/)
- [Documentation Strategy](https://typia.io/docs/llm/strategy/)
- Protocol Buffer
- [Message Schema](https://typia.io/docs/protobuf/message)
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "7.6.1-dev.20250203",
"version": "7.6.2-dev.20250205",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -38,7 +38,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "7.6.1-dev.20250203"
"typia": "7.6.2-dev.20250205"
},
"peerDependencies": {
"@samchon/openapi": ">=2.4.2 <3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/factories/JsonMetadataFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export namespace JsonMetadataFactory {
checker: props.checker,
transformer: props.transformer,
options: {
absorb: true,
escape: true,
constant: true,
absorb: true,
validate: props.validate
? (meta, explore) => {
const errors: string[] = validate(meta);
Expand Down
2 changes: 1 addition & 1 deletion src/programmers/llm/LlmModelPredicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export namespace LlmModelPredicator {
checker: props.context.checker,
transformer: props.context.transformer,
options: {
absorb: true,
escape: false,
constant: true,
absorb: false,
functional: false,
},
collection,
Expand Down
66 changes: 34 additions & 32 deletions src/transformers/features/json/JsonSchemasTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,44 @@ export namespace JsonSchemasTransformer {
// GENERATORS
//----
// METADATA
const collection: MetadataCollection = new MetadataCollection({
replace: MetadataCollection.replace,
});
const results: ValidationPipe<Metadata, MetadataFactory.IError>[] =
types.map((type) =>
MetadataFactory.analyze({
checker: props.context.checker,
transformer: props.context.transformer,
options: {
escape: true,
constant: true,
absorb: false,
validate: JsonSchemasProgrammer.validate,
},
collection,
type,
}),
);

// REPORT BUG IF REQUIRED
const metadatas: Metadata[] = [];
const errors: MetadataFactory.IError[] = [];
for (const r of results) {
if (r.success === false) errors.push(...r.errors);
else metadatas.push(r.data);
}
if (errors.length)
throw TransformerError.from({
code: "typia.json.application",
errors,
});
const analyze = (validate: boolean): Metadata[] => {
const results: ValidationPipe<Metadata, MetadataFactory.IError>[] =
types.map((type) =>
MetadataFactory.analyze({
checker: props.context.checker,
transformer: props.context.transformer,
options: {
absorb: validate,
constant: true,
escape: true,
validate:
validate === true ? JsonSchemasProgrammer.validate : undefined,
},
collection: new MetadataCollection({
replace: MetadataCollection.replace,
}),
type,
}),
);
const metadatas: Metadata[] = [];
const errors: MetadataFactory.IError[] = [];
for (const r of results) {
if (r.success === false) errors.push(...r.errors);
else metadatas.push(r.data);
}
if (errors.length)
throw TransformerError.from({
code: "typia.json.application",
errors,
});
return metadatas;
};
analyze(true);

// APPLICATION
const app: IJsonSchemaCollection<any> = JsonSchemasProgrammer.write({
version,
metadatas,
metadatas: analyze(false),
});
return ts.factory.createAsExpression(
LiteralFactory.write(app),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,47 @@ export namespace LlmApplicationOfValidateTransformer {
}) as Partial<ILlmSchema.IConfig>;

const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
const collection: MetadataCollection = new MetadataCollection({
replace: MetadataCollection.replace,
});
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
MetadataFactory.analyze({
checker: props.context.checker,
transformer: props.context.transformer,
options: {
escape: true,
constant: true,
absorb: false,
functional: true,
validate: LlmApplicationOfValidateProgrammer.validate({
model,
config,

// VALIDATE TYPE
const analyze = (validate: boolean): Metadata => {
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
MetadataFactory.analyze({
checker: props.context.checker,
transformer: props.context.transformer,
options: {
absorb: validate,
escape: true,
constant: true,
functional: true,
validate:
validate === true
? LlmApplicationOfValidateProgrammer.validate({
model,
config,
})
: undefined,
},
collection: new MetadataCollection({
replace: MetadataCollection.replace,
}),
},
collection,
type,
});
if (result.success === false)
throw TransformerError.from({
code: "typia.llm.application",
errors: result.errors,
});
type,
});
if (result.success === false)
throw TransformerError.from({
code: "typia.llm.application",
errors: result.errors,
});
return result.data;
};
analyze(true);

// GENERATE LLM APPLICATION
const schema: ILlmApplication<ILlmSchema.Model> =
LlmApplicationOfValidateProgrammer.write({
model,
context: props.context,
modulo: props.modulo,
metadata: result.data,
metadata: analyze(false),
config,
name: top.getFullText().trim(),
});
Expand Down
57 changes: 32 additions & 25 deletions src/transformers/features/llm/LlmApplicationTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,44 @@ export namespace LlmApplicationTransformer {
}) as Partial<ILlmSchema.IConfig>;

const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
const collection: MetadataCollection = new MetadataCollection({
replace: MetadataCollection.replace,
});
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
MetadataFactory.analyze({
checker: props.context.checker,
transformer: props.context.transformer,
options: {
escape: true,
constant: true,
absorb: false,
functional: true,
validate: LlmApplicationProgrammer.validate({
model,
config,
// VALIDATE TYPE
const analyze = (validate: boolean): Metadata => {
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
MetadataFactory.analyze({
checker: props.context.checker,
transformer: props.context.transformer,
options: {
absorb: validate,
escape: true,
constant: true,
functional: true,
validate:
validate === true
? LlmApplicationProgrammer.validate({
model,
config,
})
: undefined,
},
collection: new MetadataCollection({
replace: MetadataCollection.replace,
}),
},
collection,
type,
});
if (result.success === false)
throw TransformerError.from({
code: "typia.llm.applicationOfValidate",
errors: result.errors,
});
type,
});
if (result.success === false)
throw TransformerError.from({
code: "typia.llm.applicationOfValidate",
errors: result.errors,
});
return result.data;
};
analyze(true);

// GENERATE LLM APPLICATION
const schema: ILlmApplication<ILlmSchema.Model> =
LlmApplicationProgrammer.write({
model,
metadata: result.data,
metadata: analyze(false),
config,
});
const literal: ts.Expression = ts.factory.createAsExpression(
Expand Down
56 changes: 32 additions & 24 deletions src/transformers/features/llm/LlmParametersTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,43 @@ export namespace LlmParametersTransformer {
}) as Partial<ILlmSchema.IConfig>;

const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
const collection: MetadataCollection = new MetadataCollection({
replace: MetadataCollection.replace,
});
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
MetadataFactory.analyze({
checker: props.context.checker,
transformer: props.context.transformer,
options: {
escape: true,
constant: true,
absorb: false,
validate: LlmParametersProgrammer.validate({
model,
config,

// VALIDATE TYPE
const analyze = (validate: boolean): Metadata => {
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
MetadataFactory.analyze({
checker: props.context.checker,
transformer: props.context.transformer,
options: {
absorb: validate,
escape: true,
constant: true,
validate:
validate === true
? LlmParametersProgrammer.validate({
model,
config,
})
: undefined,
},
collection: new MetadataCollection({
replace: MetadataCollection.replace,
}),
},
collection,
type,
});
if (result.success === false)
throw TransformerError.from({
code: "typia.llm.parameters",
errors: result.errors,
});
type,
});
if (result.success === false)
throw TransformerError.from({
code: "typia.llm.parameters",
errors: result.errors,
});
return result.data;
};
analyze(true);

// GENERATE LLM SCHEMA
const out: ILlmFunction<any>["parameters"] = LlmParametersProgrammer.write({
model,
metadata: result.data,
metadata: analyze(false),
config,
});
return ts.factory.createAsExpression(
Expand Down
Loading

0 comments on commit b7ddefa

Please sign in to comment.