This commit is contained in:
2023-11-23 12:50:24 +00:00
parent 18d4c62f40
commit d659202c05

View File

@@ -4,7 +4,7 @@ module interface
export agentReact, agentReflex,
addNewMessage, clearMessage, removeLatestMsg, generatePrompt_tokenPrefix,
generatePrompt_tokenSuffix, conversation, work, detectCharacters, chunktext,
findDetectedCharacter, wikisearch, sendReceivePrompt
findDetectedCharacter, wikisearch, sendReceivePrompt, extractStepFromPlan
using JSON3, DataStructures, Dates, UUIDs, HTTP
using CommUtils, GeneralUtils
@@ -618,14 +618,15 @@ function work(a::agentReflex, usermsg::String)
a.attempt += 1
@show a.attempt
@show usermsg
# a.thoughtlog *=
a.thoughtlog *= "$usermsg\n"
toolname = nothing
toolinput = nothing
prompt = planner_mistral_openorca(a, usermsg)
@show prompt
respond = sendReceivePrompt(a, prompt)
plan = split(respond, "<|im_end|>")[1]
@show respond
@show plan
a.thoughtlog *= plan
a.step = 0
while true # execute step by step
a.step += 1
@@ -634,9 +635,11 @@ function work(a::agentReflex, usermsg::String)
@show task
if isstep
respond = actor_mistral_openorca(a, task)
error("work done")
error("work done 1")
else # finish all steps
error("work done 2")
break
end
@@ -1130,16 +1133,29 @@ function extractStepFromPlan(a::agent, plan::T) where {T<:AbstractString}
"""
isStep = nothing
step = nothing
respond = sendReceivePrompt(a, prompt)
isStep = GeneralUtils.getStringBetweenCharacters(respond, "{", "}")
if isStep == "no"
isStep = false
step = "nothing"
elseif isStep == "yes"
isStep = true
step = split(respond, "{yes}")[end]
else
error("undefined condition. isStep=$isStep $(@__LINE__)")
for i in 1:3
@show prompt
respond = sendReceivePrompt(a, prompt)
@show respond
isStep = GeneralUtils.getStringBetweenCharacters(respond, "{", "}")
@show isStep
if isStep == "no"
isStep = false
step = "nothing"
break
elseif isStep == "yes"
isStep = true
step = split(respond, "{yes}")[end]
break
else
# keep trying
isStep = nothing
step = nothing
end
end
if isStep === nothing && step === nothing
error("undefined condition. step $(a.step) isStep=$isStep $(@__LINE__)")
end
return isStep, step