Skip to content

Commit 415de95

Browse files
authored
Merge pull request #96 from StrongMonkey/inline-prompting
Enhance: Add ability to do inline prompting to choose oauth/pat
2 parents 8d1f06f + 5df35b4 commit 415de95

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

frame.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ type Prompt struct {
124124
}
125125

126126
type Field struct {
127-
Name string `json:"name,omitempty"`
128-
Sensitive *bool `json:"sensitive,omitempty"`
129-
Description string `json:"description,omitempty"`
127+
Name string `json:"name,omitempty"`
128+
Sensitive *bool `json:"sensitive,omitempty"`
129+
Description string `json:"description,omitempty"`
130+
Options []string `json:"options,omitempty"`
130131
}
131132

132133
type Fields []Field

gptscript_test.go

+48-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func TestCancelRun(t *testing.T) {
160160
}
161161

162162
func TestAbortChatCompletionRun(t *testing.T) {
163-
tool := ToolDef{Instructions: "What is the capital of the united states?"}
163+
tool := ToolDef{Instructions: "Generate a real long essay about the meaning of life."}
164164

165165
run, err := g.Evaluate(context.Background(), Options{DisableCache: true, IncludeEvents: true}, tool)
166166
if err != nil {
@@ -1404,6 +1404,53 @@ func TestPromptWithoutPromptAllowed(t *testing.T) {
14041404
}
14051405
}
14061406

1407+
func TestPromptWithOptions(t *testing.T) {
1408+
run, err := g.Run(context.Background(), "sys.prompt", Options{IncludeEvents: true, Prompt: true, Input: `{"fields":[{"name":"Authentication Method","description":"The authentication token for the user","options":["API Key","OAuth"]}]}`})
1409+
if err != nil {
1410+
t.Errorf("Error executing tool: %v", err)
1411+
}
1412+
1413+
// Wait for the prompt event
1414+
var promptFrame *PromptFrame
1415+
for e := range run.Events() {
1416+
if e.Prompt != nil {
1417+
if e.Prompt.Type == EventTypePrompt {
1418+
promptFrame = e.Prompt
1419+
break
1420+
}
1421+
}
1422+
}
1423+
1424+
if promptFrame == nil {
1425+
t.Fatalf("No prompt call event")
1426+
return
1427+
}
1428+
1429+
if len(promptFrame.Fields) != 1 {
1430+
t.Fatalf("Unexpected number of fields: %d", len(promptFrame.Fields))
1431+
}
1432+
1433+
if promptFrame.Fields[0].Name != "Authentication Method" {
1434+
t.Errorf("Unexpected field: %s", promptFrame.Fields[0].Name)
1435+
}
1436+
1437+
if promptFrame.Fields[0].Description != "The authentication token for the user" {
1438+
t.Errorf("Unexpected description: %s", promptFrame.Fields[0].Description)
1439+
}
1440+
1441+
if len(promptFrame.Fields[0].Options) != 2 {
1442+
t.Fatalf("Unexpected number of options: %d", len(promptFrame.Fields[0].Options))
1443+
}
1444+
1445+
if promptFrame.Fields[0].Options[0] != "API Key" {
1446+
t.Errorf("Unexpected option: %s", promptFrame.Fields[0].Options[0])
1447+
}
1448+
1449+
if promptFrame.Fields[0].Options[1] != "OAuth" {
1450+
t.Errorf("Unexpected option: %s", promptFrame.Fields[0].Options[1])
1451+
}
1452+
}
1453+
14071454
func TestGetCommand(t *testing.T) {
14081455
currentEnvVar := os.Getenv("GPTSCRIPT_BIN")
14091456
t.Cleanup(func() {

0 commit comments

Comments
 (0)