Skip to content

Commit

Permalink
enhance: use new prompt style for more granular prompts
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Feb 4, 2025
1 parent 150e8ed commit c892bf4
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 43 deletions.
5 changes: 2 additions & 3 deletions apiclient/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23.1

require (
github.com/getkin/kin-openapi v0.124.0
github.com/gptscript-ai/go-gptscript v0.9.4
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250204133419-744b25b84a61
github.com/obot-platform/obot/logger v0.0.0-20241217130503-4004a5c69f32
)

Expand All @@ -19,7 +19,6 @@ require (
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/testify v1.9.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 6 additions & 6 deletions apiclient/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/go-openapi/swag v0.22.8 h1:/9RjDSQ0vbFR+NyjGMkFTsA1IA0fmhKSThmfGZjicb
github.com/go-openapi/swag v0.22.8/go.mod h1:6QT22icPLEqAM/z/TChgb4WAveCHF92+2gF0CNjHpPI=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/gptscript-ai/go-gptscript v0.9.4 h1:4PDn1NW7ErUsWJIuxyK7G3aXGxA33TZrrMuSfH0S09c=
github.com/gptscript-ai/go-gptscript v0.9.4/go.mod h1:Dh6vYRAiVcyC3ElZIGzTvNF1FxtYwA07BHfSiFKQY7s=
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250204133419-744b25b84a61 h1:QxLjsLOYlsVLPwuRkP0Q8EcAoZT1s8vU2ZBSX0+R6CI=
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250204133419-744b25b84a61/go.mod h1:/FVuLwhz+sIfsWUgUHWKi32qT0i6+IXlUlzs70KKt/Q=
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand All @@ -37,13 +37,13 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
25 changes: 24 additions & 1 deletion apiclient/types/invoke.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package types

import "github.com/gptscript-ai/go-gptscript"

// +k8s:deepcopy-gen=false

// +k8s:openapi-gen=false
Expand Down Expand Up @@ -79,11 +81,32 @@ type Prompt struct {
Description string `json:"description,omitempty"`
Time *Time `json:"time,omitempty"`
Message string `json:"message,omitempty"`
Fields []string `json:"fields,omitempty"`
Fields Fields `json:"fields,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}

// Field should match exactly what is in the GPTScript SDK
type Field struct {
Name string `json:"name,omitempty"`
Sensitive *bool `json:"sensitive,omitempty"`
Description string `json:"description,omitempty"`
}

type Fields []Field

func ToFields(fields gptscript.Fields) Fields {
f := make(Fields, len(fields))
for i, field := range fields {
f[i] = Field{
Name: field.Name,
Sensitive: field.Sensitive,
Description: field.Description,
}
}
return f
}

type ToolInput struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Expand Down
47 changes: 45 additions & 2 deletions apiclient/types/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ require (
github.com/gorilla/websocket v1.5.0
github.com/gptscript-ai/chat-completion-client v0.0.0-20250128181713-57857b74f9f1
github.com/gptscript-ai/cmd v0.0.0-20250122115124-a3d65e9d2432
github.com/gptscript-ai/go-gptscript v0.9.6-0.20241216211344-79a66826cf82
github.com/gptscript-ai/gptscript v0.9.6-0.20250128190959-7ee5c807d2b9
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250204133419-744b25b84a61
github.com/gptscript-ai/gptscript v0.9.6-0.20250204193143-468c4f1a3cd9
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
github.com/mhale/smtpd v0.8.3
github.com/obot-platform/kinm v0.0.0-20250116162656-270198b40c6d
Expand Down Expand Up @@ -129,7 +129,7 @@ require (
github.com/gookit/color v1.5.4 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/gptscript-ai/broadcaster v0.0.0-20240625175512-c43682019b86 // indirect
github.com/gptscript-ai/tui v0.0.0-20240923192013-172e51ccf1d6 // indirect
github.com/gptscript-ai/tui v0.0.0-20250204145344-33cd15de4cee // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ github.com/gptscript-ai/chat-completion-client v0.0.0-20250128181713-57857b74f9f
github.com/gptscript-ai/chat-completion-client v0.0.0-20250128181713-57857b74f9f1/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo=
github.com/gptscript-ai/cmd v0.0.0-20250122115124-a3d65e9d2432 h1:cJh/Hl1HFd1qLpdkaZvsFTC2mXlIuiK7FgvSfaSOWmw=
github.com/gptscript-ai/cmd v0.0.0-20250122115124-a3d65e9d2432/go.mod h1:DJAo1xTht1LDkNYFNydVjTHd576TC7MlpsVRl3oloVw=
github.com/gptscript-ai/go-gptscript v0.9.6-0.20241216211344-79a66826cf82 h1:BEN268Z92gqeDc51XVvWdJWdQ47BuuWH3MUysHzilfI=
github.com/gptscript-ai/go-gptscript v0.9.6-0.20241216211344-79a66826cf82/go.mod h1:/FVuLwhz+sIfsWUgUHWKi32qT0i6+IXlUlzs70KKt/Q=
github.com/gptscript-ai/gptscript v0.9.6-0.20250128190959-7ee5c807d2b9 h1:biFzueEkd6DO7YCO5lR4syFK2lDzLhpUlbGrHf7/B04=
github.com/gptscript-ai/gptscript v0.9.6-0.20250128190959-7ee5c807d2b9/go.mod h1:3Vm532vjbbtZk6tcHdKm7RuI5rOppCb3NLecOWhTStw=
github.com/gptscript-ai/tui v0.0.0-20240923192013-172e51ccf1d6 h1:vkgNZVWQgbE33VD3z9WKDwuu7B/eJVVMMPM62ixfCR8=
github.com/gptscript-ai/tui v0.0.0-20240923192013-172e51ccf1d6/go.mod h1:frrl/B+ZH3VSs3Tqk2qxEIIWTONExX3tuUa4JsVnqx4=
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250204133419-744b25b84a61 h1:QxLjsLOYlsVLPwuRkP0Q8EcAoZT1s8vU2ZBSX0+R6CI=
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250204133419-744b25b84a61/go.mod h1:/FVuLwhz+sIfsWUgUHWKi32qT0i6+IXlUlzs70KKt/Q=
github.com/gptscript-ai/gptscript v0.9.6-0.20250204193143-468c4f1a3cd9 h1:MdmM6ZcEXUc8mTHSAs8jrBQ6lSAQVog5HrNCptVCOZA=
github.com/gptscript-ai/gptscript v0.9.6-0.20250204193143-468c4f1a3cd9/go.mod h1:uvb92bYHRX9wFHSS1jkg5Y7GBQgTb8iHP+l/wPsWCx8=
github.com/gptscript-ai/tui v0.0.0-20250204145344-33cd15de4cee h1:70PHW6Xw70yNNZ5aX936XqcMLwNmfMZpCV3FCOGKpxE=
github.com/gptscript-ai/tui v0.0.0-20250204145344-33cd15de4cee/go.mod h1:iwHxuueg2paOak7zIg0ESBWx7A0wIHGopAratbgaPNY=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/events/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func handlePrompt(ctx context.Context, c *apiclient.Client, prompt *types.Prompt
}

for _, field := range prompt.Fields {
v, err := textio.Ask(field, "")
v, err := textio.Ask(field.Name, "")
if err != nil {
return err
}
Expand All @@ -147,7 +147,7 @@ func handlePrompt(ctx context.Context, c *apiclient.Client, prompt *types.Prompt
v = string(data)
}
}
promptResponse.Responses[field] = v
promptResponse.Responses[field.Name] = v
}

if len(promptResponse.Responses) == 0 {
Expand Down
17 changes: 10 additions & 7 deletions pkg/controller/creds/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ func DetermineCredsAndCredNames(prg *gptscript.Program, tool gptscript.Tool, nam
return credentials, credentialNames, nil
}

func determineCredentialNames(prg *gptscript.Program, tool gptscript.Tool, toolName string, noAuth map[string]struct{}) ([]string, error) {
func determineCredentialNames(prg *gptscript.Program, tool gptscript.Tool, credToolName string, noAuth map[string]struct{}) ([]string, error) {
var subTool string
parsedToolName, alias, args, err := gtypes.ParseCredentialArgs(toolName, "")
parsedToolName, alias, args, err := gtypes.ParseCredentialArgs(credToolName, "")
if err != nil {
parsedToolName, subTool = gtypes.SplitToolRef(toolName)
parsedToolName, subTool = gtypes.SplitToolRef(credToolName)
parsedToolName, alias, args, err = gtypes.ParseCredentialArgs(parsedToolName, "")
if err != nil {
return nil, err
Expand All @@ -88,18 +88,21 @@ func determineCredentialNames(prg *gptscript.Program, tool gptscript.Tool, toolN
}

if args != nil {
return []string{toolName}, nil
if _, ok := noAuth[alias]; !ok {
return []string{credToolName}, nil
}
return nil, nil
}

// This is a tool and not the credential format. Parse the tool from the program to determine the alias
toolNames := make([]string, 0, len(tool.Credentials))
if subTool == "" {
toolName = parsedToolName
credToolName = parsedToolName
}
for _, cred := range tool.Credentials {
if cred == toolName {
if cred == credToolName {
if len(tool.ToolMapping[cred]) == 0 {
return nil, fmt.Errorf("cannot find credential name for tool %q", toolName)
return nil, fmt.Errorf("cannot find credential name for tool %q", credToolName)
}

for _, ref := range tool.ToolMapping[cred] {
Expand Down
2 changes: 1 addition & 1 deletion pkg/invoke/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ func (i *Invoker) stream(ctx context.Context, c kclient.WithWatch, prevThreadNam
Description: callingTool.Description,
Time: types.NewTime(frame.Prompt.Time),
Message: frame.Prompt.Message,
Fields: frame.Prompt.Fields,
Fields: types.ToFields(frame.Prompt.Fields),
Sensitive: frame.Prompt.Sensitive,
Metadata: metadata,
}
Expand Down
39 changes: 35 additions & 4 deletions pkg/storage/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions ui/admin/app/components/chat/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function PromptMessage({
return (
<div className="flex items-center gap-2">
<ToolIcon
name={prompt.name}
name={prompt.name || ""}
category={prompt.metadata.category}
icon={prompt.metadata.icon}
className="h-5 w-5"
Expand Down Expand Up @@ -310,7 +310,7 @@ export function PromptAuthForm({
const form = useForm<Record<string, string>>({
defaultValues: prompt.fields?.reduce(
(acc, field) => {
acc[field] = "";
acc[field.name] = "";
return acc;
},
{} as Record<string, string>
Expand All @@ -327,11 +327,12 @@ export function PromptAuthForm({
<form onSubmit={handleSubmit} className="flex flex-col gap-4">
{prompt.fields?.map((field) => (
<ControlledInput
key={field}
key={field.name}
control={form.control}
name={field}
label={field}
type={prompt.sensitive ? "password" : "text"}
name={field.name}
label={field.name}
description={field.description || ""}
type={prompt.sensitive || !!field.sensitive ? "password" : "text"}
/>
))}

Expand Down
8 changes: 7 additions & 1 deletion ui/admin/app/lib/model/chatEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ export type AuthPrompt = {
name: string;
time?: Date;
message: string;
fields?: string[];
fields?: PromptField[];
sensitive?: boolean;
metadata?: PromptAuthMeta;
};

export type PromptField = {
name: string;
description?: string;
sensitive?: boolean;
};

// note(ryanhopperlowe) renaming this to ChatEvent to differentiate itself specifically for a chat with an agent
// we should create a separate type for WorkflowEvents and leverage Unions to differentiate between them
export type ChatEvent = {
Expand Down
8 changes: 7 additions & 1 deletion ui/user/src/lib/services/chat/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ type Prompt = {
description?: string;
time: string;
message?: string;
fields?: string[];
fields?: PromptField[];
sensitive?: boolean;
metadata?: { [key: string]: string };
};

type PromptField = {
name: string;
description?: string;
sensitive?: boolean;
};

type ToolInput = {
name?: string;
description?: string;
Expand Down

0 comments on commit c892bf4

Please sign in to comment.