Skip to content

Commit

Permalink
chore: update prompt data structures
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 926b9da commit 744b25b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
22 changes: 17 additions & 5 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,28 @@ type InputContext struct {
Content string `json:"content,omitempty"`
}

type PromptFrame struct {
ID string `json:"id,omitempty"`
Type EventType `json:"type,omitempty"`
Time time.Time `json:"time,omitempty"`
type Prompt struct {
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"`
}

type Field struct {
Name string `json:"name,omitempty"`
Sensitive *bool `json:"sensitive,omitempty"`
Description string `json:"description,omitempty"`
}

type Fields []Field

type PromptFrame struct {
Prompt
ID string `json:"id,omitempty"`
Type EventType `json:"type,omitempty"`
Time time.Time `json:"time,omitempty"`
}

func (p *PromptFrame) String() string {
return fmt.Sprintf(`Message: %s
Fields: %v
Expand Down
12 changes: 6 additions & 6 deletions gptscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,13 +1131,13 @@ func TestPrompt(t *testing.T) {
t.Fatalf("Unexpected number of fields: %d", len(promptFrame.Fields))
}

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

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

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

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

if err = g.PromptResponse(context.Background(), PromptResponse{
ID: promptFrame.ID,
Responses: map[string]string{promptFrame.Fields[0]: "Clicky"},
Responses: map[string]string{promptFrame.Fields[0].Name: "Clicky"},
}); err != nil {
t.Errorf("Error responding: %v", err)
}
Expand Down

0 comments on commit 744b25b

Please sign in to comment.