update
This commit is contained in:
@@ -283,11 +283,7 @@ function planner_mistral_openorca(a::agentReflex, usermsg::String)
|
||||
{thinkingFormat}
|
||||
<|im_end|>
|
||||
{context}
|
||||
<|im_start|>user
|
||||
{usermsg}
|
||||
<|im_end|>
|
||||
<|im_start|>assistant
|
||||
|
||||
{shorttermMemory}
|
||||
"""
|
||||
prompt = replace(prompt, "{role}" => a.roles[a.role])
|
||||
prompt = replace(prompt, "{thinkingFormat}" => a.thinkingFormat[:planner])
|
||||
@@ -303,24 +299,35 @@ function planner_mistral_openorca(a::agentReflex, usermsg::String)
|
||||
prompt = replace(prompt, "{tools}" => "You have access to the following tools:\n$toollines")
|
||||
|
||||
context =
|
||||
"""
|
||||
{earlierConversation}
|
||||
{env state}
|
||||
{longterm memory}
|
||||
"""
|
||||
"""
|
||||
{earlierConversation}
|
||||
{env state}
|
||||
{longterm memory}
|
||||
"""
|
||||
context = replace(context, "{earlierConversation}" => "My earlier talk with the user:\n$(a.earlierConversation)")
|
||||
context = replace(context, "{env state}" => "")
|
||||
context = replace(context, "{longterm memory}" => "")
|
||||
|
||||
prompt = replace(prompt, "{context}" => context)
|
||||
|
||||
prompt = replace(prompt, "{usermsg}" => "Stimulus: $usermsg")
|
||||
# initialize short term memory
|
||||
txt =
|
||||
"""
|
||||
<|im_start|>user
|
||||
{usermsg}
|
||||
<|im_end|>
|
||||
<|im_start|>assistant
|
||||
|
||||
"""
|
||||
txt = replace(txt, "{usermsg}" => "Stimulus: $usermsg")
|
||||
a.memory[:shortterm] = txt
|
||||
prompt = replace(prompt, "{shorttermMemory}" => a.memory[:shortterm])
|
||||
|
||||
return prompt
|
||||
end
|
||||
|
||||
#WORKING try use Thought/Act/ActInput/Obs loop because some time step 2 depend on step 1
|
||||
function actor_mistral_openorca(a::agentReflex, usermsg, plan, step)
|
||||
function actor_mistral_openorca(a::agentReflex)
|
||||
"""
|
||||
general prompt format:
|
||||
|
||||
@@ -356,17 +363,13 @@ function actor_mistral_openorca(a::agentReflex, usermsg, plan, step)
|
||||
{thinkingFormat}
|
||||
<|im_end|>
|
||||
{context}
|
||||
<|im_start|>user
|
||||
{usermsg}
|
||||
<|im_end|>
|
||||
<|im_start|>assistant
|
||||
{plan}
|
||||
{shorttermMemory}
|
||||
"""
|
||||
|
||||
prompt = replace(prompt, "{role}" => a.roles[a.role])
|
||||
prompt = replace(prompt, "{thinkingFormat}" => a.thinkingFormat[:actor])
|
||||
prompt = replace(prompt, "{step}" => step)
|
||||
prompt = replace(prompt, "{plan}" => plan)
|
||||
prompt = replace(prompt, "{step}" => a.step)
|
||||
prompt = replace(prompt, "{shorttermMemory}" => a.memory[:shortterm])
|
||||
toolnames = ""
|
||||
toollines = ""
|
||||
for (toolname, v) in a.tools
|
||||
@@ -385,11 +388,8 @@ function actor_mistral_openorca(a::agentReflex, usermsg, plan, step)
|
||||
# context = replace(context, "{earlierConversation}" => "My earlier talk with the user:\n$(a.earlierConversation)")
|
||||
context = replace(context, "{env state}" => "")
|
||||
context = replace(context, "{longterm memory}" => "")
|
||||
|
||||
prompt = replace(prompt, "{context}" => context)
|
||||
|
||||
prompt = replace(prompt, "{usermsg}" => "Stimulus: $usermsg")
|
||||
|
||||
return prompt
|
||||
end
|
||||
|
||||
@@ -627,8 +627,6 @@ function work(a::agentReflex, usermsg::String)
|
||||
@show a.attempt
|
||||
@show usermsg
|
||||
if a.attempt <= a.attemptlimit
|
||||
logmsg = "user: $usermsg\n"
|
||||
a.memory[:shortterm] *= logmsg
|
||||
|
||||
toolname = nothing
|
||||
toolinput = nothing
|
||||
@@ -638,11 +636,9 @@ function work(a::agentReflex, usermsg::String)
|
||||
plan = split(respond, "<|im_end|>")[1]
|
||||
plan = split(plan, "Response:")[1]
|
||||
plan = replace(plan, "Plan:"=>"Plan $(a.attempt):")
|
||||
logmsg = "assistant: $plan\n"
|
||||
a.memory[:shortterm] *= logmsg
|
||||
a.thoughtlog *= logmsg
|
||||
actorstate, msgToUser = actor(a, usermsg, plan)
|
||||
|
||||
a.memory[:shortterm] *= plan
|
||||
actorstate, msgToUser = actor(a, plan)
|
||||
error("333")
|
||||
if actorstate == "chatbox"
|
||||
respond = msgToUser
|
||||
break
|
||||
@@ -680,7 +676,7 @@ function work(a::agentReflex, usermsg::String)
|
||||
@show chunkedtext
|
||||
push!(a.memory[:longterm], Dict(:context=>chunkedtext["Context:"],
|
||||
:lesson=>chunkedtext["Lesson:"]))
|
||||
error(">>>>>>>>>")
|
||||
error("22222222")
|
||||
end
|
||||
else
|
||||
error("undefied condition, actorstate $actorstate $(@__LINE__)")
|
||||
@@ -723,11 +719,10 @@ end
|
||||
msgToUser = "message from assistant to user"
|
||||
|
||||
"""
|
||||
function actor(a::agentReflex, usermsg, plan)
|
||||
function actor(a::agentReflex, plan)
|
||||
actorState = nothing
|
||||
msgToUser = nothing
|
||||
|
||||
@show plan
|
||||
totalsteps = checkTotalStepInPlan(a, plan)
|
||||
|
||||
a.step = 0
|
||||
@@ -736,11 +731,11 @@ function actor(a::agentReflex, usermsg, plan)
|
||||
@show a.step
|
||||
if a.step <= totalsteps
|
||||
# WORKING in step 2, I need to use a.memory[:shortterm] as input to actor()
|
||||
prompt = actor_mistral_openorca(a, usermsg, plan, a.step)
|
||||
prompt = actor_mistral_openorca(a)
|
||||
@show prompt
|
||||
respond = sendReceivePrompt(a, prompt)
|
||||
@show respond
|
||||
|
||||
|
||||
# some time LLM not generate a number after headers but I want it
|
||||
if occursin("Act:", respond)
|
||||
headerToDetect = ["Question:", "Plan:", "Thought:",
|
||||
@@ -754,7 +749,7 @@ function actor(a::agentReflex, usermsg, plan)
|
||||
|
||||
# add to memory
|
||||
a.memory[:shortterm] *= respond
|
||||
a.thoughtlog *= respond
|
||||
error("111")
|
||||
headerToDetect = ["Question $(a.step):", "Plan $(a.step):", "Thought $(a.step):",
|
||||
"Act $(a.step):", "ActInput $(a.step):", "Obs $(a.step):", "...",
|
||||
"Answer $(a.step):", "Conclusion $(a.step):", "Summary $(a.step):"]
|
||||
|
||||
Reference in New Issue
Block a user