Skip to content

chore: default to tui, support more flags #426

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
Jun 4, 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.6.0
github.com/gptscript-ai/chat-completion-client v0.0.0-20240515050533-bdef9f2226a9
github.com/gptscript-ai/tui v0.0.0-20240531161317-ce32f93ac844
github.com/gptscript-ai/tui v0.0.0-20240604045848-e01b0b7aab9f
github.com/hexops/autogold/v2 v2.2.1
github.com/hexops/valast v1.4.4
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
Expand Down Expand Up @@ -62,7 +62,7 @@ require (
github.com/gookit/color v1.5.4 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gptscript-ai/go-gptscript v0.0.0-20240531155932-57eeae840062 // indirect
github.com/gptscript-ai/go-gptscript v0.0.0-20240604030145-39497c0575b3 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hexops/autogold v1.3.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gptscript-ai/chat-completion-client v0.0.0-20240515050533-bdef9f2226a9 h1:s6nL/aokB1sJTqVXEjN0zFI5CJa66ubw9g68VTMzEw0=
github.com/gptscript-ai/chat-completion-client v0.0.0-20240515050533-bdef9f2226a9/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo=
github.com/gptscript-ai/go-gptscript v0.0.0-20240531155932-57eeae840062 h1:30/1iOONBhw9WeCsoo4U74B+a20lATBFHFiVlpyk5oo=
github.com/gptscript-ai/go-gptscript v0.0.0-20240531155932-57eeae840062/go.mod h1:h1yYzC0rgB5Kk7lwdba+Xs6cWkuJfLq6sPRna45OVG0=
github.com/gptscript-ai/tui v0.0.0-20240531161317-ce32f93ac844 h1:c8sS5fCD3TXQZj94GDlQNR0zAw+1nuT3sYSH/Qo96+A=
github.com/gptscript-ai/tui v0.0.0-20240531161317-ce32f93ac844/go.mod h1:G51xpKSFH0g1hG1s9J8vxj7NL6x43KJxZKM+77rt79s=
github.com/gptscript-ai/go-gptscript v0.0.0-20240604030145-39497c0575b3 h1:mXLpCzEg4DoOeFZt6w99QFh9n60UwpRGGG0c+aaT+5k=
github.com/gptscript-ai/go-gptscript v0.0.0-20240604030145-39497c0575b3/go.mod h1:h1yYzC0rgB5Kk7lwdba+Xs6cWkuJfLq6sPRna45OVG0=
github.com/gptscript-ai/tui v0.0.0-20240604045848-e01b0b7aab9f h1:7dCE0E/y3y3p1BPSQGQ4mtsz5cWWl0FbXfCCDCf57SI=
github.com/gptscript-ai/tui v0.0.0-20240604045848-e01b0b7aab9f/go.mod h1:ybD/8QfwaMiK2QUSnnTxgzrIaXRgipowU4pW1qxgNJ8=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
Expand Down
11 changes: 8 additions & 3 deletions pkg/cli/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type GPTScript struct {
ForceSequential bool `usage:"Force parallel calls to run sequentially"`
Workspace string `usage:"Directory to use for the workspace, if specified it will not be deleted on exit"`
UI bool `usage:"Launch the UI" local:"true" name:"ui"`
TUI bool `usage:"Launch the TUI" local:"true" name:"tui"`
DisableTUI bool `usage:"Don't use chat TUI but instead verbose output" local:"true" name:"disable-tui"`

readData []byte
}
Expand Down Expand Up @@ -438,9 +438,14 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
}

if prg.IsChat() || r.ForceChat {
if r.TUI {
return tui.Run(cmd.Context(), args[0], r.Workspace, strings.Join(args[1:], " "), tui.RunOptions{
if !r.DisableTUI && !r.Debug && !r.DebugMessages {
return tui.Run(cmd.Context(), args[0], tui.RunOptions{
TrustedRepoPrefixes: []string{"github.com/gptscript-ai/context"},
DisableCache: r.DisableCache,
Input: strings.Join(args[1:], " "),
CacheDir: r.CacheDir,
SubTool: r.SubTool,
Workspace: r.Workspace,
})
}
return chat.Start(cmd.Context(), nil, gptScript, func() (types.Program, error) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/mvl/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (f formatter) Format(entry *logrus.Entry) ([]byte, error) {
if i, ok := entry.Data["request"]; ok && i != "" {
msg += fmt.Sprintf(" [request=%s]", i)
}
if i, ok := entry.Data["cached"]; ok && i == true {
msg += " [cached]"
}
if i, ok := entry.Data["response"]; ok && i != "" {
msg += fmt.Sprintf(" [response=%s]", i)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/openai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,15 @@ func (c *Client) Call(ctx context.Context, messageRequest types.CompletionReques
result.Role = types.CompletionMessageRoleTypeAssistant
}

var usage types.Usage
if !cacheResponse {
usage = result.Usage
if cacheResponse {
result.Usage = types.Usage{}
}

status <- types.CompletionStatus{
CompletionID: id,
Chunks: response,
Response: result,
Usage: usage,
Usage: result.Usage,
Cached: cacheResponse,
}

Expand Down