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

Documentation of LLM function callling appllication #1267

Merged
merged 2 commits into from
Sep 9, 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
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ export function validate<T>(input: unknown): IValidation<T>; // detailed

// JSON FUNCTIONS
export namespace json {
export function application<T>(): IJsonApplication; // JSON schema
export function assertParse<T>(input: string): T; // type safe parser
export function assertStringify<T>(input: T): string; // safe and faster
export function application<T>(): IJsonApplication; // JSON schema
export function assertParse<T>(input: string): T; // type safe parser
export function assertStringify<T>(input: T): string; // safe and faster
}

// LLM FUNCTION CALLING APPLICATION
export namespace llm {
// LLM function calling application from a class or interface type
export function application<App>(): ILlmApplication;
export function schema<T>(): ILlmSchema; // LLM type schema
}

// PROTOCOL BUFFER
export namespace protobuf {
export function message<T>(): string; // Protocol Buffer message
export function assertDecode<T>(buffer: Uint8Array): T; // safe decoder
export function assertEncode<T>(input: T): Uint8Array; // safe encoder
export function message<T>(): string; // Protocol Buffer message
export function assertDecode<T>(buffer: Uint8Array): T; // safe decoder
export function assertEncode<T>(input: T): Uint8Array; // safe encoder
}

// RANDOM GENERATOR
Expand All @@ -36,6 +43,7 @@ Typia is a transformer library supporting below features:

- Super-fast Runtime Validators
- Enhanced JSON functions
- LLM function calling application composer
- Protocol Buffer encoder and decoder
- Random data generator

Expand All @@ -62,6 +70,7 @@ Also, `typia` is re-distributing half of donations to core contributors of `typi




## Playground
You can experience how typia works by [playground website](https://typia.io/playground):

Expand All @@ -86,9 +95,12 @@ Check out the document in the [website](https://typia.io/docs/):
- [Functional Module](https://typia.io/docs/validators/functional)
- [Special Tags](https://typia.io/docs/validators/tags/)
- Enhanced JSON
- [JSON Schema](https://typia.io/docs/json/schema)
- [JSON Schema](https://typia.io/docs/json/schema/)
- [`stringify()` functions](https://typia.io/docs/json/stringify/)
- [`parse()` functions](https://typia.io/docs/json/parse/)
- LLM Function Calling
- [`application()` function](https://typia.io/docs/llm/application/)
- [`schema()` function](https://typia.io/docs/llm/schema/)
- Protocol Buffer
- [Message Schema](https://typia.io/docs/protobuf/message)
- [`decode()` functions](https://typia.io/docs/protobuf/decode/)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^3.0.0",
"uuid": "^9.0.1",
"typia": "../typia-6.10.0-dev.20240908.tgz"
"typia": "../typia-6.10.0-dev.20240910.tgz"
}
}
2 changes: 1 addition & 1 deletion debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"tstl": "^3.0.0",
"typia": "../typia-6.10.0-dev.20240907.tgz",
"typia": "../typia-6.10.0.tgz",
"uuid": "^10.0.0"
}
}
5 changes: 5 additions & 0 deletions debug/src/llm.schema.recursive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ILlmSchema } from "@samchon/openapi";
import typia from "typia";

const schema: ILlmSchema = typia.llm.schema<Date>();
console.log(schema);
24 changes: 0 additions & 24 deletions debug/src/llm.ts

This file was deleted.

2 changes: 1 addition & 1 deletion errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"typescript": "^5.3.2"
},
"dependencies": {
"typia": "../typia-6.10.0-dev.20240908.tgz"
"typia": "../typia-6.10.0-dev.20240910.tgz"
}
}
7 changes: 7 additions & 0 deletions errors/src/llm/llm.application.bigint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import typia from "typia";

typia.llm.application<Controller>();

interface Controller {
plus(X: bigint, y: bigint): bigint;
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "6.10.0-dev.20240908",
"version": "6.10.0-dev.20240910",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -67,7 +67,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"@samchon/openapi": "^0.5.0-dev.20240906-2",
"@samchon/openapi": "^1.0.0",
"commander": "^10.0.0",
"comment-json": "^4.2.3",
"inquirer": "^8.2.5",
Expand Down
26 changes: 19 additions & 7 deletions packages/typescript-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ export function validate<T>(input: unknown): IValidation<T>; // detailed

// JSON FUNCTIONS
export namespace json {
export function application<T>(): IJsonApplication; // JSON schema
export function assertParse<T>(input: string): T; // type safe parser
export function assertStringify<T>(input: T): string; // safe and faster
export function application<T>(): IJsonApplication; // JSON schema
export function assertParse<T>(input: string): T; // type safe parser
export function assertStringify<T>(input: T): string; // safe and faster
}

// LLM FUNCTION CALLING APPLICATION
export namespace llm {
// LLM function calling application from a class or interface type
export function application<App>(): ILlmApplication;
export function schema<T>(): ILlmSchema; // LLM type schema
}

// PROTOCOL BUFFER
export namespace protobuf {
export function message<T>(): string; // Protocol Buffer message
export function assertDecode<T>(buffer: Uint8Array): T; // safe decoder
export function assertEncode<T>(input: T): Uint8Array; // safe encoder
export function message<T>(): string; // Protocol Buffer message
export function assertDecode<T>(buffer: Uint8Array): T; // safe decoder
export function assertEncode<T>(input: T): Uint8Array; // safe encoder
}

// RANDOM GENERATOR
Expand All @@ -39,6 +46,7 @@ Typia is a transformer library supporting below features:

- Super-fast Runtime Validators
- Enhanced JSON functions
- LLM function calling application composer
- Protocol Buffer encoder and decoder
- Random data generator

Expand All @@ -65,6 +73,7 @@ Also, `typia` is re-distributing half of donations to core contributors of `typi




## Playground
You can experience how typia works by [playground website](https://typia.io/playground):

Expand All @@ -89,9 +98,12 @@ Check out the document in the [website](https://typia.io/docs/):
- [Functional Module](https://typia.io/docs/validators/functional)
- [Special Tags](https://typia.io/docs/validators/tags/)
- Enhanced JSON
- [JSON Schema](https://typia.io/docs/json/schema)
- [JSON Schema](https://typia.io/docs/json/schema/)
- [`stringify()` functions](https://typia.io/docs/json/stringify/)
- [`parse()` functions](https://typia.io/docs/json/parse/)
- LLM Function Calling
- [`application()` function](https://typia.io/docs/llm/application/)
- [`schema()` function](https://typia.io/docs/llm/schema/)
- Protocol Buffer
- [Message Schema](https://typia.io/docs/protobuf/message)
- [`decode()` functions](https://typia.io/docs/protobuf/decode/)
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": "6.10.0-dev.20240908",
"version": "6.10.0-dev.20240910",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -63,7 +63,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "6.10.0-dev.20240908"
"typia": "6.10.0-dev.20240910"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.6.0"
Expand Down
45 changes: 43 additions & 2 deletions src/factories/MetadataFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Metadata } from "../schemas/metadata/Metadata";
import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
import { MetadataConstant } from "../schemas/metadata/MetadataConstant";
import { MetadataFunction } from "../schemas/metadata/MetadataFunction";
import { MetadataObject } from "../schemas/metadata/MetadataObject";
import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
import { explore_metadata } from "./internal/metadata/explore_metadata";
Expand Down Expand Up @@ -32,6 +33,8 @@ export namespace MetadataFactory {
object: MetadataObject | null;
property: string | object | null;
nested: null | MetadataAlias | MetadataArrayType | MetadataTupleType;
parameter: string | null;
output: boolean;
escaped: boolean;
aliased: boolean;
}
Expand All @@ -54,9 +57,11 @@ export namespace MetadataFactory {
top: true,
object: null,
property: null,
parameter: null,
nested: null,
escaped: false,
aliased: false,
escaped: false,
output: false,
});
iterate_metadata_collection(errors)(collection);
iterate_metadata_sort(collection)(meta);
Expand Down Expand Up @@ -105,14 +110,17 @@ export namespace MetadataFactory {
arrays: new Set(),
tuples: new Set(),
aliases: new Set(),
functions: new Set(),
};
validateMeta(context)(options)(visitor)(meta, {
object: null,
property: null,
parameter: null,
nested: null,
top: true,
aliased: false,
escaped: false,
output: false,
});
return visitor.errors;
};
Expand Down Expand Up @@ -157,6 +165,8 @@ export namespace MetadataFactory {
validateTuple(context)(options)(visitor)(tuple.type, explore);
for (const obj of meta.objects)
validateObject(context)(options)(visitor)(obj);
for (const func of meta.functions)
validateFunction(context)(options)(visitor)(func, explore);
for (const set of meta.sets)
validateMeta(context)(options)(visitor)(set, explore);
for (const map of meta.maps) {
Expand Down Expand Up @@ -230,9 +240,11 @@ export namespace MetadataFactory {
object,
top: false,
property: null,
parameter: null,
nested: null,
escaped: false,
aliased: false,
escaped: false,
output: false,
};
const errors: string[] = options.validate(
Metadata.create({
Expand All @@ -255,10 +267,38 @@ export namespace MetadataFactory {
property: property.key.isSoleLiteral()
? property.key.getSoleLiteral()!
: {},
parameter: null,
nested: null,
top: false,
aliased: false,
escaped: false,
output: false,
});
};

const validateFunction =
(context?: ts.TransformationContext) =>
(options: IOptions) =>
(visitor: IValidationVisitor) =>
(func: MetadataFunction, explore: IExplore) => {
if (visitor.functions.has(func)) return;
visitor.functions.add(func);

for (const param of func.parameters)
validateMeta(context)(options)(visitor)(param.type, {
...explore,
parameter: param.name,
nested: null,
top: false,
output: false,
});
if (func.output)
validateMeta(context)(options)(visitor)(func.output, {
...explore,
parameter: null,
nested: null,
top: false,
output: true,
});
};

Expand All @@ -269,5 +309,6 @@ export namespace MetadataFactory {
arrays: Set<MetadataArrayType>;
tuples: Set<MetadataTupleType>;
aliases: Set<MetadataAlias>;
functions: Set<MetadataFunction>;
}
}
12 changes: 9 additions & 3 deletions src/factories/internal/metadata/emplace_metadata_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ export const emplace_metadata_object =
top: false,
object: obj,
property: prop.name,
parameter: null,
nested: null,
escaped: false,
aliased: false,
escaped: false,
output: false,
});
Writable(value).optional = (prop.flags & ts.SymbolFlags.Optional) !== 0;
insert(key)(value)(prop);
Expand All @@ -119,9 +121,11 @@ export const emplace_metadata_object =
top: false,
object: obj,
property,
parameter: null,
nested: null,
escaped: false,
aliased: false,
escaped: false,
output: false,
});
const key: Metadata = analyzer(index.keyType)(null);
const value: Metadata = analyzer(index.type)({});
Expand All @@ -145,9 +149,11 @@ export const emplace_metadata_object =
top: false,
object: obj,
property: "[key]",
parameter: null,
nested: null,
escaped: false,
aliased: false,
escaped: false,
output: false,
},
messages: [],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export const iterate_metadata_comment_tags =
property: property.key.isSoleLiteral()
? property.key.getSoleLiteral()!
: {},
parameter: null,
nested: null,
escaped: false,
aliased: false,
escaped: false,
output: false,
},
);
}
Expand Down
Loading