Skip to content

Commit

Permalink
Testing LLM functions
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Sep 2, 2024
1 parent 4805d4b commit 1ce5c7b
Show file tree
Hide file tree
Showing 35 changed files with 1,150 additions and 574 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ lib/
node_modules/

package-lock.json
pnpm-lock.yaml
pnpm-lock.yaml
*.log
76 changes: 76 additions & 0 deletions src/HttpLanguageModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { HttpMigration } from "./HttpMigration";
import { OpenApi } from "./OpenApi";
import { LlmComposer } from "./converters/LlmComposer";
import { LlmMerger } from "./converters/LlmMerger";
import { HttpLlmFunctionFetcher } from "./http/HttpLlmFunctionFetcher";
import { IHttpConnection } from "./structures/IHttpConnection";
import { IHttpLlmApplication } from "./structures/IHttpLlmApplication";
import { IHttpLlmFunction } from "./structures/IHttpLlmFunction";
import { IHttpMigrateApplication } from "./structures/IHttpMigrateApplication";
import { IHttpResponse } from "./structures/IHttpResponse";
import { ILlmSchema } from "./structures/ILlmSchema";

export namespace HttpLanguageModel {
export const application = <
Schema extends ILlmSchema,
Operation extends OpenApi.IOperation,
>(
document:
| OpenApi.IDocument<any, Operation>
| IHttpMigrateApplication<any, Operation>,
options?: Partial<IHttpLlmApplication.IOptions>,
): IHttpLlmApplication<Schema> => {
// MIGRATE
if ((document as OpenApi.IDocument)["x-samchon-emended"] === true)
document = HttpMigration.application(
document as OpenApi.IDocument<any, Operation>,
);
return LlmComposer.compose(
document as IHttpMigrateApplication<any, Operation>,
{
keyword: options?.keyword ?? false,
separate: options?.separate ?? null,
},
);
};

export const schema = (props: {
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
}): ILlmSchema | null => LlmComposer.schema(props);

export interface IExecutionProps {
/**
* Document of the OpenAI function call schemas.
*/
document: IHttpLlmApplication;

/**
* Procedure schema to call.
*/
procedure: IHttpLlmFunction;

/**
* Connection info to the server.
*/
connection: IHttpConnection;

/**
* Arguments for the function call.
*/
arguments: any[];
}
export const execute = (props: IExecutionProps): Promise<unknown> =>
HttpLlmFunctionFetcher.execute(props);

export const propagate = (props: IExecutionProps): Promise<IHttpResponse> =>
HttpLlmFunctionFetcher.propagate(props);

export interface IMergeProps {
function: IHttpLlmFunction;
llm: unknown[];
human: unknown[];
}
export const merge = (props: IMergeProps): unknown[] =>
LlmMerger.parameters(props);
}
31 changes: 31 additions & 0 deletions src/HttpMigration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { OpenApi } from "./OpenApi";
import { MigrateConverter } from "./converters/MigrateConverter";
import { HttpMigrateRouteFetcher } from "./http/HttpMigrateRouteFetcher";
import { IHttpConnection } from "./structures/IHttpConnection";
import { IHttpMigrateApplication } from "./structures/IHttpMigrateApplication";
import { IHttpMigrateRoute } from "./structures/IHttpMigrateRoute";
import { IHttpResponse } from "./structures/IHttpResponse";

export namespace HttpMigration {
export const application = <
Schema extends OpenApi.IJsonSchema = OpenApi.IJsonSchema,
Operation extends OpenApi.IOperation<Schema> = OpenApi.IOperation<Schema>,
>(
document: OpenApi.IDocument<Schema, Operation>,
): IHttpMigrateApplication<Schema, Operation> =>
MigrateConverter.convert(document);

export interface IProps {
connection: IHttpConnection;
route: IHttpMigrateRoute;
parameters:
| Array<string | number | boolean | bigint | null>
| Record<string, string | number | boolean | bigint | null>;
query?: object | undefined;
body?: object | undefined;
}
export const request = (props: IProps): Promise<unknown> =>
HttpMigrateRouteFetcher.request(props);
export const propagate = (props: IProps): Promise<IHttpResponse> =>
HttpMigrateRouteFetcher.propagate(props);
}
37 changes: 1 addition & 36 deletions src/OpenApi.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { OpenApiV3 } from "./OpenApiV3";
import { OpenApiV3_1 } from "./OpenApiV3_1";
import { SwaggerV2 } from "./SwaggerV2";
import { LlmComposer } from "./converters/LlmComposer";
import { MigrateConverter } from "./converters/MigrateConverter";
import { OpenApiV3Converter } from "./converters/OpenApiV3Converter";
import { OpenApiV3Downgrader } from "./converters/OpenApiV3Downgrader";
import { OpenApiV3_1Converter } from "./converters/OpenApiV3_1Converter";
import { SwaggerV2Converter } from "./converters/SwaggerV2Converter";
import { SwaggerV2Downgrader } from "./converters/SwaggerV2Downgrader";
import { IHttpLlmApplication } from "./structures/IHttpLlmApplication";
import { IHttpMigrateApplication } from "./structures/IHttpMigrateApplication";

/**
* Emended OpenAPI v3.1 definition used by `typia` and `nestia`.
Expand Down Expand Up @@ -136,37 +132,6 @@ export namespace OpenApi {
throw new TypeError("Unrecognized Swagger/OpenAPI version.");
}

/**
* Convert to migrate document.
*
* Convert the given OpenAPI document to {@link IHttpMigrateApplication}, that is
* useful for OpenAPI generator library which makes RPC (Remote Procedure Call)
* functions for the Restful API operation.
*
* @param document OpenAPI document to migrate
* @returns Migrated document
*/
export function migrate<
Schema extends IJsonSchema = IJsonSchema,
Operation extends IOperation<Schema> = IOperation<Schema>,
>(
document: IDocument<Schema, Operation>,
): IHttpMigrateApplication<Schema, Operation> {
return MigrateConverter.convert(document);
}

export function llm(
document: OpenApi.IDocument | IHttpMigrateApplication,
options?: IHttpLlmApplication.IOptions,
): IHttpLlmApplication {
if ((document as OpenApi.IDocument)["x-samchon-emended"] !== true)
document = migrate(document as OpenApi.IDocument);
return LlmComposer.compose(document as IHttpMigrateApplication, {
keyword: options?.keyword ?? false,
separate: options?.separate ?? null,
});
}

/* -----------------------------------------------------------
PATH ITEMS
----------------------------------------------------------- */
Expand Down Expand Up @@ -1066,7 +1031,7 @@ export namespace OpenApi {
/**
* List of the union types.
*/
oneOf: Exclude<Schema, IJsonSchema.IOneOf>[];
oneOf: Exclude<Schema, IJsonSchema.IOneOf<Schema>>[];

/**
* Discriminator info of the union type.
Expand Down
Loading

0 comments on commit 1ce5c7b

Please sign in to comment.