@@ -26,25 +26,11 @@ var (
26
26
27
27
const relativeToBinaryPath = "<me>"
28
28
29
- type GPTScript interface {
30
- Run (context.Context , string , Options ) (* Run , error )
31
- Evaluate (context.Context , Options , ... ToolDef ) (* Run , error )
32
- Parse (context.Context , string ) ([]Node , error )
33
- ParseTool (context.Context , string ) ([]Node , error )
34
- Version (context.Context ) (string , error )
35
- Fmt (context.Context , []Node ) (string , error )
36
- ListTools (context.Context ) (string , error )
37
- ListModels (context.Context ) ([]string , error )
38
- Confirm (context.Context , AuthResponse ) error
39
- PromptResponse (context.Context , PromptResponse ) error
40
- Close ()
41
- }
42
-
43
- type gptscript struct {
29
+ type GPTScript struct {
44
30
url string
45
31
}
46
32
47
- func NewGPTScript (opts GlobalOptions ) (GPTScript , error ) {
33
+ func NewGPTScript (opts GlobalOptions ) (* GPTScript , error ) {
48
34
lock .Lock ()
49
35
defer lock .Unlock ()
50
36
gptscriptCount ++
@@ -98,7 +84,7 @@ func NewGPTScript(opts GlobalOptions) (GPTScript, error) {
98
84
return nil , fmt .Errorf ("failed to wait for gptscript to be ready: %w" , err )
99
85
}
100
86
}
101
- return & gptscript {url : "http://" + serverURL }, nil
87
+ return & GPTScript {url : "http://" + serverURL }, nil
102
88
}
103
89
104
90
func waitForServerReady (ctx context.Context , serverURL string ) error {
@@ -122,7 +108,7 @@ func waitForServerReady(ctx context.Context, serverURL string) error {
122
108
}
123
109
}
124
110
125
- func (g * gptscript ) Close () {
111
+ func (g * GPTScript ) Close () {
126
112
lock .Lock ()
127
113
defer lock .Unlock ()
128
114
gptscriptCount --
@@ -133,7 +119,7 @@ func (g *gptscript) Close() {
133
119
}
134
120
}
135
121
136
- func (g * gptscript ) Evaluate (ctx context.Context , opts Options , tools ... ToolDef ) (* Run , error ) {
122
+ func (g * GPTScript ) Evaluate (ctx context.Context , opts Options , tools ... ToolDef ) (* Run , error ) {
137
123
return (& Run {
138
124
url : g .url ,
139
125
requestPath : "evaluate" ,
@@ -143,7 +129,7 @@ func (g *gptscript) Evaluate(ctx context.Context, opts Options, tools ...ToolDef
143
129
}).NextChat (ctx , opts .Input )
144
130
}
145
131
146
- func (g * gptscript ) Run (ctx context.Context , toolPath string , opts Options ) (* Run , error ) {
132
+ func (g * GPTScript ) Run (ctx context.Context , toolPath string , opts Options ) (* Run , error ) {
147
133
return (& Run {
148
134
url : g .url ,
149
135
requestPath : "run" ,
@@ -154,7 +140,7 @@ func (g *gptscript) Run(ctx context.Context, toolPath string, opts Options) (*Ru
154
140
}
155
141
156
142
// Parse will parse the given file into an array of Nodes.
157
- func (g * gptscript ) Parse (ctx context.Context , fileName string ) ([]Node , error ) {
143
+ func (g * GPTScript ) Parse (ctx context.Context , fileName string ) ([]Node , error ) {
158
144
out , err := g .runBasicCommand (ctx , "parse" , map [string ]any {"file" : fileName })
159
145
if err != nil {
160
146
return nil , err
@@ -173,7 +159,7 @@ func (g *gptscript) Parse(ctx context.Context, fileName string) ([]Node, error)
173
159
}
174
160
175
161
// ParseTool will parse the given string into a tool.
176
- func (g * gptscript ) ParseTool (ctx context.Context , toolDef string ) ([]Node , error ) {
162
+ func (g * GPTScript ) ParseTool (ctx context.Context , toolDef string ) ([]Node , error ) {
177
163
out , err := g .runBasicCommand (ctx , "parse" , map [string ]any {"content" : toolDef })
178
164
if err != nil {
179
165
return nil , err
@@ -192,7 +178,7 @@ func (g *gptscript) ParseTool(ctx context.Context, toolDef string) ([]Node, erro
192
178
}
193
179
194
180
// Fmt will format the given nodes into a string.
195
- func (g * gptscript ) Fmt (ctx context.Context , nodes []Node ) (string , error ) {
181
+ func (g * GPTScript ) Fmt (ctx context.Context , nodes []Node ) (string , error ) {
196
182
for _ , node := range nodes {
197
183
node .TextNode .combine ()
198
184
}
@@ -206,7 +192,7 @@ func (g *gptscript) Fmt(ctx context.Context, nodes []Node) (string, error) {
206
192
}
207
193
208
194
// Version will return the output of `gptscript --version`
209
- func (g * gptscript ) Version (ctx context.Context ) (string , error ) {
195
+ func (g * GPTScript ) Version (ctx context.Context ) (string , error ) {
210
196
out , err := g .runBasicCommand (ctx , "version" , nil )
211
197
if err != nil {
212
198
return "" , err
@@ -216,7 +202,7 @@ func (g *gptscript) Version(ctx context.Context) (string, error) {
216
202
}
217
203
218
204
// ListTools will list all the available tools.
219
- func (g * gptscript ) ListTools (ctx context.Context ) (string , error ) {
205
+ func (g * GPTScript ) ListTools (ctx context.Context ) (string , error ) {
220
206
out , err := g .runBasicCommand (ctx , "list-tools" , nil )
221
207
if err != nil {
222
208
return "" , err
@@ -226,7 +212,7 @@ func (g *gptscript) ListTools(ctx context.Context) (string, error) {
226
212
}
227
213
228
214
// ListModels will list all the available models.
229
- func (g * gptscript ) ListModels (ctx context.Context ) ([]string , error ) {
215
+ func (g * GPTScript ) ListModels (ctx context.Context ) ([]string , error ) {
230
216
out , err := g .runBasicCommand (ctx , "list-models" , nil )
231
217
if err != nil {
232
218
return nil , err
@@ -235,17 +221,17 @@ func (g *gptscript) ListModels(ctx context.Context) ([]string, error) {
235
221
return strings .Split (strings .TrimSpace (out ), "\n " ), nil
236
222
}
237
223
238
- func (g * gptscript ) Confirm (ctx context.Context , resp AuthResponse ) error {
224
+ func (g * GPTScript ) Confirm (ctx context.Context , resp AuthResponse ) error {
239
225
_ , err := g .runBasicCommand (ctx , "confirm/" + resp .ID , resp )
240
226
return err
241
227
}
242
228
243
- func (g * gptscript ) PromptResponse (ctx context.Context , resp PromptResponse ) error {
229
+ func (g * GPTScript ) PromptResponse (ctx context.Context , resp PromptResponse ) error {
244
230
_ , err := g .runBasicCommand (ctx , "prompt-response/" + resp .ID , resp .Responses )
245
231
return err
246
232
}
247
233
248
- func (g * gptscript ) runBasicCommand (ctx context.Context , requestPath string , body any ) (string , error ) {
234
+ func (g * GPTScript ) runBasicCommand (ctx context.Context , requestPath string , body any ) (string , error ) {
249
235
run := & Run {
250
236
url : g .url ,
251
237
requestPath : requestPath ,
0 commit comments