diff --git a/src/HttpLlm.ts b/src/HttpLlm.ts index 7514858e..0633cda8 100644 --- a/src/HttpLlm.ts +++ b/src/HttpLlm.ts @@ -4,7 +4,6 @@ import { OpenApiV3 } from "./OpenApiV3"; import { OpenApiV3_1 } from "./OpenApiV3_1"; import { SwaggerV2 } from "./SwaggerV2"; import { HttpLlmComposer } from "./composers/HttpLlmApplicationComposer"; -import { LlmSchemaComposer } from "./composers/LlmSchemaComposer"; import { HttpLlmFunctionFetcher } from "./http/HttpLlmFunctionFetcher"; import { IHttpConnection } from "./structures/IHttpConnection"; import { IHttpLlmApplication } from "./structures/IHttpLlmApplication"; @@ -12,7 +11,6 @@ import { IHttpLlmFunction } from "./structures/IHttpLlmFunction"; import { IHttpMigrateApplication } from "./structures/IHttpMigrateApplication"; import { IHttpResponse } from "./structures/IHttpResponse"; import { ILlmFunction } from "./structures/ILlmFunction"; -import { ILlmSchema } from "./structures/ILlmSchema"; import { LlmDataMerger } from "./utils/LlmDataMerger"; /** @@ -30,11 +28,10 @@ import { LlmDataMerger } from "./utils/LlmDataMerger"; * {@link HttpLlm.propagate HttpLlm.propagate()}. * * By the way, if you have configured the - * {@link IHttpLlmApplication.IOptions.separate} option to separate the - * parameters into human and LLM sides, you can merge these human and LLM sides' - * parameters into one through - * {@link HttpLlm.mergeParameters HttpLlm.mergeParameters()} before the actual - * LLM function call execution. + * {@link IHttpLlmApplication.IConfig.separate} option to separate the parameters + * into human and LLM sides, you can merge these human and LLM sides' parameters + * into one through {@link HttpLlm.mergeParameters HttpLlm.mergeParameters()} + * before the actual LLM function call execution. * * @author Jeongho Nam - https://github.com/samchon */ @@ -42,15 +39,8 @@ export namespace HttpLlm { /* ----------------------------------------------------------- COMPOSERS ----------------------------------------------------------- */ - /** - * Properties for the LLM function calling application composer. - * - * @template Model Target LLM model - */ - export interface IApplicationProps { - /** Target LLM model. */ - model: Model; - + /** Properties for the LLM function calling application composer. */ + export interface IApplicationProps { /** OpenAPI document to convert. */ document: | OpenApi.IDocument @@ -58,8 +48,8 @@ export namespace HttpLlm { | OpenApiV3.IDocument | OpenApiV3_1.IDocument; - /** Options for the LLM function calling schema conversion. */ - options?: Partial>; + /** Configuration for the LLM function calling schema conversion. */ + config?: Partial; } /** @@ -72,44 +62,31 @@ export namespace HttpLlm { * converted to the {@link IHttpLlmFunction LLM function} type, and they would * be used for the LLM function calling. * - * If you have configured the {@link IHttpLlmApplication.IOptions.separate} + * If you have configured the {@link IHttpLlmApplication.IConfig.separate} * option, every parameters in the {@link IHttpLlmFunction} would be separated * into both human and LLM sides. In that case, you can merge these human and * LLM sides' parameters into one through {@link HttpLlm.mergeParameters} * before the actual LLM function call execution. * - * Additionally, if you have configured the - * {@link IHttpLlmApplication.IOptions.keyword} as `true`, the number of - * {@link IHttpLlmFunction.parameters} are always 1 and the first parameter - * type is always {@link ILlmSchemaV3.IObject}. I recommend this option because - * LLM can understand the keyword arguments more easily. - * * @param props Properties for composition * @returns LLM function calling application */ - export const application = ( - props: IApplicationProps, - ): IHttpLlmApplication => { + export const application = ( + props: IApplicationProps, + ): IHttpLlmApplication => { // MIGRATE const migrate: IHttpMigrateApplication = HttpMigration.application( props.document, ); - const defaultConfig: ILlmSchema.IConfig = - LlmSchemaComposer.defaultConfig(props.model); - return HttpLlmComposer.application({ + return HttpLlmComposer.application({ migrate, - model: props.model, - options: { - ...Object.fromEntries( - Object.entries(defaultConfig).map( - ([key, value]) => - [key, (props.options as any)?.[key] ?? value] as const, - ), - ), - separate: props.options?.separate ?? null, - maxLength: props.options?.maxLength ?? 64, - equals: props.options?.equals ?? false, - } as any as IHttpLlmApplication.IOptions, + config: { + reference: props.config?.reference ?? true, + strict: props.config?.strict ?? false, + separate: props.config?.separate ?? null, + maxLength: props.config?.maxLength ?? 64, + equals: props.config?.equals ?? false, + }, }); }; @@ -117,12 +94,12 @@ export namespace HttpLlm { FETCHERS ----------------------------------------------------------- */ /** Properties for the LLM function call. */ - export interface IFetchProps { + export interface IFetchProps { /** Application of the LLM function calling. */ - application: IHttpLlmApplication; + application: IHttpLlmApplication; /** LLM function schema to call. */ - function: IHttpLlmFunction; + function: IHttpLlmFunction; /** Connection info to the HTTP server. */ connection: IHttpConnection; @@ -140,16 +117,12 @@ export namespace HttpLlm { * sometimes). * * By the way, if you've configured the - * {@link IHttpLlmApplication.IOptions.separate}, so that the parameters are - * separated to human and LLM sides, you have to merge these humand and LLM + * {@link IHttpLlmApplication.IConfig.separate}, so that the parameters are + * separated to human and LLM sides, you have to merge these human and LLM * sides' parameters into one through {@link HttpLlm.mergeParameters} * function. * - * About the {@link IHttpLlmApplication.IOptions.keyword} option, don't worry - * anything. This `HttmLlm.execute()` function will automatically recognize - * the keyword arguments and convert them to the proper sequence. - * - * For reference, if the target API endpoinnt responds none 200/201 status, + * For reference, if the target API endpoint responds none 200/201 status, * this would be considered as an error and the {@link HttpError} would be * thrown. Otherwise you don't want such rule, you can use the * {@link HttpLlm.propagate} function instead. @@ -158,9 +131,8 @@ export namespace HttpLlm { * @returns Return value (response body) from the API endpoint * @throws HttpError when the API endpoint responds none 200/201 status */ - export const execute = ( - props: IFetchProps, - ): Promise => HttpLlmFunctionFetcher.execute(props); + export const execute = (props: IFetchProps): Promise => + HttpLlmFunctionFetcher.execute(props); /** * Propagate the LLM function call. @@ -171,15 +143,11 @@ export namespace HttpLlm { * sometimes). * * By the way, if you've configured the - * {@link IHttpLlmApplication.IOptions.separate}, so that the parameters are + * {@link IHttpLlmApplication.IConfig.separate}, so that the parameters are * separated to human and LLM sides, you have to merge these humand and LLM * sides' parameters into one through {@link HttpLlm.mergeParameters} * function. * - * About the {@link IHttpLlmApplication.IOptions.keyword} option, don't worry - * anything. This `HttmLlm.propagate()` function will automatically recognize - * the keyword arguments and convert them to the proper sequence. - * * For reference, the propagation means always returning the response from the * API endpoint, even if the status is not 200/201. This is useful when you * want to handle the response by yourself. @@ -188,17 +156,16 @@ export namespace HttpLlm { * @returns Response from the API endpoint * @throws Error only when the connection is failed */ - export const propagate = ( - props: IFetchProps, - ): Promise => HttpLlmFunctionFetcher.propagate(props); + export const propagate = (props: IFetchProps): Promise => + HttpLlmFunctionFetcher.propagate(props); /* ----------------------------------------------------------- MERGERS ----------------------------------------------------------- */ /** Properties for the parameters' merging. */ - export interface IMergeProps { + export interface IMergeProps { /** Metadata of the target function. */ - function: ILlmFunction; + function: ILlmFunction; /** Arguments composed by the LLM. */ llm: object | null; @@ -210,22 +177,21 @@ export namespace HttpLlm { /** * Merge the parameters. * - * If you've configured the {@link IHttpLlmApplication.IOptions.separate} + * If you've configured the {@link IHttpLlmApplication.IConfig.separate} * option, so that the parameters are separated to human and LLM sides, you * can merge these humand and LLM sides' parameters into one through this * `HttpLlm.mergeParameters()` function before the actual LLM function call - * wexecution. + * execution. * * On contrary, if you've not configured the - * {@link IHttpLlmApplication.IOptions.separate} option, this function would + * {@link IHttpLlmApplication.IConfig.separate} option, this function would * throw an error. * * @param props Properties for the parameters' merging * @returns Merged parameter values */ - export const mergeParameters = ( - props: IMergeProps, - ): object => LlmDataMerger.parameters(props); + export const mergeParameters = (props: IMergeProps): object => + LlmDataMerger.parameters(props); /** * Merge two values. diff --git a/src/McpLlm.ts b/src/McpLlm.ts index c0e958cc..48799534 100644 --- a/src/McpLlm.ts +++ b/src/McpLlm.ts @@ -29,15 +29,8 @@ import { OpenApiValidator } from "./utils/OpenApiValidator"; * @author Jeongho Nam - https://github.com/samchon */ export namespace McpLlm { - /** - * Properties for the LLM function calling application composer. - * - * @template Model Target LLM model - */ - export interface IApplicationProps { - /** Target LLM model. */ - model: Model; - + /** Properties for the LLM function calling application composer. */ + export interface IApplicationProps { /** * List of tools. * @@ -49,8 +42,8 @@ export namespace McpLlm { */ tools: Array; - /** Options for the LLM function calling schema conversion. */ - options?: Partial>; + /** Configuration for the LLM function calling schema conversion. */ + config?: Partial; } /** @@ -72,19 +65,14 @@ export namespace McpLlm { * @param props Properties for composition * @returns LLM function calling application */ - export const application = ( - props: IApplicationProps, - ): IMcpLlmApplication => { - const options: IMcpLlmApplication.IOptions = { - ...Object.fromEntries( - Object.entries(LlmSchemaComposer.defaultConfig(props.model)).map( - ([key, value]) => - [key, (props.options as any)?.[key] ?? value] as const, - ), - ), - maxLength: props.options?.maxLength ?? 64, - } as IMcpLlmApplication.IOptions; - const functions: IMcpLlmFunction[] = []; + export const application = (props: IApplicationProps): IMcpLlmApplication => { + const config: IMcpLlmApplication.IConfig = { + reference: props.config?.reference ?? true, + strict: props.config?.strict ?? false, + maxLength: props.config?.maxLength ?? 64, + equals: props.config?.equals ?? false, + }; + const functions: IMcpLlmFunction[] = []; const errors: IMcpLlmApplication.IError[] = []; props.tools.forEach((tool, i) => { @@ -114,17 +102,15 @@ export namespace McpLlm { } // CONVERT TO LLM PARAMETERS - const parameters: IResult< - ILlmSchema.IParameters, - IOpenApiSchemaError - > = LlmSchemaComposer.parameters(props.model)({ - config: options as any, - components, - schema: schema as - | OpenApi.IJsonSchema.IObject - | OpenApi.IJsonSchema.IReference, - accessor: `$input.tools[${i}].inputSchema`, - }) as IResult, IOpenApiSchemaError>; + const parameters: IResult = + LlmSchemaComposer.parameters({ + config, + components, + schema: schema as + | OpenApi.IJsonSchema.IObject + | OpenApi.IJsonSchema.IReference, + accessor: `$input.tools[${i}].inputSchema`, + }); if (parameters.success) functions.push({ name: tool.name, @@ -134,7 +120,7 @@ export namespace McpLlm { components, schema, required: true, - equals: options.equals, + equals: config.equals, }), }); else @@ -149,9 +135,8 @@ export namespace McpLlm { }); }); return { - model: props.model, functions, - options, + config, errors, }; }; diff --git a/src/composers/HttpLlmApplicationComposer.ts b/src/composers/HttpLlmApplicationComposer.ts index 807093ad..55bb9e6b 100644 --- a/src/composers/HttpLlmApplicationComposer.ts +++ b/src/composers/HttpLlmApplicationComposer.ts @@ -3,7 +3,6 @@ import { IHttpLlmApplication } from "../structures/IHttpLlmApplication"; import { IHttpLlmFunction } from "../structures/IHttpLlmFunction"; import { IHttpMigrateApplication } from "../structures/IHttpMigrateApplication"; import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute"; -import { ILlmFunction } from "../structures/ILlmFunction"; import { ILlmSchema } from "../structures/ILlmSchema"; import { IOpenApiSchemaError } from "../structures/IOpenApiSchemaError"; import { IResult } from "../structures/IResult"; @@ -11,12 +10,18 @@ import { OpenApiValidator } from "../utils/OpenApiValidator"; import { LlmSchemaComposer } from "./LlmSchemaComposer"; export namespace HttpLlmComposer { - export const application = (props: { - model: Model; + export const application = (props: { migrate: IHttpMigrateApplication; - options: IHttpLlmApplication.IOptions; - }): IHttpLlmApplication => { + config?: Partial; + }): IHttpLlmApplication => { // COMPOSE FUNCTIONS + const config: IHttpLlmApplication.IConfig = { + separate: props.config?.separate ?? null, + maxLength: props.config?.maxLength ?? 64, + equals: props.config?.equals ?? false, + reference: props.config?.reference ?? true, + strict: props.config?.strict ?? false, + }; const errors: IHttpLlmApplication.IError[] = props.migrate.errors .filter((e) => e.operation()["x-samchon-human"] !== true) .map((e) => ({ @@ -26,7 +31,7 @@ export namespace HttpLlmComposer { operation: () => e.operation(), route: () => undefined, })); - const functions: IHttpLlmFunction[] = props.migrate.routes + const functions: IHttpLlmFunction[] = props.migrate.routes .filter((e) => e.operation()["x-samchon-human"] !== true) .map((route, i) => { if (route.method === "head") { @@ -54,11 +59,10 @@ export namespace HttpLlmComposer { return null; } const localErrors: string[] = []; - const func: IHttpLlmFunction | null = composeFunction({ - model: props.model, - config: props.options, + const func: IHttpLlmFunction | null = composeFunction({ components: props.migrate.document().components, - route: route, + config, + route, errors: localErrors, index: i, }); @@ -72,26 +76,24 @@ export namespace HttpLlmComposer { }); return func; }) - .filter((v): v is IHttpLlmFunction => v !== null); + .filter((v): v is IHttpLlmFunction => v !== null); - const app: IHttpLlmApplication = { - model: props.model, - options: props.options, + const app: IHttpLlmApplication = { + config, functions, errors, }; - shorten(app, props.options?.maxLength ?? 64); + shorten(app, props.config?.maxLength ?? 64); return app; }; - const composeFunction = (props: { - model: Model; + const composeFunction = (props: { components: OpenApi.IComponents; route: IHttpMigrateRoute; - config: IHttpLlmApplication.IOptions; + config: IHttpLlmApplication.IConfig; errors: string[]; index: number; - }): IHttpLlmFunction | null => { + }): IHttpLlmFunction | null => { // METADATA const endpoint: string = `$input.paths[${JSON.stringify(props.route.path)}][${JSON.stringify(props.route.method)}]`; const operation: OpenApi.IOperation = props.route.operation(); @@ -173,29 +175,25 @@ export namespace HttpLlmComposer { }; parameters.required = Object.keys(parameters.properties ?? {}); - const llmParameters: IResult< - ILlmSchema.IParameters, - IOpenApiSchemaError - > = LlmSchemaComposer.parameters(props.model)({ - config: props.config as any, - components: props.components, - schema: parameters, - accessor: `${endpoint}.parameters`, - }) as IResult, IOpenApiSchemaError>; + const llmParameters: IResult = + LlmSchemaComposer.parameters({ + config: props.config, + components: props.components, + schema: parameters, + accessor: `${endpoint}.parameters`, + }); // RETURN VALUE - const output: IResult, IOpenApiSchemaError> | undefined = - props.route.success - ? (LlmSchemaComposer.schema(props.model)({ - config: props.config as any, - components: props.components, - schema: props.route.success.schema, - accessor: `${endpoint}.responses[${JSON.stringify(props.route.success.status)}][${JSON.stringify(props.route.success.type)}].schema`, - $defs: llmParameters.success - ? (llmParameters.value as any).$defs! - : {}, - }) as IResult, IOpenApiSchemaError>) - : undefined; + const output: IResult | undefined = props + .route.success + ? LlmSchemaComposer.schema({ + config: props.config, + components: props.components, + schema: props.route.success.schema, + accessor: `${endpoint}.responses[${JSON.stringify(props.route.success.status)}][${JSON.stringify(props.route.success.type)}].schema`, + $defs: llmParameters.success ? llmParameters.value.$defs : {}, + }) + : undefined; //---- // CONVERSION @@ -229,12 +227,11 @@ export namespace HttpLlmComposer { name, parameters: llmParameters.value, separated: props.config.separate - ? (LlmSchemaComposer.separate(props.model)({ - predicate: props.config.separate as any, - parameters: - llmParameters.value satisfies ILlmSchema.ModelParameters[Model] as any, + ? LlmSchemaComposer.separate({ + predicate: props.config.separate, + parameters: llmParameters.value, equals: props.config.equals ?? false, - }) as ILlmFunction.ISeparated) + }) : undefined, output: output?.value, description: description[0], @@ -251,12 +248,12 @@ export namespace HttpLlmComposer { }; }; - export const shorten = ( - app: IHttpLlmApplication, + export const shorten = ( + app: IHttpLlmApplication, limit: number = 64, ): void => { const dictionary: Set = new Set(); - const longFunctions: IHttpLlmFunction[] = []; + const longFunctions: IHttpLlmFunction[] = []; for (const func of app.functions) { dictionary.add(func.name); if (func.name.length > limit) { diff --git a/src/http/HttpLlmFunctionFetcher.ts b/src/http/HttpLlmFunctionFetcher.ts index 9e91a533..25d400a5 100644 --- a/src/http/HttpLlmFunctionFetcher.ts +++ b/src/http/HttpLlmFunctionFetcher.ts @@ -2,25 +2,20 @@ import type { HttpLlm } from "../HttpLlm"; import type { HttpMigration } from "../HttpMigration"; import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute"; import { IHttpResponse } from "../structures/IHttpResponse"; -import { ILlmSchema } from "../structures/ILlmSchema"; import { HttpMigrateRouteFetcher } from "./HttpMigrateRouteFetcher"; export namespace HttpLlmFunctionFetcher { - export const execute = ( - props: HttpLlm.IFetchProps, - ): Promise => - HttpMigrateRouteFetcher.execute(getFetchArguments("execute", props)); + export const execute = (props: HttpLlm.IFetchProps): Promise => + HttpMigrateRouteFetcher.execute(getFetchArguments("execute", props)); - export const propagate = ( - props: HttpLlm.IFetchProps, + export const propagate = ( + props: HttpLlm.IFetchProps, ): Promise => - HttpMigrateRouteFetcher.propagate( - getFetchArguments("propagate", props), - ); + HttpMigrateRouteFetcher.propagate(getFetchArguments("propagate", props)); - const getFetchArguments = ( + const getFetchArguments = ( from: string, - props: HttpLlm.IFetchProps, + props: HttpLlm.IFetchProps, ): HttpMigration.IFetchProps => { const route: IHttpMigrateRoute = props.function.route(); const input: Record = props.input; diff --git a/src/structures/IHttpLlmApplication.ts b/src/structures/IHttpLlmApplication.ts index ba64ce2d..c1431ec6 100644 --- a/src/structures/IHttpLlmApplication.ts +++ b/src/structures/IHttpLlmApplication.ts @@ -11,8 +11,8 @@ import { ILlmSchema } from "./ILlmSchema"; * {@link OpenApi.IDocument OpenAPI document} and its * {@link OpenApi.IOperation operation} metadata. It also contains * {@link IHttpLlmApplication.errors failed operations}, and adjusted - * {@link IHttpLlmApplication.options options} during the `IHttpLlmApplication` - * construction. + * {@link IHttpLlmApplication.config configuration} during the + * `IHttpLlmApplication` construction. * * About the {@link OpenApi.IOperation API operations}, they are converted to * {@link IHttpLlmFunction} type which represents LLM function calling schema. By @@ -40,7 +40,7 @@ import { ILlmSchema } from "./ILlmSchema"; * must be composed by Human, not by LLM. File uploading feature or some * sensitive information like secret key (password) are the examples. In that * case, you can separate the function parameters to both LLM and Human sides by - * configuring the {@link IHttpLlmApplication.IOptions.separate} property. The + * configuring the {@link IHttpLlmApplication.IConfig.separate} property. The * separated parameters are assigned to the {@link IHttpLlmFunction.separated} * property. * @@ -51,7 +51,7 @@ import { ILlmSchema } from "./ILlmSchema"; * continue the next conversation based on the return value. * * Additionally, if you've configured - * {@link IHttpLlmApplication.IOptions.separate}, so that the parameters are + * {@link IHttpLlmApplication.IConfig.separate}, so that the parameters are * separated to Human and LLM sides, you can merge these human and LLM sides' * parameters into one through {@link HttpLlm.mergeParameters} before the actual * LLM function call execution. @@ -73,11 +73,11 @@ export interface IHttpLlmApplication { errors: IHttpLlmApplication.IError[]; /** Configuration for the application. */ - options: IHttpLlmApplication.IOptions; + config: IHttpLlmApplication.IConfig; } export namespace IHttpLlmApplication { - /** Options for the HTTP LLM application schema composition. */ - export interface IOptions extends ILlmSchema.IConfig { + /** Configuration for the HTTP LLM application schema composition. */ + export interface IConfig extends ILlmSchema.IConfig { /** * Separator function for the parameters. * @@ -106,7 +106,7 @@ export namespace IHttpLlmApplication { * @param schema Schema to be separated. * @returns Whether the schema value must be composed by human or not. */ - separate?: null | ((schema: ILlmSchema) => boolean); + separate: null | ((schema: ILlmSchema) => boolean); /** * Maximum length of function name. @@ -118,10 +118,14 @@ export namespace IHttpLlmApplication { * * @default 64 */ - maxLength?: number; + maxLength: number; - /** Whether to disallow superfluous properties or not. */ - equals?: boolean; + /** + * Whether to disallow superfluous properties or not. + * + * @default false + */ + equals: boolean; } /** Error occurred in the composition. */ diff --git a/src/structures/IHttpLlmFunction.ts b/src/structures/IHttpLlmFunction.ts index 25fc3989..d789eb68 100644 --- a/src/structures/IHttpLlmFunction.ts +++ b/src/structures/IHttpLlmFunction.ts @@ -87,7 +87,7 @@ export interface IHttpLlmFunction { /** * List of parameter types. * - * If you've configured {@link IHttpLlmApplication.IOptions.keyword} as `true`, + * If you've configured {@link IHttpLlmApplication.IConfig.keyword} as `true`, * number of {@link IHttpLlmFunction.parameters} are always 1 and the first * parameter's type is always {@link ILlmSchema.IObject}. The properties' * rule is: @@ -120,8 +120,7 @@ export interface IHttpLlmFunction { /** * Collection of separated parameters. * - * Filled only when {@link IHttpLlmApplication.IOptions.separate} is - * configured. + * Filled only when {@link IHttpLlmApplication.IConfig.separate} is configured. */ separated?: IHttpLlmFunction.ISeparated; diff --git a/src/structures/ILlmApplication.ts b/src/structures/ILlmApplication.ts index 2b2b7b01..de55f8f8 100644 --- a/src/structures/ILlmApplication.ts +++ b/src/structures/ILlmApplication.ts @@ -14,15 +14,15 @@ import { IValidation } from "./IValidation"; * composed by Human, not by LLM. File uploading feature or some sensitive * information like secret key (password) are the examples. In that case, you * can separate the function parameters to both LLM and human sides by - * configuring the {@link ILlmApplication.IOptions.separate} property. The + * configuring the {@link ILlmApplication.IConfig.separate} property. The * separated parameters are assigned to the {@link ILlmFunction.separated} * property. * * For reference, when both LLM and Human filled parameter values to call, you * can merge them by calling the {@link HttpLlm.mergeParameters} function. In - * other words, if you've configured the - * {@link ILlmApplication.IOptions.separate} property, you have to merge the - * separated parameters before the function call execution. + * other words, if you've configured the {@link ILlmApplication.IConfig.separate} + * property, you have to merge the separated parameters before the function call + * execution. * * @author Jeongho Nam - https://github.com/samchon * @reference https://platform.openai.com/docs/guides/function-calling @@ -36,7 +36,7 @@ export interface ILlmApplication { functions: ILlmFunction[]; /** Configuration for the application. */ - options: ILlmApplication.IOptions; + config: ILlmApplication.IConfig; /** * Class type, the source of the LLM application. @@ -47,8 +47,8 @@ export interface ILlmApplication { __class?: Class | undefined; } export namespace ILlmApplication { - /** Options for application composition. */ - export interface IOptions + /** Configuration for application composition. */ + export interface IConfig extends ILlmSchema.IConfig { /** * Separator function for the parameters. @@ -78,7 +78,7 @@ export namespace ILlmApplication { * @param schema Schema to be separated. * @returns Whether the schema value must be composed by human or not. */ - separate?: null | ((schema: ILlmSchema) => boolean); + separate: null | ((schema: ILlmSchema) => boolean); /** * Custom validation functions for specific class methods. @@ -104,7 +104,7 @@ export namespace ILlmApplication { * * @default null */ - validate?: null | Partial>; + validate: null | Partial>; } /** diff --git a/src/structures/ILlmFunction.ts b/src/structures/ILlmFunction.ts index 74f248c5..55e69030 100644 --- a/src/structures/ILlmFunction.ts +++ b/src/structures/ILlmFunction.ts @@ -37,7 +37,7 @@ export interface ILlmFunction { /** * Collection of separated parameters. * - * Filled only when {@link ILlmApplication.IOptions.separate} is configured. + * Filled only when {@link ILlmApplication.IConfig.separate} is configured. */ separated?: ILlmFunction.ISeparated; diff --git a/src/structures/IMcpLlmApplication.ts b/src/structures/IMcpLlmApplication.ts index 6d12120f..fa191557 100644 --- a/src/structures/IMcpLlmApplication.ts +++ b/src/structures/IMcpLlmApplication.ts @@ -8,7 +8,7 @@ import { IMcpLlmFunction } from "./IMcpLlmFunction"; * {@link IMcpLlmFunction LLM function calling schemas} composed from the MCP * (Model Context Protocol) document. It contains * {@link IMcpLlmApplication.errors failed functions}, and adjusted - * {@link IMcpLlmApplication.options options} during the `IMcpLlmApplication` + * {@link IMcpLlmApplication.config options} during the `IMcpLlmApplication` * construction. * * About each function of MCP server, there can be {@link errors} during the @@ -39,11 +39,11 @@ export interface IMcpLlmApplication { errors: IMcpLlmApplication.IError[]; /** Configuration for the application. */ - options: IMcpLlmApplication.IOptions; + config: IMcpLlmApplication.IConfig; } export namespace IMcpLlmApplication { - /** Options for the MCP LLM application schema composition. */ - export interface IOptions extends ILlmSchema.IConfig { + /** Configuration for the HTTP LLM application schema composition. */ + export interface IConfig extends ILlmSchema.IConfig { /** * Maximum length of function name. * @@ -54,10 +54,10 @@ export namespace IMcpLlmApplication { * * @default 64 */ - maxLength?: number; + maxLength: number; /** Whether to disallow superfluous properties or not. */ - equals?: boolean; + equals: boolean; } /** Error occurred in the composition. */ diff --git a/src/utils/LlmDataMerger.ts b/src/utils/LlmDataMerger.ts index 5fc19eda..4145ca67 100644 --- a/src/utils/LlmDataMerger.ts +++ b/src/utils/LlmDataMerger.ts @@ -1,5 +1,4 @@ import { ILlmFunction } from "../structures/ILlmFunction"; -import { ILlmSchema } from "../structures/ILlmSchema"; /** * Data combiner for LLM function call. @@ -8,9 +7,9 @@ import { ILlmSchema } from "../structures/ILlmSchema"; */ export namespace LlmDataMerger { /** Properties of {@link parameters} function. */ - export interface IProps { + export interface IProps { /** Target function to call. */ - function: ILlmFunction; + function: ILlmFunction; /** Arguments composed by LLM (Large Language Model). */ llm: object | null; @@ -22,25 +21,23 @@ export namespace LlmDataMerger { /** * Combine LLM and human arguments into one. * - * When you composes {@link IOpenAiDocument} with - * {@link IOpenAiDocument.IOptions.separate} option, then the arguments of the - * target function would be separated into two parts; LLM (Large Language + * When you compose {@link IHttpLlmApplication} with + * {@link IHttpLlmApplication.IConfig.separate} option, then the arguments of + * the target function would be separated into two parts; LLM (Large Language * Model) and human. * * In that case, you can combine both LLM and human composed arguments into * one by utilizing this {@link LlmDataMerger.parameters} function, referencing - * the target function metadata {@link IOpenAiFunction.separated}. + * the target function metadata {@link ILlmFunction.separated}. * * @param props Properties to combine LLM and human arguments with metadata. * @returns Combined arguments */ - export const parameters = ( - props: IProps, - ): object => { + export const parameters = (props: IProps): object => { const separated = props.function.separated; if (separated === undefined) throw new Error( - "Error on OpenAiDataComposer.parameters(): the function parameters are not separated.", + "Error on LlmDataMerger.parameters(): the function parameters are not separated.", ); return value(props.llm, props.human) as object; };