Skip to content

Commit

Permalink
HttpLlm.appliation() escapes some special characters.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
samchon committed Dec 20, 2024
1 parent 5548c64 commit 24a8f73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 7 additions & 1 deletion src/composers/HttpLlmApplicationComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = ["$", "%", "."];

0 comments on commit 24a8f73

Please sign in to comment.