@@ -17,7 +17,6 @@ import (
17
17
18
18
"github.com/getkin/kin-openapi/openapi3"
19
19
"github.com/gptscript-ai/gptscript/internal"
20
- "github.com/gptscript-ai/gptscript/pkg/assemble"
21
20
"github.com/gptscript-ai/gptscript/pkg/builtin"
22
21
"github.com/gptscript-ai/gptscript/pkg/cache"
23
22
"github.com/gptscript-ai/gptscript/pkg/hash"
@@ -132,36 +131,6 @@ func loadLocal(base *source, name string) (*source, bool, error) {
132
131
}, true , nil
133
132
}
134
133
135
- func loadProgram (data []byte , into * types.Program , targetToolName , defaultModel string ) (types.Tool , error ) {
136
- var ext types.Program
137
-
138
- if err := json .Unmarshal (data [len (assemble .Header ):], & ext ); err != nil {
139
- return types.Tool {}, err
140
- }
141
-
142
- into .ToolSet = make (map [string ]types.Tool , len (ext .ToolSet ))
143
- for k , v := range ext .ToolSet {
144
- if builtinTool , ok := builtin .DefaultModel (k , defaultModel ); ok {
145
- v = builtinTool
146
- }
147
- into .ToolSet [k ] = v
148
- }
149
-
150
- tool := into .ToolSet [ext .EntryToolID ]
151
- if targetToolName == "" {
152
- return tool , nil
153
- }
154
-
155
- tool , ok := into .ToolSet [tool .LocalTools [strings .ToLower (targetToolName )]]
156
- if ! ok {
157
- return tool , & types.ErrToolNotFound {
158
- ToolName : targetToolName ,
159
- }
160
- }
161
-
162
- return tool , nil
163
- }
164
-
165
134
func loadOpenAPI (prg * types.Program , data []byte ) * openapi3.T {
166
135
var (
167
136
openAPICacheKey = hash .Digest (data )
@@ -189,14 +158,6 @@ func loadOpenAPI(prg *types.Program, data []byte) *openapi3.T {
189
158
func readTool (ctx context.Context , cache * cache.Client , prg * types.Program , base * source , targetToolName , defaultModel string ) ([]types.Tool , error ) {
190
159
data := base .Content
191
160
192
- if bytes .HasPrefix (data , assemble .Header ) {
193
- tool , err := loadProgram (data , prg , targetToolName , defaultModel )
194
- if err != nil {
195
- return nil , err
196
- }
197
- return []types.Tool {tool }, nil
198
- }
199
-
200
161
var (
201
162
tools []types.Tool
202
163
isOpenAPI bool
@@ -231,11 +192,19 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
231
192
// If we didn't get any tools from trying to parse it as OpenAPI, try to parse it as a GPTScript
232
193
if len (tools ) == 0 {
233
194
var err error
234
- tools , err = parser .ParseTools (bytes .NewReader (data ), parser.Options {
235
- AssignGlobals : true ,
236
- })
237
- if err != nil {
238
- return nil , err
195
+ _ , marshaled , ok := strings .Cut (string (data ), "#!GPTSCRIPT" )
196
+ if ok {
197
+ err = json .Unmarshal ([]byte (marshaled ), & tools )
198
+ if err != nil {
199
+ return nil , fmt .Errorf ("error parsing marshalled script: %w" , err )
200
+ }
201
+ } else {
202
+ tools , err = parser .ParseTools (bytes .NewReader (data ), parser.Options {
203
+ AssignGlobals : true ,
204
+ })
205
+ if err != nil {
206
+ return nil , err
207
+ }
239
208
}
240
209
}
241
210
0 commit comments