This commit is contained in:
2023-11-21 01:33:20 +00:00
parent f8ca8b757b
commit 8b351b1279

View File

@@ -62,7 +62,7 @@ abstract type agent end
thought::String = "nothing" # contain unfinished thoughts for ReAct agent only
thoughtround::Int = 0 # no. of thinking round
thoughtlimit::Int = 5 # thinking round limit
thinkingMode::Union{Dict, Nothing} = nothing
thinkingMode::Union{Dict, Nothing} = nothing
end
function agentReact(
@@ -90,8 +90,8 @@ function agentReact(
""",
),
thinkingMode::Dict=Dict(
:nothinking=> "",
:react=>
:no_thinking=> "",
:thinking=>
"""Use the following format:
Question: the input question your user is asking and you must answer
Plan: first you should always think about the question and the info you have thoroughly then extract and devise a complete plan to find the answer (pay attention to variables and their corresponding numerals).
@@ -362,7 +362,7 @@ function conversation(a::T, usermsg::String) where {T<:agent}
else # new thought
thinkingmode = chooseThinkingMode(a, usermsg)
@show thinkingmode
if thinkingmode == :nothinking
if thinkingmode == :no_thinking
a.context = conversationSummary(a) #TODO should be long conversation before use summary because it leaves out details
_ = addNewMessage(a, "user", usermsg)
prompt = generatePrompt_mistral_openorca(a, usermsg, thinkingmode)
@@ -372,7 +372,7 @@ function conversation(a::T, usermsg::String) where {T<:agent}
respond = replace(respond, "\n" => "")
_ = addNewMessage(a, "assistant", respond)
@show respond
elseif thinkingmode == :react
elseif thinkingmode == :thinking
a.context = conversationSummary(a)
_ = addNewMessage(a, "user", usermsg)
prompt = generatePrompt_mistral_openorca(a, usermsg, thinkingmode)
@@ -387,8 +387,9 @@ end
"""
Continuously run llm functions except when llm is getting Answer: or chatbox.
There are many work() depend on thinking mode.
"""
function work(a::T, prompt::String, maxround::Int=3) where {T<:agent}
function work_react(a::T, prompt::String, maxround::Int=3) where {T<:agent}
respond = nothing
while true
a.thoughtround += 1
@@ -746,7 +747,7 @@ function chooseThinkingMode(a::T, usermsg::String) where {T<:agent}
prompt = replace(prompt, "{input}" => usermsg)
result = sendReceivePrompt(a, prompt)
willusetools = GeneralUtils.getStringBetweenCharacters(result, "{", "}")
thinkingMode = willusetools == "yes" ? :react : :nothinking
thinkingMode = willusetools == "yes" ? :thinking : :no_thinking
return thinkingMode
end