@@ -252,6 +252,37 @@ export class GPTScript {
252
252
}
253
253
}
254
254
255
+ /**
256
+ * Loads a tool or tools with the specified options.
257
+ *
258
+ * @param {ToolDef | ToolDef[] } toolDefs - The tool or tools to load.
259
+ * @param {string } [content] - The content of the tool.
260
+ * @param {boolean } [disableCache] - Whether to disable the cache.
261
+ * @param {string } [subTool] - The sub-tool to use.
262
+ * @param {string } [file] - The file to load.
263
+ * @return {Promise<LoadResponse> } The loaded program.
264
+ */
265
+ async load (
266
+ toolDefs : ToolDef | ToolDef [ ] ,
267
+ content ?: string ,
268
+ disableCache ?: boolean ,
269
+ subTool ?: string ,
270
+ file ?: string
271
+ ) : Promise < LoadResponse > {
272
+ if ( ! this . ready ) {
273
+ this . ready = await this . testGPTScriptURL ( 20 ) ;
274
+ }
275
+ const r : Run = new RunSubcommand ( "load" , toolDefs , { } , GPTScript . serverURL ) ;
276
+ const requestPayload : any = { toolDefs : Array . isArray ( toolDefs ) ? toolDefs : [ toolDefs ] } ;
277
+ if ( content ) requestPayload . content = content ;
278
+ if ( disableCache !== undefined ) requestPayload . disableCache = disableCache ;
279
+ if ( subTool ) requestPayload . subTool = subTool ;
280
+ if ( file ) requestPayload . file = file ;
281
+
282
+ r . request ( requestPayload ) ;
283
+ return r . json ( ) as Promise < LoadResponse > ;
284
+ }
285
+
255
286
private async testGPTScriptURL ( count : number ) : Promise < boolean > {
256
287
while ( count > 0 ) {
257
288
try {
@@ -812,6 +843,10 @@ export interface PromptResponse {
812
843
responses : Record < string , string >
813
844
}
814
845
846
+ export interface LoadResponse {
847
+ program : Program ;
848
+ }
849
+
815
850
export function getEnv ( key : string , def : string = "" ) : string {
816
851
let v = process . env [ key ] || ""
817
852
if ( v == "" ) {
0 commit comments