Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: large openapi schemas require n^2 memory #507

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cli/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
}

if prg.IsChat() || r.ForceChat {
if !r.DisableTUI && !r.Debug && !r.DebugMessages {
if !r.DisableTUI && !r.Debug && !r.DebugMessages && !r.NoTrunc {
// Don't use cmd.Context() because then sigint will cancel everything
return tui.Run(context.Background(), args[0], tui.RunOptions{
OpenAIAPIKey: r.OpenAIOptions.APIKey,
Expand Down
26 changes: 19 additions & 7 deletions pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,13 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
}

func linkAll(ctx context.Context, cache *cache.Client, prg *types.Program, base *source, tools []types.Tool, localTools types.ToolSet) (result []types.Tool, _ error) {
localToolsMapping := make(map[string]string, len(tools))
for _, localTool := range localTools {
localToolsMapping[strings.ToLower(localTool.Parameters.Name)] = localTool.ID
}

for _, tool := range tools {
tool, err := link(ctx, cache, prg, base, tool, localTools)
tool, err := link(ctx, cache, prg, base, tool, localTools, localToolsMapping)
if err != nil {
return nil, err
}
Expand All @@ -306,7 +311,7 @@ func linkAll(ctx context.Context, cache *cache.Client, prg *types.Program, base
return
}

func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *source, tool types.Tool, localTools types.ToolSet) (types.Tool, error) {
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) {
if existing, ok := prg.ToolSet[tool.ID]; ok {
return existing, nil
}
Expand All @@ -331,7 +336,7 @@ func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *so
linkedTool = existing
} else {
var err error
linkedTool, err = link(ctx, cache, prg, base, localTool, localTools)
linkedTool, err = link(ctx, cache, prg, base, localTool, localTools, localToolsMapping)
if err != nil {
return types.Tool{}, fmt.Errorf("failed linking %s at %s: %w", targetToolName, base, err)
}
Expand All @@ -351,9 +356,7 @@ func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *so
}
}

for _, localTool := range localTools {
tool.LocalTools[strings.ToLower(localTool.Parameters.Name)] = localTool.ID
}
tool.LocalTools = localToolsMapping

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

return readTool(ctx, cache, prg, s, subTool)
result, err := readTool(ctx, cache, prg, s, subTool)
if err != nil {
return nil, err
}

if len(result) == 0 {
return nil, types.NewErrToolNotFound(types.ToToolName(name, subTool))
}

return result, nil
}

func input(ctx context.Context, cache *cache.Client, base *source, name string) (*source, error) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/types/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ type ErrToolNotFound struct {
ToolName string
}

func ToToolName(toolName, subTool string) string {
if subTool == "" {
return toolName
}
return fmt.Sprintf("%s from %s", subTool, toolName)
}

func NewErrToolNotFound(toolName string) *ErrToolNotFound {
return &ErrToolNotFound{
ToolName: toolName,
Expand Down