Skip to content

Commit 744b25b

Browse files
committed
chore: update prompt data structures
Signed-off-by: Donnie Adams <donnie@acorn.io>
1 parent 926b9da commit 744b25b

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

frame.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,28 @@ type InputContext struct {
116116
Content string `json:"content,omitempty"`
117117
}
118118

119-
type PromptFrame struct {
120-
ID string `json:"id,omitempty"`
121-
Type EventType `json:"type,omitempty"`
122-
Time time.Time `json:"time,omitempty"`
119+
type Prompt struct {
123120
Message string `json:"message,omitempty"`
124-
Fields []string `json:"fields,omitempty"`
121+
Fields Fields `json:"fields,omitempty"`
125122
Sensitive bool `json:"sensitive,omitempty"`
126123
Metadata map[string]string `json:"metadata,omitempty"`
127124
}
128125

126+
type Field struct {
127+
Name string `json:"name,omitempty"`
128+
Sensitive *bool `json:"sensitive,omitempty"`
129+
Description string `json:"description,omitempty"`
130+
}
131+
132+
type Fields []Field
133+
134+
type PromptFrame struct {
135+
Prompt
136+
ID string `json:"id,omitempty"`
137+
Type EventType `json:"type,omitempty"`
138+
Time time.Time `json:"time,omitempty"`
139+
}
140+
129141
func (p *PromptFrame) String() string {
130142
return fmt.Sprintf(`Message: %s
131143
Fields: %v

gptscript_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1131,13 +1131,13 @@ func TestPrompt(t *testing.T) {
11311131
t.Fatalf("Unexpected number of fields: %d", len(promptFrame.Fields))
11321132
}
11331133

1134-
if promptFrame.Fields[0] != "first name" {
1135-
t.Errorf("Unexpected field: %s", promptFrame.Fields[0])
1134+
if promptFrame.Fields[0].Name != "first name" {
1135+
t.Errorf("Unexpected field: %s", promptFrame.Fields[0].Name)
11361136
}
11371137

11381138
if err = g.PromptResponse(context.Background(), PromptResponse{
11391139
ID: promptFrame.ID,
1140-
Responses: map[string]string{promptFrame.Fields[0]: "Clicky"},
1140+
Responses: map[string]string{promptFrame.Fields[0].Name: "Clicky"},
11411141
}); err != nil {
11421142
t.Errorf("Error responding: %v", err)
11431143
}
@@ -1199,8 +1199,8 @@ func TestPromptWithMetadata(t *testing.T) {
11991199
t.Fatalf("Unexpected number of fields: %d", len(promptFrame.Fields))
12001200
}
12011201

1202-
if promptFrame.Fields[0] != "first name" {
1203-
t.Errorf("Unexpected field: %s", promptFrame.Fields[0])
1202+
if promptFrame.Fields[0].Name != "first name" {
1203+
t.Errorf("Unexpected field: %s", promptFrame.Fields[0].Name)
12041204
}
12051205

12061206
if promptFrame.Metadata["key"] != "value" {
@@ -1209,7 +1209,7 @@ func TestPromptWithMetadata(t *testing.T) {
12091209

12101210
if err = g.PromptResponse(context.Background(), PromptResponse{
12111211
ID: promptFrame.ID,
1212-
Responses: map[string]string{promptFrame.Fields[0]: "Clicky"},
1212+
Responses: map[string]string{promptFrame.Fields[0].Name: "Clicky"},
12131213
}); err != nil {
12141214
t.Errorf("Error responding: %v", err)
12151215
}

0 commit comments

Comments
 (0)