@@ -90,7 +90,7 @@ export class GPTScript {
90
90
if ( ! this . ready ) {
91
91
this . ready = await this . testGPTScriptURL ( 20 )
92
92
}
93
- const r = new RunSubcommand ( cmd , "" , "" , { } , GPTScript . serverURL )
93
+ const r = new RunSubcommand ( cmd , "" , { } , GPTScript . serverURL )
94
94
r . requestNoStream ( null )
95
95
return r . text ( )
96
96
}
@@ -106,38 +106,29 @@ export class GPTScript {
106
106
if ( ! this . ready ) {
107
107
this . ready = await this . testGPTScriptURL ( 20 )
108
108
}
109
- return ( new Run ( "run" , toolName , "" , opts , GPTScript . serverURL ) ) . nextChat ( opts . input )
109
+ return ( new Run ( "run" , toolName , opts , GPTScript . serverURL ) ) . nextChat ( opts . input )
110
110
}
111
111
112
112
/**
113
113
* Evaluates the given tool and returns a Run object.
114
114
*
115
- * @param {ToolDef | ToolDef[] | string } tool - The tool to be evaluated. Can be a single ToolDef object, an array of ToolDef objects, or a string representing the tool contents .
115
+ * @param {ToolDef | ToolDef[] } tool - The tool to be evaluated. Can be a single ToolDef object or an array of ToolDef objects.
116
116
* @param {RunOpts } [opts={}] - Optional options for the evaluation.
117
117
* @return {Run } The Run object representing the evaluation.
118
118
*/
119
- async evaluate ( tool : ToolDef | ToolDef [ ] | string , opts : RunOpts = { } ) : Promise < Run > {
119
+ async evaluate ( tool : ToolDef | ToolDef [ ] , opts : RunOpts = { } ) : Promise < Run > {
120
120
if ( ! this . ready ) {
121
121
this . ready = await this . testGPTScriptURL ( 20 )
122
122
}
123
- let toolString : string = ""
124
123
125
- if ( Array . isArray ( tool ) ) {
126
- toolString = toolArrayToContents ( tool )
127
- } else if ( typeof tool === "string" ) {
128
- toolString = tool
129
- } else {
130
- toolString = toolDefToString ( tool )
131
- }
132
-
133
- return ( new Run ( "evaluate" , "" , toolString , opts , GPTScript . serverURL ) ) . nextChat ( opts . input )
124
+ return ( new Run ( "evaluate" , tool , opts , GPTScript . serverURL ) ) . nextChat ( opts . input )
134
125
}
135
126
136
127
async parse ( fileName : string ) : Promise < Block [ ] > {
137
128
if ( ! this . ready ) {
138
129
this . ready = await this . testGPTScriptURL ( 20 )
139
130
}
140
- const r : Run = new RunSubcommand ( "parse" , fileName , "" , { } , GPTScript . serverURL )
131
+ const r : Run = new RunSubcommand ( "parse" , fileName , { } , GPTScript . serverURL )
141
132
r . request ( { file : fileName } )
142
133
return parseBlocksFromNodes ( ( await r . json ( ) ) . nodes )
143
134
}
@@ -146,7 +137,7 @@ export class GPTScript {
146
137
if ( ! this . ready ) {
147
138
this . ready = await this . testGPTScriptURL ( 20 )
148
139
}
149
- const r : Run = new RunSubcommand ( "parse" , "" , toolContent , { } , GPTScript . serverURL )
140
+ const r : Run = new RunSubcommand ( "parse" , "" , { } , GPTScript . serverURL )
150
141
r . request ( { content : toolContent } )
151
142
return parseBlocksFromNodes ( ( await r . json ( ) ) . nodes )
152
143
}
@@ -173,7 +164,7 @@ export class GPTScript {
173
164
}
174
165
}
175
166
176
- const r : Run = new RunSubcommand ( "fmt" , "" , JSON . stringify ( { nodes : nodes } ) , { } , GPTScript . serverURL )
167
+ const r : Run = new RunSubcommand ( "fmt" , "" , { } , GPTScript . serverURL )
177
168
r . request ( { nodes : nodes } )
178
169
return r . text ( )
179
170
}
@@ -223,8 +214,7 @@ export class GPTScript {
223
214
export class Run {
224
215
public readonly id : string
225
216
public readonly opts : RunOpts
226
- public readonly filePath : string
227
- public readonly content : string
217
+ public readonly tools ?: ToolDef | ToolDef [ ] | string
228
218
public state : RunState = RunState . Creating
229
219
public calls : Record < string , CallFrame > = { }
230
220
public err : string = ""
@@ -238,17 +228,15 @@ export class Run {
238
228
private stderr ?: string
239
229
private callbacks : Record < string , ( ( f : Frame ) => void ) [ ] > = { }
240
230
private chatState ?: string
241
- private callIdsByParentIds : Record < string , string [ ] > = { }
242
231
private parentCallId : string = ""
243
232
private prg ?: Program
244
233
private respondingToolId ?: string
245
234
246
- constructor ( subCommand : string , path : string , content : string , opts : RunOpts , gptscriptURL ?: string ) {
235
+ constructor ( subCommand : string , tools : ToolDef | ToolDef [ ] | string , opts : RunOpts , gptscriptURL ?: string ) {
247
236
this . id = randomId ( "run-" )
248
237
this . requestPath = subCommand
249
238
this . opts = opts
250
- this . filePath = path
251
- this . content = content
239
+ this . tools = tools
252
240
253
241
this . gptscriptURL = gptscriptURL
254
242
}
@@ -260,7 +248,7 @@ export class Run {
260
248
261
249
let run = this
262
250
if ( run . state !== RunState . Creating ) {
263
- run = new ( this . constructor as any ) ( this . requestPath , this . filePath , this . content , this . opts , this . gptscriptURL )
251
+ run = new ( this . constructor as any ) ( this . requestPath , this . tools , this . opts , this . gptscriptURL )
264
252
}
265
253
266
254
if ( this . chatState && this . state === RunState . Continue ) {
@@ -269,10 +257,13 @@ export class Run {
269
257
this . opts . chatState = this . chatState
270
258
}
271
259
run . opts . input = input
272
- if ( run . content !== "" ) {
273
- run . request ( { content : this . content , ...this . opts } )
260
+ if ( Array . isArray ( this . tools ) ) {
261
+ run . request ( { toolDefs : this . tools , ...this . opts } )
262
+ } else if ( typeof this . tools === "string" ) {
263
+ run . request ( { file : this . tools , ...this . opts } )
274
264
} else {
275
- run . request ( { file : this . filePath , ...this . opts } )
265
+ // In this last case, this.tools is a single ToolDef.
266
+ run . request ( { toolDefs : [ this . tools ] , ...this . opts } )
276
267
}
277
268
278
269
return run
@@ -463,8 +454,12 @@ export class Run {
463
454
return this . chatState
464
455
}
465
456
466
- public firstCallId ( ) : string {
467
- return this . parentCallId
457
+ public parentCallFrame ( ) : CallFrame | undefined {
458
+ if ( this . parentCallId ) {
459
+ return this . calls [ this . parentCallId ]
460
+ }
461
+
462
+ return undefined
468
463
}
469
464
470
465
public program ( ) : Program | undefined {
@@ -551,8 +546,8 @@ export class Run {
551
546
}
552
547
553
548
class RunSubcommand extends Run {
554
- constructor ( subCommand : string , path : string , content : string , opts : RunOpts , gptscriptURL ?: string ) {
555
- super ( subCommand , path , content , opts , gptscriptURL )
549
+ constructor ( subCommand : string , tool : ToolDef | ToolDef [ ] | string , opts : RunOpts , gptscriptURL ?: string ) {
550
+ super ( subCommand , tool , opts , gptscriptURL )
556
551
}
557
552
558
553
processStdout ( data : string | object ) : string {
@@ -608,16 +603,19 @@ export interface ToolDef {
608
603
modelName : string
609
604
modelProvider : boolean
610
605
jsonResponse : boolean
611
- temperature : number
606
+ temperature ? : number
612
607
cache ?: boolean
613
608
chat : boolean
614
- internalPrompt : boolean
609
+ internalPrompt ? : boolean
615
610
arguments : ArgumentSchema
616
611
tools : string [ ]
617
612
globalTools : string [ ]
613
+ globalModelName : string
618
614
context : string [ ]
615
+ exportContext : string [ ]
619
616
export : string [ ]
620
- blocking : boolean
617
+ agents : string [ ]
618
+ credentials : string [ ]
621
619
instructions : string
622
620
}
623
621
@@ -697,6 +695,7 @@ export interface Usage {
697
695
export interface CallFrame {
698
696
id : string
699
697
tool ?: Tool
698
+ agentGroup ?: ToolReference [ ]
700
699
displayText ?: string
701
700
inputContext : InputContext [ ]
702
701
toolCategory ?: string
@@ -768,67 +767,6 @@ function parseBlocksFromNodes(nodes: any[]): Block[] {
768
767
return blocks
769
768
}
770
769
771
- function toolArrayToContents ( toolArray : ToolDef [ ] ) {
772
- return toolArray . map ( singleTool => {
773
- return toolDefToString ( singleTool )
774
- } ) . join ( "\n---\n" )
775
- }
776
-
777
- function toolDefToString ( tool : ToolDef ) {
778
- let toolInfo : string [ ] = [ ]
779
- if ( tool . name ) {
780
- toolInfo . push ( `Name: ${ tool . name } ` )
781
- }
782
- if ( tool . description ) {
783
- toolInfo . push ( `Description: ${ tool . description } ` )
784
- }
785
- if ( tool . globalTools ?. length ) {
786
- toolInfo . push ( `Global Tools: ${ tool . globalTools . join ( ", " ) } ` )
787
- }
788
- if ( tool . tools ?. length > 0 ) {
789
- toolInfo . push ( `Tools: ${ tool . tools . join ( ", " ) } ` )
790
- }
791
- if ( tool . context ?. length > 0 ) {
792
- toolInfo . push ( `Context: ${ tool . context . join ( ", " ) } ` )
793
- }
794
- if ( tool . export ?. length > 0 ) {
795
- toolInfo . push ( `Export: ${ tool . export . join ( ", " ) } ` )
796
- }
797
- if ( tool . maxTokens !== undefined ) {
798
- toolInfo . push ( `Max Tokens: ${ tool . maxTokens } ` )
799
- }
800
- if ( tool . modelName ) {
801
- toolInfo . push ( `Model: ${ tool . modelName } ` )
802
- }
803
- if ( tool . cache !== undefined && ! tool . cache ) {
804
- toolInfo . push ( "Cache: false" )
805
- }
806
- if ( tool . temperature !== undefined ) {
807
- toolInfo . push ( `Temperature: ${ tool . temperature } ` )
808
- }
809
- if ( tool . jsonResponse ) {
810
- toolInfo . push ( "JSON Response: true" )
811
- }
812
- if ( tool . arguments && tool . arguments . properties ) {
813
- for ( const [ arg , desc ] of Object . entries ( tool . arguments . properties ) ) {
814
- toolInfo . push ( `Args: ${ arg } : ${ desc . description } ` )
815
- }
816
- }
817
- if ( tool . internalPrompt ) {
818
- toolInfo . push ( `Internal Prompt: ${ tool . internalPrompt } ` )
819
- }
820
- if ( tool . chat ) {
821
- toolInfo . push ( "Chat: true" )
822
- }
823
-
824
- if ( tool . instructions ) {
825
- toolInfo . push ( "" )
826
- toolInfo . push ( tool . instructions )
827
- }
828
-
829
- return toolInfo . join ( "\n" )
830
- }
831
-
832
770
function randomId ( prefix : string ) : string {
833
771
return prefix + Math . random ( ) . toString ( 36 ) . substring ( 2 , 12 )
834
772
}
0 commit comments