From 24a8f733248091d17d3776fbac9414264838e21e Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Fri, 20 Dec 2024 22:31:33 +0900 Subject: [PATCH] `HttpLlm.appliation()` escapes some special characters. ChatGPT allows only `/^[a-zA-Z0-9_-]+$/` characters in the tool calling function name. By the way, `$` and `%` characters are often shown in the URL path. For such special characters, this PR replaces them to `_` character to successfully composing LLM function calling application from the OpenAPI document. --- package.json | 2 +- src/composers/HttpLlmApplicationComposer.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9e80614..b0dd5c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@samchon/openapi", - "version": "2.3.0", + "version": "2.3.1", "description": "OpenAPI definitions and converters for 'typia' and 'nestia'.", "main": "./lib/index.js", "module": "./lib/index.mjs", diff --git a/src/composers/HttpLlmApplicationComposer.ts b/src/composers/HttpLlmApplicationComposer.ts index a313ec8..b73ec36 100644 --- a/src/composers/HttpLlmApplicationComposer.ts +++ b/src/composers/HttpLlmApplicationComposer.ts @@ -172,7 +172,7 @@ export namespace HttpLlmComposer { ]; // FUNTION NAME - const name: string = props.route.accessor.join("_"); + const name: string = emend(props.route.accessor.join("_")); const isNameVariable: boolean = /^[a-zA-Z0-9_-]+$/.test(name); const isNameStartsWithNumber: boolean = /^[0-9]/.test(name[0] ?? ""); if (isNameVariable === false) @@ -231,3 +231,9 @@ export namespace HttpLlmComposer { }; }; } + +const emend = (str: string): string => { + for (const ch of FORBIDDEN) str = str.split(ch).join("_"); + return str; +}; +const FORBIDDEN = ["$", "%", "."];