Skip to content

enhance: add green color to tool call names #182

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

Merged
merged 1 commit into from
Mar 25, 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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d
github.com/acorn-io/cmd v0.0.0-20240203032901-e9e631185ddb
github.com/adrg/xdg v0.4.0
github.com/fatih/color v1.16.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/hexops/autogold/v2 v2.1.0
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
Expand All @@ -34,7 +35,6 @@ require (
github.com/connesc/cipherio v0.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions pkg/cli/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/acorn-io/cmd"
"github.com/fatih/color"
"github.com/gptscript-ai/gptscript/pkg/assemble"
"github.com/gptscript-ai/gptscript/pkg/builtin"
"github.com/gptscript-ai/gptscript/pkg/cache"
Expand Down Expand Up @@ -34,6 +35,7 @@ type GPTScript struct {
CacheOptions
OpenAIOptions
DisplayOptions
Color *bool `usage:"Use color in output (default true)" default:"true"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can this just be a bool instead of *bool?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the example of the --cache flag, which you can see here:

Cache *bool `usage:"Disable caching" default:"true"`

It uses a bool pointer. I noticed that when I had just a bool, the default:"true" struct tag didn't do anything, but it worked as soon as I made it a pointer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I just noticed that the description for --cache is the opposite of what it's supposed to be, lol

Confirm bool `usage:"Prompt before running potentially dangerous commands"`
Debug bool `usage:"Enable debug logging"`
Quiet *bool `usage:"No output logging (set --quiet=false to force on even when there is no TTY)" short:"q"`
Expand Down Expand Up @@ -113,6 +115,10 @@ func (r *GPTScript) Pre(*cobra.Command, []string) error {
}

func (r *GPTScript) Run(cmd *cobra.Command, args []string) error {
if r.Color != nil {
color.NoColor = !*r.Color
}

gptOpt := gptscript.Options{
Cache: cache.Options(r.CacheOptions),
OpenAI: openai.Options(r.OpenAIOptions),
Expand Down
4 changes: 3 additions & 1 deletion pkg/types/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package types
import (
"fmt"
"strings"

"github.com/fatih/color"
)

type CompletionRequest struct {
Expand Down Expand Up @@ -81,7 +83,7 @@ func (in CompletionMessage) String() string {
}
buf.WriteString(content.Text)
if content.ToolCall != nil {
buf.WriteString(fmt.Sprintf("tool call %s -> %s", content.ToolCall.Function.Name, content.ToolCall.Function.Arguments))
buf.WriteString(fmt.Sprintf("tool call %s -> %s", color.GreenString(content.ToolCall.Function.Name), content.ToolCall.Function.Arguments))
}
}
return buf.String()
Expand Down