Skip to content

Commit 02a3cee

Browse files
Merge pull request #507 from ibuildthecloud/main
bug: large openapi schemas require n^2 memory
2 parents 566256a + bbe8f66 commit 02a3cee

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

pkg/cli/gptscript.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
453453
}
454454

455455
if prg.IsChat() || r.ForceChat {
456-
if !r.DisableTUI && !r.Debug && !r.DebugMessages {
456+
if !r.DisableTUI && !r.Debug && !r.DebugMessages && !r.NoTrunc {
457457
// Don't use cmd.Context() because then sigint will cancel everything
458458
return tui.Run(context.Background(), args[0], tui.RunOptions{
459459
OpenAIAPIKey: r.OpenAIOptions.APIKey,

pkg/loader/loader.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,13 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
296296
}
297297

298298
func linkAll(ctx context.Context, cache *cache.Client, prg *types.Program, base *source, tools []types.Tool, localTools types.ToolSet) (result []types.Tool, _ error) {
299+
localToolsMapping := make(map[string]string, len(tools))
300+
for _, localTool := range localTools {
301+
localToolsMapping[strings.ToLower(localTool.Parameters.Name)] = localTool.ID
302+
}
303+
299304
for _, tool := range tools {
300-
tool, err := link(ctx, cache, prg, base, tool, localTools)
305+
tool, err := link(ctx, cache, prg, base, tool, localTools, localToolsMapping)
301306
if err != nil {
302307
return nil, err
303308
}
@@ -306,7 +311,7 @@ func linkAll(ctx context.Context, cache *cache.Client, prg *types.Program, base
306311
return
307312
}
308313

309-
func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *source, tool types.Tool, localTools types.ToolSet) (types.Tool, error) {
314+
func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *source, tool types.Tool, localTools types.ToolSet, localToolsMapping map[string]string) (types.Tool, error) {
310315
if existing, ok := prg.ToolSet[tool.ID]; ok {
311316
return existing, nil
312317
}
@@ -331,7 +336,7 @@ func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *so
331336
linkedTool = existing
332337
} else {
333338
var err error
334-
linkedTool, err = link(ctx, cache, prg, base, localTool, localTools)
339+
linkedTool, err = link(ctx, cache, prg, base, localTool, localTools, localToolsMapping)
335340
if err != nil {
336341
return types.Tool{}, fmt.Errorf("failed linking %s at %s: %w", targetToolName, base, err)
337342
}
@@ -351,9 +356,7 @@ func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *so
351356
}
352357
}
353358

354-
for _, localTool := range localTools {
355-
tool.LocalTools[strings.ToLower(localTool.Parameters.Name)] = localTool.ID
356-
}
359+
tool.LocalTools = localToolsMapping
357360

358361
tool = builtin.SetDefaults(tool)
359362
prg.ToolSet[tool.ID] = tool
@@ -438,7 +441,16 @@ func resolve(ctx context.Context, cache *cache.Client, prg *types.Program, base
438441
return nil, err
439442
}
440443

441-
return readTool(ctx, cache, prg, s, subTool)
444+
result, err := readTool(ctx, cache, prg, s, subTool)
445+
if err != nil {
446+
return nil, err
447+
}
448+
449+
if len(result) == 0 {
450+
return nil, types.NewErrToolNotFound(types.ToToolName(name, subTool))
451+
}
452+
453+
return result, nil
442454
}
443455

444456
func input(ctx context.Context, cache *cache.Client, base *source, name string) (*source, error) {

pkg/types/tool.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ type ErrToolNotFound struct {
3030
ToolName string
3131
}
3232

33+
func ToToolName(toolName, subTool string) string {
34+
if subTool == "" {
35+
return toolName
36+
}
37+
return fmt.Sprintf("%s from %s", subTool, toolName)
38+
}
39+
3340
func NewErrToolNotFound(toolName string) *ErrToolNotFound {
3441
return &ErrToolNotFound{
3542
ToolName: toolName,

0 commit comments

Comments
 (0)