1- import { IConnection } from "@nestia/fetcher" ;
1+ import { IConnection , IPropagation } from "@nestia/fetcher" ;
22import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher" ;
33import { IMigrateRoute } from "@samchon/openapi" ;
44
55import { IOpenAiDocument } from "./structures/IOpenAiDocument" ;
66import { 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