@@ -7,41 +7,67 @@ import (
7
7
"github.com/microsoft/retina/ai/pkg/lm"
8
8
flowretrieval "github.com/microsoft/retina/ai/pkg/retrieval/flows"
9
9
"github.com/microsoft/retina/ai/pkg/scenarios"
10
- "github.com/microsoft/retina/ai/pkg/scenarios/dns"
11
- "github.com/microsoft/retina/ai/pkg/scenarios/drops"
12
10
13
11
"github.com/sirupsen/logrus"
14
12
"k8s.io/client-go/kubernetes"
15
13
"k8s.io/client-go/rest"
16
14
)
17
15
18
- var (
19
- definitions = []* scenarios.Definition {
20
- drops .Definition ,
21
- dns .Definition ,
22
- }
23
- )
24
-
25
16
type Bot struct {
26
- log logrus.FieldLogger
27
- config * rest.Config
28
- clientset * kubernetes.Clientset
29
- model lm.Model
17
+ log logrus.FieldLogger
18
+ config * rest.Config
19
+ clientset * kubernetes.Clientset
20
+ model lm.Model
21
+ flowRetriever * flowretrieval.Retriever
30
22
}
31
23
32
24
// input log, config, clientset, model
33
- func NewBot (log logrus.FieldLogger , config * rest.Config , clientset * kubernetes.Clientset , model lm.Model ) * Bot {
34
- return & Bot {
35
- log : log .WithField ("component" , "chat" ),
36
- config : config ,
37
- clientset : clientset ,
38
- model : model ,
25
+ func NewBot (log logrus.FieldLogger , config * rest.Config , clientset * kubernetes.Clientset , model lm.Model , useFlowsFromFile bool ) * Bot {
26
+ b := & Bot {
27
+ log : log .WithField ("component" , "chat" ),
28
+ config : config ,
29
+ clientset : clientset ,
30
+ model : model ,
31
+ flowRetriever : flowretrieval .NewRetriever (log , config , clientset ),
32
+ }
33
+
34
+ if useFlowsFromFile {
35
+ b .flowRetriever .UseFile ()
39
36
}
37
+
38
+ return b
40
39
}
41
40
41
+ func (b * Bot ) HandleScenario (question string , history lm.ChatHistory , definition * scenarios.Definition , parameters map [string ]string ) (lm.ChatHistory , error ) {
42
+ if definition == nil {
43
+ return history , fmt .Errorf ("no scenario selected" )
44
+ }
45
+
46
+ cfg := & scenarios.Config {
47
+ Log : b .log ,
48
+ Config : b .config ,
49
+ Clientset : b .clientset ,
50
+ Model : b .model ,
51
+ FlowRetriever : b .flowRetriever ,
52
+ }
53
+
54
+ ctx := context .TODO ()
55
+ response , err := definition .Handle (ctx , cfg , parameters , question , history )
56
+ if err != nil {
57
+ return history , fmt .Errorf ("error handling scenario: %w" , err )
58
+ }
59
+
60
+ history = append (history , lm.MessagePair {
61
+ User : question ,
62
+ Assistant : response ,
63
+ })
64
+
65
+ return history , nil
66
+ }
67
+
68
+ // FIXME get user input and implement scenario selection
42
69
func (b * Bot ) Loop () error {
43
70
var history lm.ChatHistory
44
- flowRetriever := flowretrieval .NewRetriever (b .log , b .config , b .clientset )
45
71
46
72
for {
47
73
// TODO get user input
@@ -53,39 +79,26 @@ func (b *Bot) Loop() error {
53
79
return fmt .Errorf ("error selecting scenario: %w" , err )
54
80
}
55
81
56
- // cfg.FlowRetriever.UseFile()
57
-
58
- cfg := & scenarios.Config {
59
- Log : b .log ,
60
- Config : b .config ,
61
- Clientset : b .clientset ,
62
- Model : b .model ,
63
- FlowRetriever : flowRetriever ,
64
- }
65
-
66
- ctx := context .TODO ()
67
- response , err := definition .Handle (ctx , cfg , params , question , history )
82
+ newHistory , err := b .HandleScenario (question , history , definition , params )
68
83
if err != nil {
69
84
return fmt .Errorf ("error handling scenario: %w" , err )
70
85
}
71
86
72
- fmt .Println (response )
87
+ fmt .Println (newHistory [ len ( newHistory ) - 1 ]. Assistant )
73
88
74
- // TODO keep chat loop going
75
- break
89
+ history = newHistory
76
90
}
77
-
78
- return nil
79
91
}
80
92
93
+ // FIXME fix prompts
81
94
func (b * Bot ) selectScenario (question string , history lm.ChatHistory ) (* scenarios.Definition , map [string ]string , error ) {
82
- // TODO use chat interface
83
- // FIXME hard-coding the scenario and params for now
84
- d := definitions [0 ]
85
- params := map [string ]string {
86
- scenarios .Namespace1 .Name : "default" ,
87
- scenarios .Namespace2 .Name : "default" ,
95
+ ctx := context .TODO ()
96
+ response , err := b .model .Generate (ctx , selectionSystemPrompt , nil , selectionPrompt (question , history ))
97
+ if err != nil {
98
+ return nil , nil , fmt .Errorf ("error generating response: %w" , err )
88
99
}
89
100
90
- return d , params , nil
101
+ // TODO parse response and return scenario definition and parameters
102
+ _ = response
103
+ return nil , nil , nil
91
104
}
0 commit comments