Interface IHttpLlmFunction<Model>

LLM function calling schema from HTTP (OpenAPI) operation.

IHttpLlmFunction is a data structure representing a function converted from the OpenAPI operation, used for the LLM (Large Language Model) function calling. It's a typical RPC (Remote Procedure Call) structure containing the function name, parameters, and return type.

If you provide this IHttpLlmFunction data to the LLM provider like "OpenAI", the "OpenAI" will compose a function arguments by analyzing conversations with the user. With the LLM composed arguments, you can execute the function through LlmFetcher.execute and get the result.

For reference, different between IHttpLlmFunction and its origin source OpenApi.IOperation is, IHttpLlmFunction has converted every type schema information from OpenApi.IJsonSchema to ILlmSchemaV3 to escape reference types, and downgrade the version of the JSON schema to OpenAPI 3.0. It's because LLM function call feature cannot understand both reference types and OpenAPI 3.1 specification.

Additionally, the properties' rule is:

{
...pathParameters,
query,
body,
}
interface IHttpLlmFunction<Model extends Model> {
    deprecated?: boolean;
    description?: string;
    method: "get" | "post" | "put" | "delete" | "patch";
    name: string;
    operation: () => OpenApi.IOperation;
    output?: ModelSchema[Model];
    parameters: ModelParameters[Model];
    path: string;
    route: () => IHttpMigrateRoute;
    separated?: IHttpLlmFunction.ISeparated<Model>;
    tags?: string[];
}

Type Parameters

Properties

deprecated?: boolean

Whether the function is deprecated or not.

If the deprecated is true, the function is not recommended to use.

LLM (Large Language Model) may not use the deprecated function.

description?: string

Description of the function.

IHttpLlmFunction.description is composed by below rule:

  1. Starts from the OpenApi.IOperation.summary paragraph.
  2. The next paragraphs are filled with the OpenApi.IOperation.description. By the way, if the first paragraph of OpenApi.IOperation.description is same with the OpenApi.IOperation.summary, it would not be duplicated.
  3. Parameters' descriptions are added with @param tag.
  4. Security requirements are added with @security tag.
  5. Tag names are added with @tag tag.
  6. If OpenApi.IOperation.deprecated, @deprecated tag is added.

For reference, the description is very important property to teach the purpose of the function to the LLM (Language Large Model), and LLM actually determines which function to call by the description.

Also, when the LLM conversates with the user, the description is used to explain the function to the user. Therefore, the description property has the highest priority, and you have to consider it.

method: "get" | "post" | "put" | "delete" | "patch"

HTTP method of the endpoint.

name: string

Representative name of the function.

The name is a repsentative name identifying the function in the IHttpLlmApplication. The name value is just composed by joining the IHttpMigrateRoute.accessor by underscore _ character.

Here is the composition rule of the IHttpMigrateRoute.accessor:

The accessor is composed with the following rules. At first, namespaces are composed by static directory names in the path. Parametric symbols represented by :param or {param} cannot be a part of the namespace.

Instead, they would be a part of the function name. The function name is composed with the HTTP method and parametric symbols like getByParam or postByParam. If there are multiple path parameters, they would be concatenated by And like getByParam1AndParam2.

For refefence, if the operation's method is delete, the function name would be replaced to erase instead of delete. It is the reason why the delete is a reserved keyword in many programming languages.

  • Example 1
    • path: POST /shopping/sellers/sales
    • accessor: shopping.sellers.sales.post
  • Example 2
    • endpoint: `GET /shoppings/sellers/sales/:saleId/reviews/:reviewId/comments/:id
    • accessor: shoppings.sellers.sales.reviews.getBySaleIdAndReviewIdAndCommentId

64

operation: () => OpenApi.IOperation

Get the Swagger operation metadata.

Get the Swagger operation metadata, of the source.

Type declaration

output?: ModelSchema[Model]

Expected return type.

If the target operation returns nothing (void), the output would be undefined.

parameters: ModelParameters[Model]

List of parameter types.

If you've configured IHttpLlmApplication.IOptions.keyword as true, number of IHttpLlmFunction.parameters are always 1 and the first parameter's type is always ILlmSchemaV3.IObject. The properties' rule is:

{
...pathParameters,
query,
body,
}

Otherwise, the parameters would be multiple, and the sequence of the parameters are following below rules:

[
...pathParameters,
...(query ? [query] : []),
...(body ? [body] : []),
]
path: string

Path of the endpoint.

route: () => IHttpMigrateRoute

Get the migration route metadata.

Get the migration route metadata, of the source.

Type declaration

Collection of separated parameters.

Filled only when IHttpLlmApplication.IOptions.separate is configured.

tags?: string[]

Category tags for the function.

Same with OpenApi.IOperation.tags indicating the category of the function.