From fb528e8117755df2b5809d0ca74a57f849869749 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Mon, 23 Dec 2024 01:40:34 +0900 Subject: [PATCH 1/2] Fix `ILlmFunction.parameters.description` problem. `typia.llm.application()` function had not filled `ILlmFunction.parameters.description` property. This PR fixes it including the `typia.llm.applicationOfValidate()` function case. --- package.json | 2 +- .../llm/LlmApplicationProgrammer.ts | 11 +- test/src/debug/llm.application.ts | 128 ++++++++++++++++-- 3 files changed, 126 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 99284d2925..2c6cd0c020 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typia", - "version": "7.5.0", + "version": "7.5.1", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/src/programmers/llm/LlmApplicationProgrammer.ts b/src/programmers/llm/LlmApplicationProgrammer.ts index e8d385ffb0..4403b0d97a 100644 --- a/src/programmers/llm/LlmApplicationProgrammer.ts +++ b/src/programmers/llm/LlmApplicationProgrammer.ts @@ -242,9 +242,14 @@ export namespace LlmApplicationProgrammer { > = LlmSchemaComposer.parameters(props.model)({ config: LlmSchemaComposer.defaultConfig(props.model) as any, components: props.components, - schema: schema as - | OpenApi.IJsonSchema.IObject - | OpenApi.IJsonSchema.IReference, + schema: { + ...(schema as + | OpenApi.IJsonSchema.IObject + | OpenApi.IJsonSchema.IReference), + title: schema.title ?? props.function.parameters[0]?.title, + description: + schema.description ?? props.function.parameters[0]?.description, + }, accessor: props.accessor, }) as IResult; if (result.success === false) { diff --git a/test/src/debug/llm.application.ts b/test/src/debug/llm.application.ts index bab3cd8894..32522a9e25 100644 --- a/test/src/debug/llm.application.ts +++ b/test/src/debug/llm.application.ts @@ -1,17 +1,123 @@ -import { ILlmApplication } from "@samchon/openapi"; -import typia from "typia"; +import { ILlmApplication, ILlmFunction } from "@samchon/openapi"; +import typia, { tags } from "typia"; -interface SomeApplication { - plus(props: { x: number; y: number }): number; +const app: ILlmApplication<"chatgpt"> = typia.llm.application< + BbsArticleController, + "chatgpt" +>(); +const func: ILlmFunction<"chatgpt"> | undefined = app.functions.find( + (func) => func.name === "create", +); +console.log(func?.parameters.description); +console.log(func?.output?.description); + +interface BbsArticleController { + /** + * Create a new article. + * + * Writes a new article and archives it into the DB. + * + * @param props Properties of create function + * @returns Newly created article + */ + create(props: { + /** + * Information of the article to create + */ + input: IBbsArticle.ICreate; + }): Promise; /** - * @human + * Update an article. + * + * Updates an article with new content. + * + * @param props Properties of update function + * @param input New content to update */ - minus(props: { x: number; y: number }): number; + update(props: { + /** + * Target article's {@link IBbsArticle.id}. + */ + id: string & tags.Format<"uuid">; + + /** + * New content to update. + */ + input: IBbsArticle.IUpdate; + }): Promise; + + /** + * Erase an article. + * + * Erases an article from the DB. + * + * @param props Properties of erase function + */ + erase(props: { + /** + * Target article's {@link IBbsArticle.id}. + */ + id: string & tags.Format<"uuid">; + }): Promise; } -const app: ILlmApplication<"chatgpt"> = typia.llm.application< - SomeApplication, - "chatgpt" ->(); -console.log(app); +/** + * Article entity. + * + * `IBbsArticle` is an entity representing an article in the BBS (Bulletin Board System). + */ +interface IBbsArticle extends IBbsArticle.ICreate { + /** + * Primary Key. + */ + id: string & tags.Format<"uuid">; + + /** + * Creation time of the article. + */ + created_at: string & tags.Format<"date-time">; + + /** + * Last updated time of the article. + */ + updated_at: string & tags.Format<"date-time">; +} +namespace IBbsArticle { + /** + * Information of the article to create. + */ + export interface ICreate { + /** + * Title of the article. + * + * Representative title of the article. + */ + title: string; + + /** + * Content body. + * + * Content body of the article writtn in the markdown format. + */ + body: string; + + /** + * Thumbnail image URI. + * + * Thumbnail image URI which can represent the article. + * + * If configured as `null`, it means that no thumbnail image in the article. + */ + thumbnail: + | null + | (string & tags.Format<"uri"> & tags.ContentMediaType<"image/*">); + } + + /** + * Information of the article to update. + * + * Only the filled properties will be updated. + */ + export type IUpdate = Partial; +} From 8208b96d8da20a3a6f358f414a4b7d2fe8aab74d Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Mon, 23 Dec 2024 01:45:25 +0900 Subject: [PATCH 2/2] Test case for #1442 --- ...42_llm_function_parameters_description.ts} | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) rename test/src/{debug/llm.application.ts => features/issues/test_pr_1442_llm_function_parameters_description.ts} (77%) diff --git a/test/src/debug/llm.application.ts b/test/src/features/issues/test_pr_1442_llm_function_parameters_description.ts similarity index 77% rename from test/src/debug/llm.application.ts rename to test/src/features/issues/test_pr_1442_llm_function_parameters_description.ts index 32522a9e25..39e6b2c839 100644 --- a/test/src/debug/llm.application.ts +++ b/test/src/features/issues/test_pr_1442_llm_function_parameters_description.ts @@ -1,15 +1,26 @@ import { ILlmApplication, ILlmFunction } from "@samchon/openapi"; import typia, { tags } from "typia"; -const app: ILlmApplication<"chatgpt"> = typia.llm.application< - BbsArticleController, - "chatgpt" ->(); -const func: ILlmFunction<"chatgpt"> | undefined = app.functions.find( - (func) => func.name === "create", -); -console.log(func?.parameters.description); -console.log(func?.output?.description); +import { TestValidator } from "../../helpers/TestValidator"; + +export const test_pr_1442_llm_function_parameters_description = (): void => { + const app: ILlmApplication<"chatgpt"> = typia.llm.application< + BbsArticleController, + "chatgpt" + >(); + for (const func of app.functions) + TestValidator.equals("parameters.description")( + !!func.parameters.description, + )(true); + + const func: ILlmFunction<"chatgpt"> | undefined = app.functions.find( + (func) => func.name === "create", + ); + TestValidator.equals("parameters.description")( + !!func?.parameters.description, + )(true); + TestValidator.equals("output.description")(!!func?.output?.description)(true); +}; interface BbsArticleController { /**