update
This commit is contained in:
165
src/interface.jl
165
src/interface.jl
@@ -4,7 +4,7 @@ export addNewMessage, conversation
|
||||
|
||||
using JSON3, DataStructures, Dates, UUIDs, HTTP, Random, MQTTClient
|
||||
using GeneralUtils
|
||||
using ..type, ..util, ..llmfunction
|
||||
using ..type, ..util, ..llmfunction, ..mcts
|
||||
|
||||
# ------------------------------------------------------------------------------------------------ #
|
||||
# pythoncall setting #
|
||||
@@ -85,102 +85,105 @@ using ..type, ..util, ..llmfunction
|
||||
Signature\n
|
||||
-----
|
||||
"""
|
||||
function conversation(a::T) where {T<:agent}
|
||||
function conversation(a::T, userinput::Dict) where {T<:agent}
|
||||
"""
|
||||
[] update document
|
||||
[] MCTS() for planning
|
||||
[x] MCTS() for planning
|
||||
"""
|
||||
while true
|
||||
# check for incoming user message
|
||||
if isready(a.receiveUserMsgChannel)
|
||||
incomingMsg = take!(a.receiveUserMsgChannel)
|
||||
incomingPayload = incomingMsg[:payload]
|
||||
# "newtopic" command to delete chat history
|
||||
if userinput[:text] == "newtopic"
|
||||
clearhistory(a)
|
||||
|
||||
# "newtopic" command to delete chat history
|
||||
if incomingPayload[:text] == "newtopic"
|
||||
clearhistory(a)
|
||||
msgMeta = deepcopy(a.msgMeta)
|
||||
msgMeta[:sendTopic] = incomingMsg[:msgMeta][:replyTopic]
|
||||
msgMeta[:senderName] = "agent-backend"
|
||||
msgMeta[:senderId] = a.id
|
||||
msgMeta[:receiverName] = "agent-frontend"
|
||||
msgMeta[:receiverId] = incomingMsg[:msgMeta][:senderId]
|
||||
msgMeta[:replyTopic] = a.config[:receivemsg][:prompt]
|
||||
msgMeta[:msgId] = string(uuid4())
|
||||
msgMeta[:replyToMsgId] = incomingMsg[:msgMeta][:msgId]
|
||||
return "Okay. What shall we talk about?"
|
||||
|
||||
outgoingMsg = Dict(
|
||||
:msgMeta=> msgMeta,
|
||||
:payload=> Dict(
|
||||
:name=> a.name, # will be shown in frontend as agent name
|
||||
:text => "Okay. What shall we talk about?",
|
||||
)
|
||||
)
|
||||
_ = GeneralUtils.sendMqttMsg(outgoingMsg)
|
||||
else
|
||||
# add usermsg to a.chathistory
|
||||
addNewMessage(a, "user", userinput[:text])
|
||||
|
||||
else # a new thinking
|
||||
# add usermsg to a.chathistory
|
||||
addNewMessage(a, "user", usermsg)
|
||||
#[] if the last used tool is a chatbox, put usermsg -> observation and continue actor loop as planned
|
||||
if !isempty(a.plan[:currenttrajectory]) &&
|
||||
a.plan[:currenttrajectory][end][:action] == "chatbox"
|
||||
|
||||
#[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 #[WORKING] new thinking
|
||||
|
||||
else
|
||||
#planning with MCTS() -> best plan
|
||||
|
||||
#actor loop(best plan)
|
||||
initialState = 0
|
||||
bestplan = runMCTS(initialState, decisionMaker, stateValueEstimator, reflector,
|
||||
3, 10, 1000, 1.0)
|
||||
error("---> bestplan")
|
||||
# actor loop(bestplan)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
sleep(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 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 #[] 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"
|
||||
# #[] 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
|
||||
|
||||
|
||||
|
||||
# function conversation(a::T) where {T<:agent}
|
||||
# """
|
||||
# [] update document
|
||||
# [x] MCTS() for planning
|
||||
# """
|
||||
# while true
|
||||
# # check for incoming user message
|
||||
# if isready(a.receiveUserMsgChannel)
|
||||
# incomingMsg = take!(a.receiveUserMsgChannel)
|
||||
# incomingPayload = incomingMsg[:payload]
|
||||
# @show incomingMsg
|
||||
|
||||
# # "newtopic" command to delete chat history
|
||||
# if incomingPayload[:text] == "newtopic"
|
||||
# clearhistory(a)
|
||||
# msgMeta = deepcopy(a.msgMeta)
|
||||
# msgMeta[:sendTopic] = incomingMsg[:msgMeta][:replyTopic]
|
||||
# msgMeta[:senderName] = "agent-backend"
|
||||
# msgMeta[:senderId] = a.id
|
||||
# msgMeta[:receiverName] = "agent-frontend"
|
||||
# msgMeta[:receiverId] = incomingMsg[:msgMeta][:senderId]
|
||||
# msgMeta[:replyTopic] = a.config[:receivemsg][:prompt]
|
||||
# msgMeta[:msgId] = string(uuid4())
|
||||
# msgMeta[:replyToMsgId] = incomingMsg[:msgMeta][:msgId]
|
||||
|
||||
# outgoingMsg = Dict(
|
||||
# :msgMeta=> msgMeta,
|
||||
# :payload=> Dict(
|
||||
# :name=> a.name, # will be shown in frontend as agent name
|
||||
# :text => "Okay. What shall we talk about?",
|
||||
# )
|
||||
# )
|
||||
# # _ = GeneralUtils.sendMqttMsg(outgoingMsg)
|
||||
|
||||
# else
|
||||
# @show a = 55555
|
||||
# # add usermsg to a.chathistory
|
||||
# addNewMessage(a, "user", usermsg)
|
||||
|
||||
# #[] if the last used tool is a chatbox
|
||||
# if a.plan[:currenttrajectory][end][:action] == "chatbox"
|
||||
# #usermsg -> observation and continue actor loop as planned
|
||||
|
||||
|
||||
|
||||
# else #[WORKING] new thinking
|
||||
|
||||
|
||||
# initialState = 0
|
||||
# bestplan = runMCTS(initialState, decisionMaker, stateValueEstimator, reflector,
|
||||
# 3, 10, 1000, 1.0)
|
||||
|
||||
# # actor loop(best plan)
|
||||
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# sleep(1)
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user