This commit is contained in:
narawat lamaiin
2024-03-24 19:11:10 +07:00
parent 145006eba4
commit a4acd42107
4 changed files with 85 additions and 65 deletions

View File

@@ -152,6 +152,7 @@ end
function planner_mistral_openorca(a::agentReflex)
"""
general prompt format:
@@ -180,6 +181,7 @@ function planner_mistral_openorca(a::agentReflex)
"""
conversation = messagesToString(a.messages)
toollines = ""
for (toolname, v) in a.tools
if toolname [""]
@@ -191,14 +193,14 @@ function planner_mistral_openorca(a::agentReflex)
# skip objective and plan because LLM is going to generate new plan
shorttermMemory = dictToString(a.memory[:shortterm], skiplist=["Objective:", "Plan 1:"])
@show "---> 2"
aboutYourself =
"""
Your name is $(a.agentName)
Your name is $(a.name)
$(a.roles[a.role])
$(a.roleSpecificInstruction[a.role])
"""
@show "---> 3"
# assistant_plan_prompt =
# """
# <s>
@@ -233,7 +235,7 @@ function planner_mistral_openorca(a::agentReflex)
# Plan:
# """
assistant_plan_prompt =
prompt =
"""
<|im_start|>system
<About yourself>
@@ -266,9 +268,9 @@ function planner_mistral_openorca(a::agentReflex)
Plan:
"""
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic], max_tokens=512,
timeout=180, stopword=["<|user|>", "</"])
response = sendReceivePrompt(a, assistant_plan_prompt, max_tokens=1024, temperature=0.1,
timeout=180, stopword=["<|user|>", "</"])
response = split(response, "<|")[1]
response = split(response, "</")[1]
response = split(response, "\n\n")[1]
@@ -336,7 +338,8 @@ function updatePlan(a::agentReflex)
Updated plan:
"""
result = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.1)
result = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
timeout=180, stopword=["<|", "</"])
@show updatedPlan = result
a.memory[:shortterm]["Plan 1:"] = result
@@ -369,7 +372,7 @@ function selfAwareness(a::agentReflex)
aboutYourself =
"""
Your name is $(a.agentName)
Your name is $(a.name)
$(a.roles[a.role])
"""
@@ -420,8 +423,9 @@ function selfAwareness(a::agentReflex)
<|assistant|>
Info extraction:
"""
response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.4, timeout=180,
stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
response = split(response, "<|")[1]
response = split(response, "</")[1]
response = split(response, "</|assistant|>")[1]
@@ -483,7 +487,7 @@ function sentenceToKeywordMemory(a::agentReflex)
aboutYourself =
"""
Your name is $(a.agentName)
Your name is $(a.name)
$(a.roles[a.role])
"""
@@ -531,8 +535,9 @@ function sentenceToKeywordMemory(a::agentReflex)
<|assistant|>
Info extraction:
"""
response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.2, timeout=180,
stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.2, timeout=180,
stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
response = split(response, "<|")[1]
response = split(response, "</")[1]
response = split(response, "</|assistant|>")[1]
@@ -565,7 +570,7 @@ function keywordMemoryToPlanMatching(a::agentReflex)
aboutYourself =
"""
Your name is $(a.agentName)
Your name is $(a.name)
$(a.roles[a.role])
"""
@@ -608,8 +613,9 @@ function keywordMemoryToPlanMatching(a::agentReflex)
<|assistant|>
Info mapping:
"""
response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.4, timeout=180,
stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
response = split(response, "<|")[1]
response = split(response, "</")[1]
response = split(response, "</|assistant|>")[1]
@@ -706,7 +712,7 @@ end
# # your should request the missing information first before making a decision
# aboutYourself =
# """
# Your name is $(a.agentName)
# Your name is $(a.name)
# $(a.roles[a.role])
# """
@@ -922,7 +928,7 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
# your should request the missing information first before making a decision
aboutYourself =
"""
Your name is $(a.agentName)
Your name is $(a.name)
$(a.roles[a.role])
"""
@@ -963,7 +969,7 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
<s>
<|system|>
<About yourself>
Your name is $(a.agentName)
Your name is $(a.name)
$(a.roles[a.role])
</About yourself>
<You have access to the following tools>
@@ -994,7 +1000,7 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
<s>
<|system|>
<About yourself>
Your name is $(a.agentName)
Your name is $(a.name)
$(a.roles[a.role])
</About yourself>
<You have access to the following tools>
@@ -1029,10 +1035,10 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
latestTask = nothing
while true # while Thought or Act is empty, run actor again
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.4, timeout=300,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>"],
seed=rand(1000000:2000000))
println("")
@show actor_raw = response
@@ -1273,13 +1279,16 @@ function work(a::agentReflex)
end
end
end
while true # Work loop
objective = nothing
# make new plan
if !haskey(a.memory[:shortterm], "Plan 1:")
plan = planner_mistral_openorca(a)
a.memory[:shortterm]["Plan $(a.attempt):"] = plan
a.memory[:log]["Plan $(a.attempt):"] = plan
a.task = 1 # reset because new plan is created
@@ -1295,7 +1304,7 @@ function work(a::agentReflex)
# enter actor loop
actorstate, msgToUser = actor(a)
if actorstate == "askbox"
response = msgToUser
workstate = actorstate
@@ -1488,7 +1497,9 @@ function writeEvaluationGuideline(a::agentReflex)
"""
response = sendReceivePrompt(a, prompt)
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
return response
end
@@ -1553,7 +1564,9 @@ function grading(a, guideline::T, text::T) where {T<:AbstractString}
println("")
score = nothing
while true
response = sendReceivePrompt(a, prompt, timeout=180)
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
try
response = "{" * split(response, "}")[1] * "}"
@show response
@@ -1619,7 +1632,9 @@ function analyze(a)
"""
response = sendReceivePrompt(a, prompt, max_tokens=1024, timeout=180)
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
return response
end
@@ -1677,7 +1692,9 @@ function selfReflext(a, analysis::T) where {T<:AbstractString}
"""
response = sendReceivePrompt(a, prompt, max_tokens=1024)
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
return response
end
@@ -1737,7 +1754,9 @@ function formulateUserResponse(a)
<|assistant|>
Recommendation:
"""
response = sendReceivePrompt(a, prompt, max_tokens=1024, timeout=300)
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=300,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
return response
end
@@ -1803,7 +1822,9 @@ function extractinfo(a, text::T) where {T<:AbstractString}
</s>
Answer:
"""
response = sendReceivePrompt(a, prompt, temperature=0.0)
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
if occursin("Yes", response)
prompt =
"""
@@ -1819,7 +1840,9 @@ function extractinfo(a, text::T) where {T<:AbstractString}
"""
response = sendReceivePrompt(a, prompt, temperature=0.0)
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
return response
else
return nothing
@@ -1861,7 +1884,9 @@ function updateEnvState(a, newinfo)
Updated Current State:\n
"""
response = sendReceivePrompt(a, prompt, temperature=0.0)
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
return response
end
@@ -1934,7 +1959,9 @@ function checkTaskCompletion(a)
"""
response = nothing
_response = nothing
_response = sendReceivePrompt(a, prompt, max_tokens=1024)
_response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
@show checkTaskCompletion_raw = _response
_response = split(_response, "</")[1]
_response = split(_response, "\n\n")[1]
@@ -2030,7 +2057,9 @@ function recap(a)
Extracted info:
"""
aware = "Self-awareness: map the info from the recap to the plan's tasks then state your mapping."
response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.0)
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
response = split(response, "</")[1]
response = split(response, "<|")[1]
response = split(response, "\n\n")[1]
@@ -2121,7 +2150,7 @@ function readKeywordMemory(a; keywordmemory::Union{AbstractDict, Nothing}=nothin
<s>
<|system|>
<About yourself>
Your name is $(a.agentName)
Your name is $(a.name)
$(a.roles[a.role])
</About yourself>
<Your job>
@@ -2148,7 +2177,9 @@ function readKeywordMemory(a; keywordmemory::Union{AbstractDict, Nothing}=nothin
<|assistant|>
"""
response = sendReceivePrompt(a, prompt, max_tokens=512, temperature=0.0)
response = sendReceivePrompt(a, prompt, a.config[:text2text][:mqtttopic],
max_tokens=1024, temperature=0.4, timeout=180,
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>", "<|user|>"])
response = split(response, "</|assistant|>")[1]
# store LLM readout string to result