Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block LLM function schema composition by @human tag. #1427

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.2.0",
"version": "7.2.1",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
27 changes: 26 additions & 1 deletion packages/typescript-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export namespace protobuf {
export function random<T>(g?: Partial<IRandomGenerator>): T;
```

Typia is a transformer library supporting below features:
`typia` is a transformer library supporting below features:

- Super-fast Runtime Validators
- Enhanced JSON schema and serde functions
Expand All @@ -63,6 +63,31 @@ Typia is a transformer library supporting below features:



## Transformation
If you call `typia` function, it would be compiled like below.

This is the key concept of `typia`, transforming TypeScript type to a runtime function. The `typia.is<T>()` function is transformed to a dedicated type checker by analyzing the target type `T` in the compilation level.

This feature enables developers to ensure type safety in their applications, leveraging TypeScript's static typing while also providing runtime validation. Instead of defining additional schemas, you can simply utilize the pure TypeScript type itself.

```typescript
//----
// examples/checkString.ts
//----
import typia, { tags } from "typia";
export const checkString = typia.createIs<string>();

//----
// examples/checkUUID.js
//----
import typia from "typia";
export const checkString = (() => {
return (input) => "string" === typeof input;
})();
```



## Sponsors
Thanks for your support.

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.1.0-dev.20241209",
"version": "7.2.1-dev.20241212",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "7.1.0-dev.20241209"
"typia": "7.2.1-dev.20241212"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.8.0",
Expand Down
5 changes: 4 additions & 1 deletion src/programmers/json/JsonApplicationProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
import { Metadata } from "../../schemas/metadata/Metadata";
import { MetadataFunction } from "../../schemas/metadata/MetadataFunction";
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
import { MetadataProperty } from "../../schemas/metadata/MetadataProperty";

import { JsonSchemasProgrammer } from "./JsonSchemasProgrammer";

Expand Down Expand Up @@ -60,6 +61,7 @@ export namespace JsonApplicationProgrammer {
export const write = <Version extends "3.0" | "3.1">(props: {
version: Version;
metadata: Metadata;
filter?: (prop: MetadataProperty) => boolean;
}): __IJsonApplication<Version> => {
const errors: string[] = validate(props.metadata, {
top: true,
Expand Down Expand Up @@ -101,7 +103,8 @@ export namespace JsonApplicationProgrammer {
(p) =>
p.jsDocTags.find(
(tag) => tag.name === "hidden" || tag.name === "internal",
) === undefined,
) === undefined &&
(props.filter === undefined || props.filter(p) === true),
)
.map((r) =>
collectFunction({
Expand Down
2 changes: 2 additions & 0 deletions src/programmers/llm/LlmApplicationProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export namespace LlmApplicationProgrammer {
JsonApplicationProgrammer.write({
version: "3.1",
metadata: props.metadata,
filter: (p) =>
p.jsDocTags.some((tag) => tag.name === "human") === false,
});
const functions: Array<ILlmFunction<Model> | null> =
application.functions.map((func) =>
Expand Down
2 changes: 1 addition & 1 deletion test/debug.js → test/debug.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cp = require("child_process");
import cp from "child_process";

cp.execSync(`npx ts-node src/debug/${process.argv[2]}.ts`, {
cwd: __dirname,
Expand Down
16 changes: 10 additions & 6 deletions test/generate/output/generate_http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,19 @@ export const validateQuery = (() => {
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return {
success,
errors,
data: input,
} as any;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
errors: [],
data: input,
} as any;
};
Expand Down
32 changes: 20 additions & 12 deletions test/generate/output/generate_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,15 +758,19 @@ export const validate = (() => {
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return {
success,
errors,
data: input,
} as any;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
errors: [],
data: input,
} as any;
};
Expand Down Expand Up @@ -1704,15 +1708,19 @@ export const validateEquals = (() => {
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return {
success,
errors,
data: input,
} as any;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
errors: [],
data: input,
} as any;
};
Expand Down
32 changes: 20 additions & 12 deletions test/generate/output/generate_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,15 +605,19 @@ export const createValidateStringify = (() => {
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return {
success,
errors,
data: input,
} as any;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
errors: [],
data: input,
} as any;
};
Expand Down Expand Up @@ -1098,15 +1102,19 @@ export const createValidateParse = (() => {
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return {
success,
errors,
data: input,
} as any;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
errors: [],
data: input,
} as any;
};
Expand Down
32 changes: 20 additions & 12 deletions test/generate/output/generate_misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,19 @@ export const createValidateClone = (() => {
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return {
success,
errors,
data: input,
} as any;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
errors: [],
data: input,
} as any;
};
Expand Down Expand Up @@ -1195,15 +1199,19 @@ export const createValidatePrune = (() => {
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return {
success,
errors,
data: input,
} as any;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
errors: [],
data: input,
} as any;
};
Expand Down
48 changes: 30 additions & 18 deletions test/generate/output/generate_notations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,19 @@ export const createValidateCamel = (() => {
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return {
success,
errors,
data: input,
} as any;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
errors: [],
data: input,
} as any;
};
Expand Down Expand Up @@ -1098,15 +1102,19 @@ export const createValidatePascal = (() => {
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return {
success,
errors,
data: input,
} as any;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
errors: [],
data: input,
} as any;
};
Expand Down Expand Up @@ -1650,15 +1658,19 @@ export const createValidateSnake = (() => {
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return {
success,
errors,
data: input,
} as any;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
errors: [],
data: input,
} as any;
};
Expand Down
Loading
Loading