Skip to content

Commit

Permalink
Merge pull request #12 from wrtnio/feat/test
Browse files Browse the repository at this point in the history
Revive legacy `IOpenAiSchema` type.
  • Loading branch information
samchon authored Dec 4, 2024
2 parents 4eadc2b + 56bad25 commit 5486814
Show file tree
Hide file tree
Showing 6 changed files with 631 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@wrtnio/schema",
"version": "2.0.2",
"version": "3.0.0",
"description": "JSON and LLM function calling schemas extended for Wrtn Studio Pro",
"main": "lib/index.js",
"module": "./lib/index.mjs",
"typings": "./lib/index.d.ts",
"scripts": {
"prepare": "ts-patch install",
"build": "npm run build:main",
"build": "npm run build:main && npm run build:test",
"build:main": "rimraf lib && tsc && rollup -c",
"build:test": "rimraf bin && tsc -p test/tsconfig.json",
"dev": "npm run build:test -- --watch",
Expand Down
5 changes: 3 additions & 2 deletions src/IHttpOpenAiApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import { ISwaggerOperation } from "./ISwaggerOperation";
* {@link ISwaggerSchema.IReference} type, the operation would be failed and
* pushed into the {@link IHttpOpenAiApplication.errors}. Otherwise not, the operation
* would be successfully converted to {@link IHttpOpenAiFunction} and its type schemas
* are downgraded to {@link OpenApiV3.IJsonSchema} and converted to {@link ILlmSchema}.
* are downgraded to {@link OpenApiV3.IJsonSchema} and converted to
* {@link IOpenAiSchema}.
*
* About the options, if you've configured {@link IHttpOpenAiApplication.options.keyword}
* (as `true`), number of {@link IHttpOpenAiFunction.parameters} are always 1 and the first
* parameter type is always {@link ILlmSchema.IObject}. Otherwise, the parameters would
* parameter type is always {@link IOpenAiSchema.IObject}. Otherwise, the parameters would
* be multiple, and the sequence of the parameters are following below rules.
*
* - `pathParameters`: Path parameters of {@link IHttpMigrateRoute.parameters}
Expand Down
51 changes: 49 additions & 2 deletions src/IHttpOpenAiFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { ISwaggerOperation } from "./ISwaggerOperation";
* @author Samchon
*/
export interface IHttpOpenAiFunction
extends Omit<IHttpLlmFunction<"3.0">, "parameters" | "separated"> {
extends Omit<IHttpLlmFunction<"3.0">, "parameters" | "separated" | "output"> {
/**
* List of parameter types.
*
Expand Down Expand Up @@ -91,6 +91,13 @@ export interface IHttpOpenAiFunction
*/
parameters: IOpenAiSchema[];

/**
* Expected return type.
*
* If the function returns nothing (`void`), then the output is `undefined`.
*/
output?: IOpenAiSchema | undefined;

/**
* Collection of separated parameters.
*
Expand All @@ -99,8 +106,48 @@ export interface IHttpOpenAiFunction
separated?: IHttpOpenAiFunction.ISeparated;
}
export namespace IHttpOpenAiFunction {
export interface IOptions extends IOpenAiSchema.IConfig {
export interface IOptions {
/**
* Separator function for the parameters.
*
* When composing parameter arguments through LLM function call,
* there can be a case that some parameters must be composed by human,
* or LLM cannot understand the parameter.
*
* For example, if the parameter type has configured
* {@link IOpenAiSchema.IString.contentMediaType} which indicates file
* uploading, it must be composed by human, not by LLM
* (Large Language Model).
*
* In that case, if you configure this property with a function that
* predicating whether the schema value must be composed by human or
* not, the parameters would be separated into two parts.
*
* - {@link IHttpOpenAiFunction.separated.llm}
* - {@link IHttpOpenAiFunction.separated.human}
*
* When writing the function, note that returning value `true` means
* to be a human composing the value, and `false` means to LLM
* composing the value. Also, when predicating the schema, it would
* better to utilize the {@link GeminiTypeChecker} like features.
*
* @param schema Schema to be separated.
* @returns Whether the schema value must be composed by human or not.
* @default null
*/
separate: null | ((schema: IOpenAiSchema) => boolean);

/**
* Whether to allow recursive types or not.
*
* If allow, then how many times to repeat the recursive types.
*
* By the way, if the model is "chatgpt", the recursive types are always
* allowed without any limitation, due to it supports the reference type.
*
* @default 3
*/
recursive: false | number;
}

/**
Expand Down
Loading

0 comments on commit 5486814

Please sign in to comment.