Skip to content

Commit

Permalink
Support ILlmFunction.tags by @tag name comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Sep 25, 2024
1 parent f9b53ba commit 6903fc0
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 46 deletions.
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.3-dev.20240925.tgz"
"typia": "../typia-6.10.4-dev.20240925.tgz"
}
}
3 changes: 1 addition & 2 deletions debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
"typescript": "^5.4.2"
},
"dependencies": {
"@samchon/openapi": "^1.0.5",
"tstl": "^3.0.0",
"typia": "../typia-6.10.2.tgz",
"typia": "../typia-6.10.4-dev.20240925.tgz",
"uuid": "^10.0.0"
}
}
9 changes: 8 additions & 1 deletion debug/src/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ interface ICalculator {
* @deprecated
*/
plus(x: number, y: number): number;

/**
* @tag arithmetic
* @tag mathmatics
* @tag something for nothing
*/
minus(x: number, y: number): number;
}

const app: ILlmApplication = typia.llm.application<ICalculator>();
console.log(app.functions[0]?.deprecated);
console.log(app.functions[1]?.tags);
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.3-dev.20240925.tgz"
"typia": "../typia-6.10.4-dev.20240925.tgz"
}
}
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.3",
"version": "6.10.4",
"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": "^1.0.5",
"@samchon/openapi": "^1.0.6",
"commander": "^10.0.0",
"comment-json": "^4.2.3",
"inquirer": "^8.2.5",
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.3-dev.20240925",
"version": "6.10.4-dev.20240925",
"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.3-dev.20240925"
"typia": "6.10.4-dev.20240925"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.7.0"
Expand Down
86 changes: 51 additions & 35 deletions src/programmers/llm/LlmApplicationProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,41 +104,57 @@ export namespace LlmApplicationProgrammer {
function: MetadataFunction;
description: string | null;
jsDocTags: IJsDocTagInfo[];
}): ILlmFunction => ({
name: props.name,
parameters: props.function.parameters.map((p) => {
const jsDocTagDescription = writeDescriptionFromJsDocTag({
jsDocTags: p.jsDocTags,
tag: "param",
parameter: p.name,
});
return writeSchema({
metadata: p.type,
description: jsDocTagDescription ?? p.description,
jsDocTags: jsDocTagDescription ? [] : p.jsDocTags,
});
}),
output:
props.function.output.size() || props.function.output.nullable
? writeSchema({
metadata: props.function.output,
description:
writeDescriptionFromJsDocTag({
jsDocTags: props.jsDocTags,
tag: "return",
}) ??
writeDescriptionFromJsDocTag({
jsDocTags: props.jsDocTags,
tag: "returns",
}),
jsDocTags: [],
})
: undefined,
description: props.description ?? undefined,
deprecated: props.jsDocTags.some((tag) => tag.name === "deprecated")
? true
: undefined,
});
}): ILlmFunction => {
const deprecated: boolean = props.jsDocTags.some(
(tag) => tag.name === "deprecated",
);
const tags: string[] = props.jsDocTags
.map((tag) =>
tag.name === "tag"
? (tag.text?.filter((elem) => elem.kind === "text") ?? [])
: [],
)
.flat()
.map((elem) => elem.text)
.map((str) => str.trim().split(" ")[0] ?? "")
.filter((str) => !!str.length);
return {
name: props.name,
parameters: props.function.parameters.map((p) => {
const jsDocTagDescription: string | null = writeDescriptionFromJsDocTag(
{
jsDocTags: p.jsDocTags,
tag: "param",
parameter: p.name,
},
);
return writeSchema({
metadata: p.type,
description: jsDocTagDescription ?? p.description,
jsDocTags: jsDocTagDescription ? [] : p.jsDocTags,
});
}),
output:
props.function.output.size() || props.function.output.nullable
? writeSchema({
metadata: props.function.output,
description:
writeDescriptionFromJsDocTag({
jsDocTags: props.jsDocTags,
tag: "return",
}) ??
writeDescriptionFromJsDocTag({
jsDocTags: props.jsDocTags,
tag: "returns",
}),
jsDocTags: [],
})
: undefined,
description: props.description ?? undefined,
deprecated: deprecated || undefined,
tags: tags.length ? tags : undefined,
};
};

const writeSchema = (props: {
metadata: Metadata;
Expand Down
2 changes: 1 addition & 1 deletion test-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"typescript": "^5.4.5"
},
"dependencies": {
"typia": "../typia-6.10.3-dev.20240925.tgz"
"typia": "../typia-6.10.4-dev.20240925.tgz"
}
}
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^3.0.0",
"uuid": "^9.0.1",
"typia": "../typia-6.10.3-dev.20240925.tgz"
"typia": "../typia-6.10.4-dev.20240925.tgz"
}
}
9 changes: 9 additions & 0 deletions test/src/features/llm.application/test_llm_application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const test_llm_application = (): void => {
type: "string",
},
description: "Get ID.",
deprecated: true,
},
{
name: "getValue",
Expand All @@ -35,6 +36,7 @@ export const test_llm_application = (): void => {
},
description:
"Get value.\n\nGet value with plus operation of member value, x and y.",
tags: ["mathmatics", "arithmetic"],
},
{
name: "getPerformance",
Expand All @@ -53,6 +55,7 @@ export const test_llm_application = (): void => {
description: "The performance interface.",
},
description: "Get performance.",
tags: ["monitor"],
},
{
name: "synchronize",
Expand Down Expand Up @@ -81,6 +84,8 @@ class SomeClass {

/**
* Get ID.
*
* @deprecated
*/
getId = (): string => {
return this.id;
Expand All @@ -98,13 +103,17 @@ class SomeClass {
* @returns Sum of them.
*
* `this.value + x + y`
* @tag mathmatics
* @tag arithmetic
*/
getValue(x: number, y: number): number {
return this.value + x + y;
}

/**
* Get performance.
*
* @tag monitor tool
*/
async getPerformance(): Promise<IPerformance> {
return { level: 3 };
Expand Down

0 comments on commit 6903fc0

Please sign in to comment.