update
This commit is contained in:
@@ -235,7 +235,7 @@ function chat_mistral_openorca(a::agentReflex)
|
||||
end
|
||||
|
||||
#WORKING
|
||||
function planner_mistral_openorca(a::agentReflex, objective::T) where {T<:AbstractString}
|
||||
function planner_mistral_openorca(a::agentReflex)
|
||||
"""
|
||||
general prompt format:
|
||||
|
||||
@@ -263,6 +263,15 @@ function planner_mistral_openorca(a::agentReflex, objective::T) where {T<:Abstra
|
||||
"
|
||||
"""
|
||||
|
||||
conversation = messagesToString(a.messages)
|
||||
toollines = ""
|
||||
for (toolname, v) in a.tools
|
||||
if toolname ∉ ["chatbox"]
|
||||
toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
|
||||
toollines *= toolline
|
||||
end
|
||||
end
|
||||
|
||||
assistant_plan_prompt =
|
||||
"""
|
||||
<|im_start|>system
|
||||
@@ -282,16 +291,21 @@ function planner_mistral_openorca(a::agentReflex, objective::T) where {T<:Abstra
|
||||
Use the following format:
|
||||
Objective: the objective you intend to do
|
||||
Plan: first you should always think about the objective, the info you need and the info you have thoroughly then extract and devise a step by step plan (pay attention to correct numeral calculation and commonsense).
|
||||
p.s.1 each step should be a single action.
|
||||
p.s.2 don't respond to the stimulus yet.
|
||||
p.s.1 each step of the plan should be a single action.
|
||||
<|im_end|>
|
||||
$conversation
|
||||
<|im_start|>assistant
|
||||
Objective: $objective
|
||||
Plan:
|
||||
Objective:
|
||||
"""
|
||||
plan = sendReceivePrompt(a, assistant_plan_prompt, temperature=0.2)
|
||||
result = sendReceivePrompt(a, assistant_plan_prompt, max_tokens=1024, temperature=0.2)
|
||||
@show raw_plan = result
|
||||
x = split(result, "<|im_end|>")[1]
|
||||
x = split(x, "Step")[1]
|
||||
x = split(x, "Plan:")
|
||||
objective = x[1]
|
||||
plan = x[2]
|
||||
|
||||
return plan
|
||||
return objective, plan
|
||||
end
|
||||
|
||||
|
||||
@@ -501,16 +515,16 @@ function conversation(a::agentReflex, usermsg::String; attemptlimit::Int=3)
|
||||
|
||||
# a.earlierConversation = conversationSummary(a)
|
||||
_ = addNewMessage(a, "user", usermsg)
|
||||
isusetools, objective = isUseTools(a)
|
||||
isusetools = isUseTools(a)
|
||||
# newinfo = extractinfo(a, usermsg)
|
||||
# a.env = newinfo !== nothing ? updateEnvState(a, newinfo) : a.env
|
||||
@show isusetools
|
||||
|
||||
if isusetools # use tools before responseing
|
||||
response = work(a, objective)
|
||||
response = work(a)
|
||||
end
|
||||
|
||||
response = chat_mistral_openorca(a)
|
||||
|
||||
response = chat_mistral_openorca(a) #TODO if chatbox is used, skip this
|
||||
response = removeTrailingCharacters(response)
|
||||
_ = addNewMessage(a, "assistant", response)
|
||||
|
||||
@@ -520,17 +534,19 @@ end
|
||||
"""
|
||||
Continuously run llm functions except when llm is getting Answer: or chatbox.
|
||||
There are many work() depend on thinking mode.
|
||||
""" #WORKING add plan and actor
|
||||
function work(a::agentReflex, objective::T) where {T<:AbstractString}
|
||||
"""
|
||||
function work(a::agentReflex)
|
||||
actorstate = nothing
|
||||
response = nothing
|
||||
error(1)
|
||||
a.memory[:shortterm] = OrderedDict{String, Any}()
|
||||
a.memory[:log] = OrderedDict{String, Any}()
|
||||
a.memory[:shortterm]["user:"] = objective
|
||||
a.memory[:log]["user:"] = objective
|
||||
a.newplan = true
|
||||
|
||||
while true # Work loop
|
||||
#WORKING
|
||||
a.memory[:shortterm] = OrderedDict{String, Any}()
|
||||
a.memory[:log] = OrderedDict{String, Any}()
|
||||
|
||||
|
||||
|
||||
|
||||
# plan
|
||||
if a.attempt <= a.attemptlimit
|
||||
toolname = nothing
|
||||
@@ -538,17 +554,17 @@ function work(a::agentReflex, objective::T) where {T<:AbstractString}
|
||||
if a.newplan == true
|
||||
a.attempt += 1
|
||||
a.step = 0
|
||||
prompt_plan = planner_mistral_openorca(a)
|
||||
objective, plan = planner_mistral_openorca(a)
|
||||
println("")
|
||||
@show prompt_plan
|
||||
response = sendReceivePrompt(a, prompt_plan, max_tokens=1024)
|
||||
@show objective
|
||||
@show plan
|
||||
|
||||
# sometimes LLM add not-need word I don't want
|
||||
plan = splittext(response, ["Step 1", "<|im_end|>", "Response", "Execution",
|
||||
"Result", "Recommendation", "My response"])
|
||||
# plan = splittext(response, ["Step 1", "<|im_end|>", "Response", "Execution",
|
||||
# "Result", "Recommendation", "My response"])
|
||||
# plan = replace(plan, "Plan:"=>"")
|
||||
println("")
|
||||
@show plan
|
||||
# println("")
|
||||
# @show plan
|
||||
|
||||
a.newplan = false
|
||||
a.memory[:shortterm]["Plan $(a.attempt):"] = plan
|
||||
@@ -626,7 +642,7 @@ function work(a::agentReflex, objective::T) where {T<:AbstractString}
|
||||
|
||||
# communicates with user
|
||||
_ = addNewMessage(a, "assistant", response)
|
||||
return response
|
||||
return actorstate, response
|
||||
end
|
||||
|
||||
|
||||
|
||||
10
src/utils.jl
10
src/utils.jl
@@ -403,16 +403,16 @@ function isUseTools(a::agentReflex)
|
||||
|
||||
# if LLM mentions any tools, use Plan/Thought/Act loop
|
||||
isusetool = false
|
||||
objective = sendReceivePrompt(a, prompt, temperature=0.2)
|
||||
response = sendReceivePrompt(a, prompt, temperature=0.0)
|
||||
response = split(response, "<|im_end|>")[1]
|
||||
for (toolname, v) in a.tools
|
||||
if occursin(toolname, objective)
|
||||
if occursin(toolname, response)
|
||||
isusetool = true
|
||||
break
|
||||
end
|
||||
end
|
||||
@show objective
|
||||
|
||||
return isusetool, objective
|
||||
|
||||
return isusetool
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user