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

HttpLlm.application() bans the multipart/form-data type. #65

Merged
merged 1 commit into from
Nov 11, 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
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.0.0-dev.20241111-2",
"version": "2.0.0-dev.20241111-3",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",
"main": "./lib/index.js",
"module": "./lib/index.mjs",
Expand Down
27 changes: 26 additions & 1 deletion src/converters/HttpLlmConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,32 @@ export namespace HttpLlmConverter {
const functions: IHttpLlmFunction<Schema, Operation, Route>[] =
props.migrate.routes
.map((route) => {
if (route.method === "head") return null;
if (route.method === "head") {
errors.push({
method: route.method,
path: route.path,
messages: [
"HEAD method is not supported in the LLM application.",
],
operation: () => route.operation(),
route: () => route as any as Route,
});
return null;
} else if (
route.body?.type === "multipart/form-data" ||
route.success?.type === "multipart/form-data"
) {
errors.push({
method: route.method,
path: route.path,
messages: [
`The "multipart/form-data" content type is not supported in the LLM application.`,
],
operation: () => route.operation(),
route: () => route as any as Route,
});
return null;
}
const func: IHttpLlmFunction<Schema> | null = composeFunction({
model: props.model,
options: props.options,
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ export class AppController {
};
}

/**
* @deprecated
*/
@TypedRoute.Post(":index/:level/:optimal/multipart")
public query_multipart(
@TypedParam("index")
Expand All @@ -94,6 +91,9 @@ export class AppController {
};
}

/**
* @deprecated
*/
@TypedRoute.Get("nothing")
public nothing(): void {}
}
Expand Down
85 changes: 85 additions & 0 deletions test/features/llm/chatgpt/test_chatgpt_schema_ref.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { TestValidator } from "@nestia/e2e";
import { IChatGptSchema } from "@samchon/openapi";
import { ChatGptConverter } from "@samchon/openapi/lib/converters/ChatGptConverter";
import typia, { IJsonApplication, tags } from "typia";

export const test_chatgpt_schema_ref = (): void => {
test(typia.json.application<[IShoppingCategory]>(), {
$ref: "#/$defs/IShoppingCategory",
$defs: {
IShoppingCategory: {
type: "object",
properties: {
id: {
type: "string",
format: "uuid",
},
name: {
type: "string",
},
children: {
type: "array",
items: {
$ref: "#/$defs/IShoppingCategory",
},
},
},
additionalProperties: false,
required: ["id", "name", "children"],
},
},
});
test(typia.json.application<[IShoppingCategory.IInvert]>(), {
$ref: "#/$defs/IShoppingCategory.IInvert",
$defs: {
"IShoppingCategory.IInvert": {
type: "object",
properties: {
id: {
type: "string",
format: "uuid",
},
name: {
type: "string",
},
parent: {
oneOf: [
{
type: "null",
},
{
$ref: "#/$defs/IShoppingCategory.IInvert",
},
],
},
},
required: ["id", "name", "parent"],
additionalProperties: false,
},
},
});
};

const test = (
collection: IJsonApplication,
expected: IChatGptSchema.ITop,
): void => {
const schema: IChatGptSchema.ITop | null = ChatGptConverter.schema({
components: collection.components,
schema: collection.schemas[0],
});
TestValidator.equals("ref")(schema)(expected);
};

interface IShoppingCategory {
id: string & tags.Format<"uuid">;
name: string;
children: IShoppingCategory[];
}
namespace IShoppingCategory {
export interface IInvert {
id: string & tags.Format<"uuid">;
name: string;
parent: IShoppingCategory.IInvert | null;
}
}
4 changes: 1 addition & 3 deletions test/features/llm/test_http_llm_function_deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export const test_http_llm_function_deprecated = (): void => {
});
const func: IHttpLlmFunction<ILlmSchemaV3> | undefined =
application.functions.find(
(f) =>
f.method === "post" &&
f.path === "/{index}/{level}/{optimal}/multipart",
(f) => f.method === "get" && f.path === "/nothing",
);
TestValidator.equals("deprecated")(func?.deprecated)(true);
};
22 changes: 22 additions & 0 deletions test/features/llm/test_http_llm_function_multipart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TestValidator } from "@nestia/e2e";
import { HttpLlm, IHttpLlmApplication, OpenApi } from "@samchon/openapi";

import swagger from "../../swagger.json";

export const test_http_llm_function_multipart = (): void => {
const document: OpenApi.IDocument = OpenApi.convert(swagger as any);
const application: IHttpLlmApplication<"3.0"> = HttpLlm.application({
model: "3.0",
document,
options: {
keyword: true,
},
});
TestValidator.equals("multipart not suppported")(
!!application.errors.find(
(e) =>
e.method === "post" &&
e.path === "/{index}/{level}/{optimal}/multipart",
),
)(true);
};
30 changes: 25 additions & 5 deletions test/features/llm/test_llm_schema_recursive_array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const test_llm_schema_recursive_array = (): void => {
Department: {
type: "object",
properties: {
id: {
type: "string",
format: "uuid",
},
name: {
type: "string",
},
Expand All @@ -18,7 +22,7 @@ export const test_llm_schema_recursive_array = (): void => {
},
},
},
required: ["name", "children"],
required: ["id", "name", "children"],
},
},
},
Expand All @@ -30,6 +34,10 @@ export const test_llm_schema_recursive_array = (): void => {
TestValidator.equals("recursive")(schema)({
type: "object",
properties: {
id: {
type: "string",
format: "uuid",
},
name: {
type: "string",
},
Expand All @@ -38,6 +46,10 @@ export const test_llm_schema_recursive_array = (): void => {
items: {
type: "object",
properties: {
id: {
type: "string",
format: "uuid",
},
name: {
type: "string",
},
Expand All @@ -46,6 +58,10 @@ export const test_llm_schema_recursive_array = (): void => {
items: {
type: "object",
properties: {
id: {
type: "string",
format: "uuid",
},
name: {
type: "string",
},
Expand All @@ -54,6 +70,10 @@ export const test_llm_schema_recursive_array = (): void => {
items: {
type: "object",
properties: {
id: {
type: "string",
format: "uuid",
},
name: {
type: "string",
},
Expand All @@ -63,22 +83,22 @@ export const test_llm_schema_recursive_array = (): void => {
maxItems: 0,
},
},
required: ["name", "children"],
required: ["id", "name", "children"],
additionalProperties: false,
},
},
},
required: ["name", "children"],
required: ["id", "name", "children"],
additionalProperties: false,
},
},
},
required: ["name", "children"],
required: ["id", "name", "children"],
additionalProperties: false,
},
},
},
required: ["name", "children"],
required: ["id", "name", "children"],
additionalProperties: false,
});
};
4 changes: 2 additions & 2 deletions test/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
],
"info": {
"version": "1.1.1-dev.20241008-2",
"version": "2.0.0-dev.20241111-3",
"title": "@samchon/openapi",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",
"license": {
Expand Down Expand Up @@ -275,7 +275,6 @@
},
"/{index}/{level}/{optimal}/multipart": {
"post": {
"deprecated": true,
"tags": [],
"parameters": [
{
Expand Down Expand Up @@ -377,6 +376,7 @@
},
"/nothing": {
"get": {
"deprecated": true,
"tags": [],
"parameters": [],
"responses": {
Expand Down