Skip to content

Commit 65e1e09

Browse files
authored
enhance: add green color to tool call names (#182)
Signed-off-by: Grant Linville <[email protected]>
1 parent fd7e77d commit 65e1e09

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d
99
github.com/acorn-io/cmd v0.0.0-20240203032901-e9e631185ddb
1010
github.com/adrg/xdg v0.4.0
11+
github.com/fatih/color v1.16.0
1112
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
1213
github.com/hexops/autogold/v2 v2.1.0
1314
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
@@ -34,7 +35,6 @@ require (
3435
github.com/connesc/cipherio v0.2.1 // indirect
3536
github.com/davecgh/go-spew v1.1.1 // indirect
3637
github.com/dsnet/compress v0.0.1 // indirect
37-
github.com/fatih/color v1.16.0 // indirect
3838
github.com/go-logr/logr v1.4.1 // indirect
3939
github.com/golang/snappy v0.0.4 // indirect
4040
github.com/google/go-cmp v0.6.0 // indirect

pkg/cli/gptscript.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/acorn-io/cmd"
10+
"github.com/fatih/color"
1011
"github.com/gptscript-ai/gptscript/pkg/assemble"
1112
"github.com/gptscript-ai/gptscript/pkg/builtin"
1213
"github.com/gptscript-ai/gptscript/pkg/cache"
@@ -34,6 +35,7 @@ type GPTScript struct {
3435
CacheOptions
3536
OpenAIOptions
3637
DisplayOptions
38+
Color *bool `usage:"Use color in output (default true)" default:"true"`
3739
Confirm bool `usage:"Prompt before running potentially dangerous commands"`
3840
Debug bool `usage:"Enable debug logging"`
3941
Quiet *bool `usage:"No output logging (set --quiet=false to force on even when there is no TTY)" short:"q"`
@@ -113,6 +115,10 @@ func (r *GPTScript) Pre(*cobra.Command, []string) error {
113115
}
114116

115117
func (r *GPTScript) Run(cmd *cobra.Command, args []string) error {
118+
if r.Color != nil {
119+
color.NoColor = !*r.Color
120+
}
121+
116122
gptOpt := gptscript.Options{
117123
Cache: cache.Options(r.CacheOptions),
118124
OpenAI: openai.Options(r.OpenAIOptions),

pkg/types/completion.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package types
33
import (
44
"fmt"
55
"strings"
6+
7+
"github.com/fatih/color"
68
)
79

810
type CompletionRequest struct {
@@ -81,7 +83,7 @@ func (in CompletionMessage) String() string {
8183
}
8284
buf.WriteString(content.Text)
8385
if content.ToolCall != nil {
84-
buf.WriteString(fmt.Sprintf("tool call %s -> %s", content.ToolCall.Function.Name, content.ToolCall.Function.Arguments))
86+
buf.WriteString(fmt.Sprintf("tool call %s -> %s", color.GreenString(content.ToolCall.Function.Name), content.ToolCall.Function.Arguments))
8587
}
8688
}
8789
return buf.String()

0 commit comments

Comments
 (0)