Skip to content

feat: add ability to include metadata with prompts #807

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
Aug 20, 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
1 change: 1 addition & 0 deletions pkg/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ var tools = map[string]types.Tool{
"message", "The message to display to the user",
"fields", "A comma-separated list of fields to prompt for",
"sensitive", "(true or false) Whether the input should be hidden",
"metadata", "(optional) A JSON object of metadata to attach to the prompt",
),
},
BuiltinFunc: prompt.SysPrompt,
Expand Down
12 changes: 8 additions & 4 deletions pkg/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,29 @@ func sysPromptHTTP(ctx context.Context, envs []string, url string, prompt types.

func SysPrompt(ctx context.Context, envs []string, input string, _ chan<- string) (_ string, err error) {
var params struct {
Message string `json:"message,omitempty"`
Fields string `json:"fields,omitempty"`
Sensitive string `json:"sensitive,omitempty"`
Message string `json:"message,omitempty"`
Fields string `json:"fields,omitempty"`
Sensitive string `json:"sensitive,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
if err := json.Unmarshal([]byte(input), &params); err != nil {
return "", err
}

var fields []string
for _, env := range envs {
if url, ok := strings.CutPrefix(env, types.PromptURLEnvVar+"="); ok {
var fields []string
if params.Fields != "" {
fields = strings.Split(params.Fields, ",")
}

httpPrompt := types.Prompt{
Message: params.Message,
Fields: fields,
Sensitive: params.Sensitive == "true",
Metadata: params.Metadata,
}

return sysPromptHTTP(ctx, envs, url, httpPrompt)
}
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/sdkserver/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ func (s *server) prompt(w http.ResponseWriter, r *http.Request) {
}(id)

s.events.C <- event{
Prompt: types.Prompt{
Message: prompt.Message,
Fields: prompt.Fields,
Sensitive: prompt.Sensitive,
},
Prompt: prompt,
Event: gserver.Event{
RunID: id,
Event: runner.Event{
Expand Down
7 changes: 4 additions & 3 deletions pkg/types/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const (
)

type Prompt struct {
Message string `json:"message,omitempty"`
Fields []string `json:"fields,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Message string `json:"message,omitempty"`
Fields []string `json:"fields,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}