This commit is contained in:
narawat lamaiin
2024-04-18 13:27:29 +07:00
parent 4415bdbe91
commit 2f5800348f
2 changed files with 109 additions and 81 deletions

View File

@@ -85,19 +85,42 @@ using ..type, ..util, ..llmfunction
Signature\n Signature\n
----- -----
""" #TODO update document """ #TODO update document
function conversation(a::T, usermsg::String) where {T<:agent} function conversation(a::T) where {T<:agent}
while true
println("---> conversation loop")
println("---> a.receiveUserMsgChannel ready = $(isready(a.receiveUserMsgChannel))")
#TODO add "newtopic" command to delete history #TODO add "newtopic" command to delete history
# check for incoming user message
# add usermsg to a.chathistory if isready(a.receiveUserMsgChannel)
addNewMessage(a, "user", usermsg) incomingMsg = take!(a.receiveUserMsgChannel)
@show incomingMsg
#WORKING if the last used tool is a chatbox end
if a.plan[:currenttrajectory][end][:action] == "chatbox"
# usermsg -> observation and continue actor loop as planned
else # a new thinking # # if new user message available
# # if new message == "newtopic"
# #TODO add "newtopic" command to delete history
# # else
# # add usermsg to a.chathistory
# addNewMessage(a, "user", usermsg)
# #WORKING if the last used tool is a chatbox
# # if a.plan[:currenttrajectory][end][:action] == "chatbox"
# # usermsg -> observation and continue actor loop as planned
# # else # a new thinking
# # planning with MCTS() -> best plan
# # actor loop(best plan)
# # end
sleep(3)
end end
@@ -109,35 +132,36 @@ function conversation(a::T, usermsg::String) where {T<:agent}
workstate = nothing
response = nothing
_ = addNewMessage(a, "user", usermsg) # workstate = nothing
isuseplan = isUsePlans(a) # response = nothing
# newinfo = extractinfo(a, usermsg)
# a.env = newinfo !== nothing ? updateEnvState(a, newinfo) : a.env
@show isuseplan
if isuseplan # use plan before responding # _ = addNewMessage(a, "user", usermsg)
if haskey(a.memory[:shortterm], "User:") == false #TODO should change role if user want to buy wine. # isuseplan = isUsePlans(a)
a.memory[:shortterm]["User:"] = usermsg # # newinfo = extractinfo(a, usermsg)
end # # a.env = newinfo !== nothing ? updateEnvState(a, newinfo) : a.env
workstate, response = work(a) # @show isuseplan
end
# if LLM using askbox, use returning msg form askbox as conversation response # if isuseplan # use plan before responding
if workstate == "askbox" || workstate == "formulatedUserResponse" # if haskey(a.memory[:shortterm], "User:") == false #TODO should change role if user want to buy wine.
#TODO paraphrase msg so that it is human friendlier word. # a.memory[:shortterm]["User:"] = usermsg
else # end
response = chat_mistral_openorca(a) # workstate, response = work(a)
response = split(response, "\n\n")[1] # end
response = split(response, "\n\n")[1]
end # # if LLM using askbox, use returning msg form askbox as conversation response
# if workstate == "askbox" || workstate == "formulatedUserResponse"
# #TODO paraphrase msg so that it is human friendlier word.
# else
# response = chat_mistral_openorca(a)
# response = split(response, "\n\n")[1]
# response = split(response, "\n\n")[1]
# end
# response = removeTrailingCharacters(response)
# _ = addNewMessage(a, "assistant", response)
response = removeTrailingCharacters(response)
_ = addNewMessage(a, "assistant", response)
return response
end end

View File

@@ -76,7 +76,7 @@ abstract type agent end
Signature\n Signature\n
----- -----
""" #TODO update document """ #TODO update docstring
@kwdef mutable struct sommelier <: agent @kwdef mutable struct sommelier <: agent
name::String name::String
id::String id::String
@@ -113,11 +113,13 @@ abstract type agent end
msgMeta::Dict{Symbol, Any} # a template for msgMeta msgMeta::Dict{Symbol, Any} # a template for msgMeta
# put incoming message here. waiting for further processing # put incoming message here. waiting for further processing
incomingUserMsg::Channel{Dict} = Channel{Dict}(8) # for user communication receiveUserMsgChannel::Channel{Dict} = Channel{Dict}(8) # for incoming user communication
internalMsg::Channel{Dict} = Channel{Dict}(8) # for internal communication receiveInternalMsgChannel::Channel{Dict} = Channel{Dict}(8) # for internal communication
end end
function sommelier( function sommelier(
receiveUserMsgChannel::Channel,
receiveInternalMsgChannel::Channel,
mqttClient, mqttClient,
msgMeta::Dict= GeneralUtils.generate_msgMeta("N/A"), msgMeta::Dict= GeneralUtils.generate_msgMeta("N/A"),
config::Dict = Dict( config::Dict = Dict(
@@ -153,6 +155,8 @@ function sommelier(
#NEXTVERSION set agent according to config #NEXTVERSION set agent according to config
newAgent = sommelier( newAgent = sommelier(
receiveUserMsgChannel= receiveUserMsgChannel,
receiveInternalMsgChannel= receiveInternalMsgChannel,
name= name, name= name,
id= id, id= id,
config= config, config= config,