This commit is contained in:
2023-12-03 14:41:56 +00:00
parent 07555c2613
commit e6c464c96e
3 changed files with 30 additions and 23 deletions

View File

@@ -373,7 +373,7 @@ function actor_mistral_openorca(a::agentReflex)
{context}
<|im_end|>
{shorttermMemory}
Thought:
Thought $(a.step):
"""
prompt = replace(prompt, "{role}" => a.roles[a.role])
@@ -386,6 +386,9 @@ function actor_mistral_openorca(a::agentReflex)
if k ["user:", "Plan 1:"]
s1 = "$k $v"
s *= s1
if s[end] != "\n"
s *= "\n"
end
end
end
prompt = replace(prompt, "{shorttermMemory}" => s)
@@ -615,11 +618,13 @@ function conversation(a::agentReflex, usermsg::String; attemptlimit::Int=3)
a.earlierConversation = conversationSummary(a) #TODO should be long conversation before use summary because it leaves out details
_ = addNewMessage(a, "user", usermsg)
prompt = chat_mistral_openorca(a, usermsg)
println("")
@show prompt
respond = sendReceivePrompt(a, prompt)
respond = split(respond, "<|im_end|>")[1]
respond = replace(respond, "\n" => "")
_ = addNewMessage(a, "assistant", respond)
println("")
@show respond
else
respond = work(a, usermsg)
@@ -645,6 +650,7 @@ function work(a::agentReflex, usermsg::String)
println("continue_thinking!!")
_ = addNewMessage(a, "user", usermsg)
a.memory[:shortterm]["Obs $mark_actor:"] = usermsg
a.step += 1
a.memory[:log]["Obs $mark_actor:"] = usermsg
else
error("undefined condition thinkingmode = $thinkingmode $(@__LINE__)")
@@ -687,7 +693,7 @@ function work(a::agentReflex, usermsg::String)
elseif actorstate == "all steps done" #WORKING add canceled during plan
println("all steps done")
respond = formulateRespond(a)
respond = formulateUserRespond(a)
error("10")
a.memory[:shortterm]["Respond $mark_plan:"] = respond
@@ -777,30 +783,27 @@ function actor(a::agentReflex)
println("")
@show prompt_actor
respond = sendReceivePrompt(a, prompt_actor)
respond = split(respond, "Obs")[1]
respond = splittext(respond, ["Obs", "<|im_end|>"])
respond_actor_raw = respond
println("")
@show respond_actor_raw
if occursin("Thought", respond)
ind = findfirst(":", respond)[end]
respond = respond[ind+1:end]
if !occursin("Thought", respond)
respond = "Thought: " * respond
end
respond = "Thought: " * respond
headerToDetect = ["Question:", "Plan:", "Thought:",
"Act:", "ActInput:", "Obs:", "...",
"Answer:", "Conclusion:", "Summary:"]
# some time LLM not generate a number after headers but I want it
if occursin("Act:", respond)
headerToDetect = ["Question:", "Plan:", "Thought:",
"Act:", "ActInput:", "Obs:", "...",
"Answer:", "Conclusion:", "Summary:"]
headers = detectCharacters(respond, headerToDetect)
respond = replaceHeaders(respond, headers, a.step)
end
# replace headers with headers with correct attempt and step number
respond = replaceHeaders(respond, headerToDetect, a.step)
respond = split(respond, "<|im_end|>")[1]
headers = detectCharacters(respond, headerToDetect)
respond_actor = respond
println("")
@show respond_actor
mark_plan = "$(a.attempt)"
mark_actor = "$(a.step)"
headerToDetect = ["Plan $mark_plan:",
@@ -832,14 +835,15 @@ function actor(a::agentReflex)
toolresult = f(a, toolinput)
@show toolresult
a.memory[:shortterm]["Obs $mark_actor:"] = toolresult
a.step += 1
go, reason = goNogo(a)
@show go
a.memory[:shortterm]["Check $mark_actor:"] = reason
if go == "No" # in case there is a cancel, go straight to evaluation
a.step -= 1
error(113)
end
a.step += 1
end
else #TODO finish all steps
actorState = "all steps done"
@@ -1190,8 +1194,9 @@ function goNogo(a)
"""
respond = sendReceivePrompt(a, prompt)
decision = GeneralUtils.getStringBetweenCharacters(respond, "{", "}")
start = findfirst("}", respond) +1
start = findfirst("}", respond)[end] +1
reason = respond[start:end]
return decision, reason