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,59 +85,83 @@ 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}
#TODO add "newtopic" command to delete history while true
println("---> conversation loop")
# add usermsg to a.chathistory println("---> a.receiveUserMsgChannel ready = $(isready(a.receiveUserMsgChannel))")
addNewMessage(a, "user", usermsg) #TODO add "newtopic" command to delete history
# check for incoming user message
if isready(a.receiveUserMsgChannel)
incomingMsg = take!(a.receiveUserMsgChannel)
@show incomingMsg
end
# # if new user message available
# # if new message == "newtopic"
# #TODO add "newtopic" command to delete history
#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
end # # 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)
workstate = nothing
response = nothing
_ = addNewMessage(a, "user", usermsg)
isuseplan = isUsePlans(a)
# newinfo = extractinfo(a, usermsg)
# a.env = newinfo !== nothing ? updateEnvState(a, newinfo) : a.env
@show isuseplan
if isuseplan # use plan before responding
if haskey(a.memory[:shortterm], "User:") == false #TODO should change role if user want to buy wine.
a.memory[:shortterm]["User:"] = usermsg
end
workstate, response = work(a)
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 end
response = removeTrailingCharacters(response)
_ = addNewMessage(a, "assistant", response)
return response
# workstate = nothing
# response = nothing
# _ = addNewMessage(a, "user", usermsg)
# isuseplan = isUsePlans(a)
# # newinfo = extractinfo(a, usermsg)
# # a.env = newinfo !== nothing ? updateEnvState(a, newinfo) : a.env
# @show isuseplan
# if isuseplan # use plan before responding
# if haskey(a.memory[:shortterm], "User:") == false #TODO should change role if user want to buy wine.
# a.memory[:shortterm]["User:"] = usermsg
# end
# workstate, response = work(a)
# 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)
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,39 +113,41 @@ 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(
mqttClient, receiveUserMsgChannel::Channel,
msgMeta::Dict= GeneralUtils.generate_msgMeta("N/A"), receiveInternalMsgChannel::Channel,
config::Dict = Dict( mqttClient,
:frontend=> Dict( msgMeta::Dict= GeneralUtils.generate_msgMeta("N/A"),
:mqtttopic=> nothing config::Dict = Dict(
:frontend=> Dict(
:mqtttopic=> nothing
),
:internal=> Dict(
:mqtttopic=> nothing
),
:text2text=> Dict(
:mqtttopic=> "txt2text/api/v1/prompt/gpu",
),
)
;
name::String= "Assistant",
id::String= string(uuid4()),
tools::Dict= Dict(
:chatbox=> Dict(
:name => "chatbox",
:description => "Useful for when you need to communicate with the user.",
:input => "Input should be a conversation to the user.",
:output => "" ,
:func => nothing,
),
), ),
:internal=> Dict( maxHistoryMsg::Integer= 20,
:mqtttopic=> nothing thinkinglimit::Integer= 5,
), thinkingcount::Integer= 0,
:text2text=> Dict(
:mqtttopic=> "txt2text/api/v1/prompt/gpu",
),
)
;
name::String= "Assistant",
id::String= string(uuid4()),
tools::Dict= Dict(
:chatbox=> Dict(
:name => "chatbox",
:description => "Useful for when you need to communicate with the user.",
:input => "Input should be a conversation to the user.",
:output => "" ,
:func => nothing,
),
),
maxHistoryMsg::Integer= 20,
thinkinglimit::Integer= 5,
thinkingcount::Integer= 0,
) )
#NEXTVERSION publish to a.config[:configtopic] to get a config. #NEXTVERSION publish to a.config[:configtopic] to get a config.
@@ -153,15 +155,17 @@ function sommelier(
#NEXTVERSION set agent according to config #NEXTVERSION set agent according to config
newAgent = sommelier( newAgent = sommelier(
name = name, receiveUserMsgChannel= receiveUserMsgChannel,
id = id, receiveInternalMsgChannel= receiveInternalMsgChannel,
config = config, name= name,
mqttClient = mqttClient, id= id,
msgMeta = msgMeta, config= config,
maxHistoryMsg = maxHistoryMsg, mqttClient= mqttClient,
tools = tools, msgMeta= msgMeta,
thinkinglimit = thinkinglimit, maxHistoryMsg= maxHistoryMsg,
thinkingcount = thinkingcount, tools= tools,
thinkinglimit= thinkinglimit,
thinkingcount= thinkingcount,
) )
return newAgent return newAgent