update
This commit is contained in:
138
src/interface.jl
138
src/interface.jl
@@ -292,11 +292,14 @@ function planner_mistral_openorca(a::agentReflex)
|
||||
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 of the plan should be a single action.
|
||||
p.s.2 make sure you gather all the required information.
|
||||
<|im_end|>
|
||||
$conversation
|
||||
<|im_start|>assistant
|
||||
Objective:
|
||||
"""
|
||||
# p.s.2 the last step should be about responding.
|
||||
|
||||
result = sendReceivePrompt(a, assistant_plan_prompt, max_tokens=1024, temperature=0.2)
|
||||
@show raw_plan = result
|
||||
x = split(result, "<|im_end|>")[1]
|
||||
@@ -396,7 +399,6 @@ end
|
||||
# return prompt
|
||||
# end
|
||||
|
||||
|
||||
function actor_mistral_openorca(a::agentReflex)
|
||||
"""
|
||||
general prompt format:
|
||||
@@ -430,20 +432,16 @@ function actor_mistral_openorca(a::agentReflex)
|
||||
prompt =
|
||||
"""
|
||||
<|im_start|>system
|
||||
{role}
|
||||
$(a.roles[a.role])
|
||||
{tools}
|
||||
{thinkingFormat}
|
||||
$(a.thinkingFormat[:actor])
|
||||
{context}
|
||||
<|im_end|>
|
||||
{shorttermMemory}
|
||||
Thought $(a.step):
|
||||
"""
|
||||
|
||||
prompt = replace(prompt, "{role}" => a.roles[a.role])
|
||||
prompt = replace(prompt, "{thinkingFormat}" => a.thinkingFormat[:actor])
|
||||
prompt = replace(prompt, "{step}" => a.step)
|
||||
|
||||
s = dictToString(a.memory[:shortterm], ["user:", "Plan 1:"])
|
||||
s = dictToString(a.memory[:shortterm], skiplist=["user:", "Plan 1:"])
|
||||
prompt = replace(prompt, "{shorttermMemory}" => s)
|
||||
|
||||
toolnames = ""
|
||||
@@ -455,9 +453,13 @@ function actor_mistral_openorca(a::agentReflex)
|
||||
end
|
||||
prompt = replace(prompt, "{toolnames}" => toolnames)
|
||||
prompt = replace(prompt, "{tools}" => "You have access to the following tools:\n$toollines")
|
||||
|
||||
conversation = messagesToString_nomark(a.messages, addressAIas="I")
|
||||
|
||||
context =
|
||||
"""
|
||||
Your talk with the user:
|
||||
$conversation
|
||||
{env state}
|
||||
{longterm memory}
|
||||
{plan}
|
||||
@@ -471,6 +473,80 @@ function actor_mistral_openorca(a::agentReflex)
|
||||
return prompt
|
||||
end
|
||||
|
||||
# function actor_mistral_openorca(a::agentReflex)
|
||||
# """
|
||||
# general prompt format:
|
||||
|
||||
# "
|
||||
# <|im_start|>system
|
||||
# {role}
|
||||
# {tools}
|
||||
# {thinkingFormat}
|
||||
# <|im_end|>
|
||||
# {context}
|
||||
# <|im_start|>user
|
||||
# {usermsg}
|
||||
# <|im_end|>
|
||||
# <|im_start|>assistant
|
||||
|
||||
# "
|
||||
|
||||
# Note:
|
||||
# {context} =
|
||||
# "
|
||||
# {earlierConversation}
|
||||
# {env state}
|
||||
# {shortterm memory}
|
||||
# {longterm memory}
|
||||
# "
|
||||
# """
|
||||
|
||||
# mark = "$(a.step)"
|
||||
|
||||
# prompt =
|
||||
# """
|
||||
# <|im_start|>system
|
||||
# {role}
|
||||
# {tools}
|
||||
# {thinkingFormat}
|
||||
# {context}
|
||||
# <|im_end|>
|
||||
# {shorttermMemory}
|
||||
# Thought $(a.step):
|
||||
# """
|
||||
|
||||
# prompt = replace(prompt, "{role}" => a.roles[a.role])
|
||||
# prompt = replace(prompt, "{thinkingFormat}" => a.thinkingFormat[:actor])
|
||||
# prompt = replace(prompt, "{step}" => a.step)
|
||||
|
||||
# s = dictToString(a.memory[:shortterm], skiplist=["user:", "Plan 1:"])
|
||||
# prompt = replace(prompt, "{shorttermMemory}" => s)
|
||||
|
||||
# toolnames = ""
|
||||
# toollines = ""
|
||||
# for (toolname, v) in a.tools
|
||||
# toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
|
||||
# toollines *= toolline
|
||||
# toolnames *= "$toolname, "
|
||||
# end
|
||||
# prompt = replace(prompt, "{toolnames}" => toolnames)
|
||||
# prompt = replace(prompt, "{tools}" => "You have access to the following tools:\n$toollines")
|
||||
|
||||
# context =
|
||||
# """
|
||||
# {env state}
|
||||
# {longterm memory}
|
||||
# {plan}
|
||||
# """
|
||||
# # context = replace(context, "{earlierConversation}" => "My earlier talk with the user:\n$(a.earlierConversation)")
|
||||
# context = replace(context, "{env state}" => "")
|
||||
# context = replace(context, "{longterm memory}" => "")
|
||||
# context = replace(context, "{plan}" => "My plan:\n$(a.memory[:shortterm]["Plan $(a.attempt):"])")
|
||||
# prompt = replace(prompt, "{context}" => context)
|
||||
|
||||
# return prompt
|
||||
# end
|
||||
|
||||
|
||||
|
||||
"""
|
||||
@@ -526,7 +602,7 @@ function conversation(a::agentReflex, usermsg::String; attemptlimit::Int=3)
|
||||
end
|
||||
|
||||
# if LLM using chatbox, use returning msg form chatbox as conversation response
|
||||
if workstate == "chatbox" ?
|
||||
if workstate == "chatbox"
|
||||
#TODO paraphrase msg so that it is human friendlier word.
|
||||
else
|
||||
response = chat_mistral_openorca(a)
|
||||
@@ -916,8 +992,6 @@ function actor(a::agentReflex)
|
||||
a.memory[:shortterm] = removeHeaders(a.memory[:shortterm], a.step, ["Plan"])
|
||||
a.memory[:log] = removeHeaders(a.memory[:log], a.step, ["Plan"])
|
||||
println("repeating step $(a.step)")
|
||||
|
||||
#WORKING
|
||||
else
|
||||
error("undefined condition decision = $decision $(@__LINE__)")
|
||||
end
|
||||
@@ -1238,7 +1312,7 @@ julia> report = formulateUserresponse(agent, shorttermMemory)
|
||||
```
|
||||
"""
|
||||
function formulateUserresponse(a)
|
||||
stimulus = a.memory[:shortterm]["user:"]
|
||||
stimulus = a.memory[:shortterm]["user:"] #BUG no "user" key
|
||||
|
||||
work = dictToString(a.memory[:shortterm], ["user:"])
|
||||
|
||||
@@ -1294,34 +1368,10 @@ julia> shorttermMemory = OrderedDict{String, Any}(
|
||||
julia> decision = goNogo(agent)
|
||||
"Yes"
|
||||
```
|
||||
"""
|
||||
""" #WORKING add choice skip, if LLM already completed the step
|
||||
function goNogo(a)
|
||||
stimulus = a.memory[:shortterm]["user:"]
|
||||
work = dictToString(a.memory[:shortterm], ["user:"])
|
||||
|
||||
# prompt =
|
||||
# """
|
||||
# <|im_start|>system
|
||||
# Symbol meaning:
|
||||
# Stimulus: the input user gives to you and you must response
|
||||
# Plan: a plan
|
||||
# Thought: your thought
|
||||
# Act: the action you took
|
||||
# Actinput: the input to the action
|
||||
# Obs: the result of the action
|
||||
|
||||
# Stimulus:
|
||||
# $stimulus
|
||||
|
||||
# Your work:
|
||||
# $work
|
||||
|
||||
# From your work, you job is to decide what to do next by choosing one of the following choices:
|
||||
# If you are ready to do the next step of the plan say, "{Yes}". And what is the rationale behind the decision?
|
||||
# If you need to repeat the latest step say, "{No}". And what is the rationale behind the decision?
|
||||
# If you are ready to formulate a final response to user original stimulus say, {formulateUserresponse}. And what is the rationale behind the decision?
|
||||
# <|im_end|>
|
||||
# """
|
||||
# stimulus = a.memory[:shortterm]["user:"]
|
||||
work = dictToString(a.memory[:shortterm])
|
||||
|
||||
prompt =
|
||||
"""
|
||||
@@ -1334,24 +1384,18 @@ function goNogo(a)
|
||||
Actinput: the input to the action
|
||||
Obs: the result of the action
|
||||
|
||||
Stimulus:
|
||||
$stimulus
|
||||
|
||||
Your work:
|
||||
$work
|
||||
|
||||
Your job is to check whether step $(a.step) of your work is completed according to the plan and choose only one of the following choices.
|
||||
choice 1: If you are ready to do the next step of the plan say, "{Yes}". And what is the rationale behind the decision?
|
||||
choice 2: If you need to repeat the latest step say, "{No}". And what is the rationale behind the decision?
|
||||
choice 1: If you get what you intend to do and you are ready to do the next step of the plan say, "{Yes}". And what is the rationale behind the decision to do the next step?
|
||||
choice 2: If you didn't get what you intend to do and you need to repeat the latest step say, "{No}". And what is the rationale behind the decision to repeat the latest step?
|
||||
<|im_end|>
|
||||
<|im_start|>assistant
|
||||
|
||||
"""
|
||||
|
||||
response = sendReceivePrompt(a, prompt)
|
||||
|
||||
|
||||
|
||||
decision = nothing
|
||||
reason = nothing
|
||||
if occursin("Yes", response)
|
||||
|
||||
Reference in New Issue
Block a user