update
This commit is contained in:
131
src/interface.jl
131
src/interface.jl
@@ -39,7 +39,8 @@ macro executeStringFunction(functionStr, args...)
|
||||
func_expr = Meta.parse(functionStr)
|
||||
|
||||
# Create a new function with the parsed expression
|
||||
function_to_call = eval(Expr(:function, Expr(:call, func_expr, args...), func_expr.args[2:end]...))
|
||||
function_to_call = eval(Expr(:function, Expr(:call, func_expr, args...),
|
||||
func_expr.args[2:end]...))
|
||||
|
||||
# Call the newly created function with the provided arguments
|
||||
function_to_call(args...)
|
||||
@@ -744,47 +745,61 @@ julia> response = ChatAgent.conversation(newAgent, "Hi! how are you?")
|
||||
# Signature
|
||||
"""
|
||||
function conversation(a::T, userinput::Dict) where {T<:agent}
|
||||
|
||||
# "newtopic" command to delete chat history
|
||||
if userinput[:text] == "newtopic"
|
||||
clearhistory(a)
|
||||
|
||||
return "Okay. What shall we talk about?"
|
||||
|
||||
else
|
||||
# add usermsg to a.chathistory
|
||||
addNewMessage(a, "user", userinput[:text])
|
||||
|
||||
currentstate =
|
||||
if isempty(a.plan[:currenttrajectory])
|
||||
# set up initial state
|
||||
Dict{Symbol, Any}(
|
||||
# deepcopy the info to prevent modifying the info unintentionally during MCTS planning
|
||||
:customerinfo=> deepcopy(a.keywordinfo[:customerinfo]),
|
||||
:storeinfo=> deepcopy(a.keywordinfo[:storeinfo]),
|
||||
:userselect=> nothing,
|
||||
:reward=> 0,
|
||||
:isterminal=> false,
|
||||
:evaluation=> nothing,
|
||||
:lesson=> nothing,
|
||||
:thoughtDict=> nothing,
|
||||
:totalTrajectoryReward=> nothing,
|
||||
:thoughtHistory=> OrderedDict{Symbol, Any}( # contain question, thought_1, action_1, observation_1, thought_2, ...
|
||||
# :recap=>,
|
||||
:question=> userinput[:text],
|
||||
)
|
||||
)
|
||||
a.plan[:currenttrajectory] = Dict{Symbol, Any}(
|
||||
# deepcopy the info to prevent modifying the info unintentionally during MCTS planning
|
||||
:customerinfo=> deepcopy(a.keywordinfo[:customerinfo]),
|
||||
:storeinfo=> deepcopy(a.keywordinfo[:storeinfo]),
|
||||
:userselect=> nothing,
|
||||
:reward=> 0,
|
||||
:isterminal=> false,
|
||||
:evaluation=> nothing,
|
||||
:lesson=> nothing,
|
||||
|
||||
:totalTrajectoryReward=> nothing,
|
||||
|
||||
# contain question, thought_1, action_1, observation_1, thought_2, ...
|
||||
:thoughtHistory=> OrderedDict{Symbol, Any}(
|
||||
#[] :recap=>,
|
||||
:question=> userinput[:text],
|
||||
)
|
||||
)
|
||||
else
|
||||
a.plan[:currenttrajectory]
|
||||
_, a.plan[:currenttrajectory] = makeNewState(a.plan[:currenttrajectory],
|
||||
a.plan[:activeplan][:thoughtHistory], userinput[:text], userinput[:select],
|
||||
userinput[:reward], userinput[:isterminal])
|
||||
end
|
||||
end
|
||||
|
||||
while true
|
||||
bestNextState, besttrajectory = runMCTS(a, a.plan[:currenttrajectory], decisionMaker,
|
||||
evaluator, reflector, totalsample=2, maxDepth=2, maxiterations=1, explorationweight=1.0)
|
||||
a.plan[:activeplan] = bestNextState
|
||||
|
||||
latestActionKey, latestActionIndice =
|
||||
GeneralUtils.findHighestIndexKey(bestNextState[:thoughtHistory], "action")
|
||||
actionname = bestNextState[:thoughtHistory][latestActionKey][:name]
|
||||
actioninput = bestNextState[:thoughtHistory][latestActionKey][:input]
|
||||
|
||||
bestNextState, besttrajectory = runMCTS(a, currentstate, decisionMaker, evaluator, reflector,
|
||||
totalsample=3, maxDepth=2, maxiterations=1, explorationweight=1.0)
|
||||
|
||||
# transition
|
||||
newstate = transition(a, bestNextState)
|
||||
a.plan[:currenttrajectory] = newstate
|
||||
|
||||
if actionname == "chatbox"
|
||||
# add usermsg to a.chathistory
|
||||
addNewMessage(a, "assistant", actioninput)
|
||||
return actioninput
|
||||
elseif actionname == "recommendbox"
|
||||
# add usermsg to a.chathistory
|
||||
addNewMessage(a, "assistant", actioninput)
|
||||
return actioninput
|
||||
else
|
||||
_, a.plan[:currenttrajectory] = transition(a, a.plan[:activeplan])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -797,6 +812,62 @@ end
|
||||
|
||||
|
||||
|
||||
# function conversation(a::T, userinput::Dict) where {T<:agent}
|
||||
|
||||
# # get new user msg from a.receiveUserMsgChannel
|
||||
|
||||
|
||||
# # "newtopic" command to delete chat history
|
||||
# if userinput[:text] == "newtopic"
|
||||
# clearhistory(a)
|
||||
|
||||
# return "Okay. What shall we talk about?"
|
||||
|
||||
# else
|
||||
# # add usermsg to a.chathistory
|
||||
# addNewMessage(a, "user", userinput[:text])
|
||||
|
||||
# currentstate =
|
||||
# if isempty(a.plan[:currenttrajectory])
|
||||
# # set up initial state
|
||||
# Dict{Symbol, Any}(
|
||||
# # deepcopy the info to prevent modifying the info unintentionally during MCTS planning
|
||||
# :customerinfo=> deepcopy(a.keywordinfo[:customerinfo]),
|
||||
# :storeinfo=> deepcopy(a.keywordinfo[:storeinfo]),
|
||||
# :userselect=> nothing,
|
||||
# :reward=> 0,
|
||||
# :isterminal=> false,
|
||||
# :evaluation=> nothing,
|
||||
# :lesson=> nothing,
|
||||
# :thoughtDict=> nothing,
|
||||
# :totalTrajectoryReward=> nothing,
|
||||
# :thoughtHistory=> OrderedDict{Symbol, Any}( # contain question, thought_1, action_1, observation_1, thought_2, ...
|
||||
# # :recap=>,
|
||||
# :question=> userinput[:text],
|
||||
# )
|
||||
# )
|
||||
# else
|
||||
# a.plan[:currenttrajectory]
|
||||
# end
|
||||
|
||||
# bestNextState, besttrajectory = runMCTS(a, currentstate, decisionMaker, evaluator, reflector,
|
||||
# totalsample=3, maxDepth=2, maxiterations=1, explorationweight=1.0)
|
||||
|
||||
# # transition
|
||||
# newstate = transition(a, bestNextState)
|
||||
# a.plan[:currenttrajectory] = newstate
|
||||
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user