Repository navigation
Expand file tree
/
Copy pathsystem_message_sections_e2e_test.go
More file actions
98 lines (86 loc) · 3 KB
/
Copy pathsystem_message_sections_e2e_test.go
File metadata and controls
98 lines (86 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
package e2e
import (
"strings"
"testing"
copilot "github.com/github/copilot-sdk/go"
"github.com/github/copilot-sdk/go/internal/e2e/testharness"
)
func TestSystemMessageSectionsE2E(t *testing.T) {
ctx := testharness.NewTestContext(t)
client := ctx.NewClient()
t.Cleanup(func() { client.ForceStop() })
t.Run("should_use_replaced_identity_section_in_response", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
SystemMessage: &copilot.SystemMessageConfig{
Mode: "customize",
Sections: map[string]copilot.SectionOverride{
"identity": {
Action: copilot.SectionActionReplace,
Content: "You are a helpful gardening assistant called Botanica. You only answer questions about plants and gardening.",
},
},
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
response, err := session.SendAndWait(t.Context(), copilot.MessageOptions{
Prompt: "Who are you?",
})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
if response == nil {
t.Fatal("Expected a response from the assistant")
return
}
ad, ok := response.Data.(*copilot.AssistantMessageData)
if !ok {
t.Fatalf("Expected AssistantMessageData, got %T", response.Data)
}
content := strings.ToLower(ad.Content)
if !strings.Contains(content, "botanica") && !strings.Contains(content, "garden") && !strings.Contains(content, "plant") {
t.Errorf("Expected response to reflect the replaced identity section, but got: %s", ad.Content)
}
})
t.Run("should_use_replaced_preamble_section_in_response", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
SystemMessage: &copilot.SystemMessageConfig{
Mode: "customize",
Sections: map[string]copilot.SectionOverride{
copilot.SectionPreamble: {
Action: copilot.SectionActionReplace,
Content: "You are a helpful gardening assistant called Botanica. You only answer questions about plants and gardening.",
},
},
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
response, err := session.SendAndWait(t.Context(), copilot.MessageOptions{
Prompt: "Who are you?",
})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
if response == nil {
t.Fatal("Expected a response from the assistant")
return
}
ad, ok := response.Data.(*copilot.AssistantMessageData)
if !ok {
t.Fatalf("Expected AssistantMessageData, got %T", response.Data)
}
content := strings.ToLower(ad.Content)
if !strings.Contains(content, "botanica") && !strings.Contains(content, "garden") && !strings.Contains(content, "plant") {
t.Errorf("Expected response to reflect the replaced preamble section, but got: %s", ad.Content)
}
})
}