-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAgent.R
45 lines (40 loc) · 907 Bytes
/
Agent.R
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
source('GPTInterface.R')
Agent <- R6Class(
"Agent",
public = list(
id = "",
messages = list(),
gptInterface = NULL,
config = NULL,
workingDir = "",
tokensUsed = 0,
lastChatPartner = NULL,
initialize = function(config,id) {
self$id <- id
self$gptInterface <- GPTInterface$new(self,config)
self$config <- config
self$workingDir <- paste0(
config$runtimeDirPrefix,"/",
config$aiName
)
self
},
appendMessage = function(role,msg) {
self$messages <- c(self$messages,list(list(
"role" =role,"content"=msg
)))
},
resetMessages = function() {
self$messages <- list()
},
syncChat = function(cmdMsg) {
self$gptInterface$syncChat(cmdMsg)
},
chat = function(cmdMsg) {
#encodedMsg <- commandHandler$encodeCommand(cmdMsg)
response <- self$gptInterface$chat(cmdMsg)
#print(paste0("Agent responding: ",response))
response
}
)
)