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

Commit 1682a08

Browse files
authored
Merge pull request #17 from wrtnio/features/propagate
Add `OpenAiFetcher.propagate()` function.
2 parents 1492881 + 970475b commit 1682a08

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wrtnio/openai-function-schema",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "OpenAI LLM function schema from OpenAPI (Swagger) document",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",
@@ -37,16 +37,16 @@
3737
"author": "",
3838
"license": "ISC",
3939
"dependencies": {
40-
"@nestia/fetcher": "^3.7.0",
40+
"@nestia/fetcher": "^3.8.0",
4141
"@samchon/openapi": "^0.4.2",
4242
"commander": "^10.0.0",
4343
"inquirer": "^8.2.5",
44-
"typia": "^6.5.0"
44+
"typia": "^6.5.4"
4545
},
4646
"devDependencies": {
47-
"@nestia/core": "^3.7.0",
47+
"@nestia/core": "^3.8.0",
4848
"@nestia/e2e": "^0.7.0",
49-
"@nestia/sdk": "^3.7.0",
49+
"@nestia/sdk": "^3.8.0",
5050
"@nestjs/common": "^10.3.10",
5151
"@nestjs/core": "^10.3.10",
5252
"@nestjs/platform-express": "^10.3.10",
@@ -63,7 +63,7 @@
6363
"rollup": "^4.18.0",
6464
"ts-node": "^10.9.2",
6565
"ts-patch": "^3.2.1",
66-
"typescript": "^5.5.3",
66+
"typescript": "^5.5.4",
6767
"typescript-transform-paths": "^3.4.7",
6868
"uuid": "^10.0.0"
6969
},

src/OpenAiFetcher.ts

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { IConnection } from "@nestia/fetcher";
1+
import { IConnection, IPropagation } from "@nestia/fetcher";
22
import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher";
33
import { IMigrateRoute } from "@samchon/openapi";
44

55
import { IOpenAiDocument } from "./structures/IOpenAiDocument";
66
import { IOpenAiFunction } from "./structures/IOpenAiFunction";
77

88
/**
9-
* Function call executor for OpenAI.
9+
* Function call executors for OpenAI.
1010
*
1111
* `OpenAiFetcher` is a module for function call execution with target function's
1212
* metadata {@link IOpenAiFunction} and OpenAI composed arguments.
@@ -47,23 +47,54 @@ export namespace OpenAiFetcher {
4747
/**
4848
* Execute the function call.
4949
*
50-
* `OpenAiFetcher.fetch()` is a function executing the target API endpoint with
50+
* `OpenAiFetcher.execute()` is a function executing the target API endpoint with
5151
* the operation's metadata {@link IOpenAiFunction} and OpenAI composed arguments.
5252
*
53-
* Also, `OpenAiFetcher.fetch()` is designed to consider
53+
* Also, `OpenAiFetcher.execute()` is designed to consider
5454
* {@link IOpenAiDocument.IOptions.keyword} option, so that it can unwrap the
5555
* composed arguments into the function call arguments automatically.
5656
*
5757
* However, about the {@link IOpenAiDocument.IOptions.separate} case, you have
5858
* to use {@link OpenAiDataCombiner.parameters} function to combine the LLM and
5959
* human arguments into one, by yourself manually.
6060
*
61-
* @param props
62-
* @returns
61+
* @param props Function call properties.
62+
* @returns Response of the function call.
6363
*/
64-
export const execute = async (props: IProps): Promise<any> => {
65-
const route: IMigrateRoute = props.function.route();
66-
return PlainFetcher.fetch(
64+
export const execute = (props: IProps): Promise<any> =>
65+
PlainFetcher.fetch(...getFetcherArguments(props));
66+
67+
/**
68+
* Propagate the function call.
69+
*
70+
* `OpenAiFetcher.propagate()` is a function propagating the target API endpoint with
71+
* the operation's metadata {@link IOpenAiFunction} and OpenAI composed arguments.
72+
*
73+
* Also, `OpenAiFetcher.execute()` is designed to consider
74+
* {@link IOpenAiDocument.IOptions.keyword} option, so that it can unwrap the
75+
* composed arguments into the function call arguments automatically.
76+
*
77+
* However, about the {@link IOpenAiDocument.IOptions.separate} case, you have
78+
* to use {@link OpenAiDataCombiner.parameters} function to combine the LLM and
79+
* human arguments into one, by yourself manually.
80+
*
81+
* > For reference, the propagation means always returning the response even if the
82+
* > request is failled, with the response's status code. About detailed concept
83+
* > of the propagation, refer to the {@link IPropagation} type.
84+
*
85+
* @param props Function call properties.
86+
* @returns Propagation of the function call.
87+
*/
88+
export const propagate = (
89+
props: IProps,
90+
): Promise<IPropagation.IBranch<boolean, number, any>> =>
91+
PlainFetcher.propagate(...getFetcherArguments(props)) as Promise<
92+
IPropagation.IBranch<boolean, number, any>
93+
>;
94+
95+
const getFetcherArguments = (props: IProps) => {
96+
const route = props.function.route();
97+
return [
6798
props.connection,
6899
{
69100
method: props.function.method.toUpperCase() as "POST",
@@ -89,7 +120,7 @@ export namespace OpenAiFetcher {
89120
? props.arguments[0].body
90121
: props.arguments[route.parameters.length + (route.query ? 1 : 0)]
91122
: undefined,
92-
);
123+
] as const;
93124
};
94125

95126
const getKeywordPath = (props: {

0 commit comments

Comments
 (0)