Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
Merge pull request #17 from wrtnio/features/propagate
Browse files Browse the repository at this point in the history
Add `OpenAiFetcher.propagate()` function.
  • Loading branch information
samchon authored Jul 23, 2024
2 parents 1492881 + 970475b commit 1682a08
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wrtnio/openai-function-schema",
"version": "0.2.0",
"version": "0.2.1",
"description": "OpenAI LLM function schema from OpenAPI (Swagger) document",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -37,16 +37,16 @@
"author": "",
"license": "ISC",
"dependencies": {
"@nestia/fetcher": "^3.7.0",
"@nestia/fetcher": "^3.8.0",
"@samchon/openapi": "^0.4.2",
"commander": "^10.0.0",
"inquirer": "^8.2.5",
"typia": "^6.5.0"
"typia": "^6.5.4"
},
"devDependencies": {
"@nestia/core": "^3.7.0",
"@nestia/core": "^3.8.0",
"@nestia/e2e": "^0.7.0",
"@nestia/sdk": "^3.7.0",
"@nestia/sdk": "^3.8.0",
"@nestjs/common": "^10.3.10",
"@nestjs/core": "^10.3.10",
"@nestjs/platform-express": "^10.3.10",
Expand All @@ -63,7 +63,7 @@
"rollup": "^4.18.0",
"ts-node": "^10.9.2",
"ts-patch": "^3.2.1",
"typescript": "^5.5.3",
"typescript": "^5.5.4",
"typescript-transform-paths": "^3.4.7",
"uuid": "^10.0.0"
},
Expand Down
51 changes: 41 additions & 10 deletions src/OpenAiFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { IConnection } from "@nestia/fetcher";
import { IConnection, IPropagation } from "@nestia/fetcher";
import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher";
import { IMigrateRoute } from "@samchon/openapi";

import { IOpenAiDocument } from "./structures/IOpenAiDocument";
import { IOpenAiFunction } from "./structures/IOpenAiFunction";

/**
* Function call executor for OpenAI.
* Function call executors for OpenAI.
*
* `OpenAiFetcher` is a module for function call execution with target function's
* metadata {@link IOpenAiFunction} and OpenAI composed arguments.
Expand Down Expand Up @@ -47,23 +47,54 @@ export namespace OpenAiFetcher {
/**
* Execute the function call.
*
* `OpenAiFetcher.fetch()` is a function executing the target API endpoint with
* `OpenAiFetcher.execute()` is a function executing the target API endpoint with
* the operation's metadata {@link IOpenAiFunction} and OpenAI composed arguments.
*
* Also, `OpenAiFetcher.fetch()` is designed to consider
* Also, `OpenAiFetcher.execute()` is designed to consider
* {@link IOpenAiDocument.IOptions.keyword} option, so that it can unwrap the
* composed arguments into the function call arguments automatically.
*
* However, about the {@link IOpenAiDocument.IOptions.separate} case, you have
* to use {@link OpenAiDataCombiner.parameters} function to combine the LLM and
* human arguments into one, by yourself manually.
*
* @param props
* @returns
* @param props Function call properties.
* @returns Response of the function call.
*/
export const execute = async (props: IProps): Promise<any> => {
const route: IMigrateRoute = props.function.route();
return PlainFetcher.fetch(
export const execute = (props: IProps): Promise<any> =>
PlainFetcher.fetch(...getFetcherArguments(props));

/**
* Propagate the function call.
*
* `OpenAiFetcher.propagate()` is a function propagating the target API endpoint with
* the operation's metadata {@link IOpenAiFunction} and OpenAI composed arguments.
*
* Also, `OpenAiFetcher.execute()` is designed to consider
* {@link IOpenAiDocument.IOptions.keyword} option, so that it can unwrap the
* composed arguments into the function call arguments automatically.
*
* However, about the {@link IOpenAiDocument.IOptions.separate} case, you have
* to use {@link OpenAiDataCombiner.parameters} function to combine the LLM and
* human arguments into one, by yourself manually.
*
* > For reference, the propagation means always returning the response even if the
* > request is failled, with the response's status code. About detailed concept
* > of the propagation, refer to the {@link IPropagation} type.
*
* @param props Function call properties.
* @returns Propagation of the function call.
*/
export const propagate = (
props: IProps,
): Promise<IPropagation.IBranch<boolean, number, any>> =>
PlainFetcher.propagate(...getFetcherArguments(props)) as Promise<
IPropagation.IBranch<boolean, number, any>
>;

const getFetcherArguments = (props: IProps) => {
const route = props.function.route();
return [
props.connection,
{
method: props.function.method.toUpperCase() as "POST",
Expand All @@ -89,7 +120,7 @@ export namespace OpenAiFetcher {
? props.arguments[0].body
: props.arguments[route.parameters.length + (route.query ? 1 : 0)]
: undefined,
);
] as const;
};

const getKeywordPath = (props: {
Expand Down

0 comments on commit 1682a08

Please sign in to comment.