This commit is contained in:
2023-12-29 05:37:58 +00:00
parent 6d41efa243
commit 96ccd5c639
2 changed files with 37 additions and 29 deletions

View File

@@ -337,15 +337,15 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
# $conversation
# """
start = "Thought"
start = "Thought:"
aware = ""
thought = "Thought: you should always think about what to do according to the plan (pay attention to correct numeral calculation and commonsense and do one thing at a time.)"
if length(a.memory[:shortterm]) > 2 # must have User:, Plan:, Thought:, Act:, Actinput:
start = "Self-awareness"
start = "Self-awareness:"
# aware = "Self-awareness: based on the recap, assess your progress against the plan then identify areas where you need to address."
# aware = "Self-awareness: based on the recap and the plan, state your current understanding of the matter in details then identify areas where you need to address."
# aware = "Self-awareness: Based on Obs, review your progress against the plan. Then, describe in detail the results you have achieved so far. Finally, describe in detail what you are missing. (focus on your actions and their results)"
aware = "Self-awareness: Based on Obs, check your progress against the plan. Then, repeat all the details of what you have been gathered. Finally, describe in detail what you are missing."
aware = "Self-awareness: Based on action's input and observed results, check your progress against the plan. Then, repeat all the details of what you have been gathered. Finally,describe in detail what you are missing."
thought = "Thought: you should always think about what to do according to self-awareness (1. let's think a single step. 2. focus on incomplete task 3. pay attention to correct numeral calculation and commonsense.)"
end
@@ -380,7 +380,7 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
</s>
<|assistant|>
$work
$start:
$start
"""
prompt = replace(prompt, "{toolnames}" => toolnames)
@@ -393,18 +393,20 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
tempcounter = 0.2
while true # while Thought or Act is empty, run actor again
# tempcounter += 0.1
tempcounter += 0.2
@show tempcounter
response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=tempcounter, timeout=180)
response = splittext(response, ["Obs", "<|im_end|>"])
latestTask = shortMemLatestTask(a.memory[:shortterm]) +1
if start == "Thought"
response = "Thought $latestTask: " * response
else
response = "Self-awareness $latestTask: " * response
end
# if start == "Thought:"
# response = "Thought $latestTask: " * response
# else
# response = "Self-awareness $latestTask: " * response
# end
response = start * response
headerToDetect = ["Question:", "Plan:", "Self-awareness:", "Thought:",
"Act:", "Actinput:", "Obs:", "...",
@@ -415,7 +417,7 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
response = split(response, "<|")[1]
response = split(response, "</")[1]
headers = detectCharacters(response, headerToDetect)
# headers = detectCharacters(response, headerToDetect)
println("")
@@ -720,7 +722,7 @@ function conversation(a::agentReflex, usermsg::String; attemptlimit::Int=3)
@show isuseplan
if isuseplan # use plan before responding
if haskey(a.memory[:shortterm], "User:") == false
if haskey(a.memory[:shortterm], "User:") == false #TODO should change role if user want to buy wine.
a.memory[:shortterm]["User:"] = usermsg
end
workstate, response = work(a)
@@ -952,17 +954,18 @@ function writeEvaluationGuideline(a::agentReflex)
prompt =
"""
<|im_start|>system
You have access to the following tools:
askbox: Useful for when you need to ask a customer for more context. Input should be a conversation to customer.
wikisearch: Useful for when you need to search an encyclopedia Input is keywords and not a question.
$(a.roles[a.role])
<You have access to the following tools>
askbox: Useful for when you need to ask a customer for more context. Input should be a conversation to customer.
wikisearch: Useful for when you need to search an encyclopedia Input is keywords and not a question.
</You have access to the following tools>
<Your job>
1. Write an evaluation guideline for wine recommendation in order to be able to evaluate your response.
2. An example of what the response should be.
</Your job>
</s>
<|assistant|>
Your work:
$(a.memory[:shortterm]["User:"])
Your job are:
1. Write an evaluation guideline for your work in order to be able to evaluate your response.
2. An example of what the response should be.
<|im_end|>
"""
response = sendReceivePrompt(a, prompt)
@@ -1016,13 +1019,13 @@ function grading(a, guideline::T, text::T) where {T<:AbstractString}
</Your response>
<Your job>
1. Evaluate your response using the evaluation guideline and an example response.
1. Evaluate your response using the evaluation guideline.
2. Give yourself a score out of 9 for your response.
</Your job>
<Example in JSON format>
<Your job example in JSON format>
{"Evaluate": "The response does not directly address user needs. It does not include price into account and other user mentioned factors", "Score": 6}
</Example in JSON format>
<|im_end|>
</Your job example in JSON format>
</s>
<assistant>
"""
@@ -1031,8 +1034,10 @@ function grading(a, guideline::T, text::T) where {T<:AbstractString}
@show prompt_grading
println("")
response = sendReceivePrompt(a, prompt)
@show response = JSON3.read(response)
score = response["Score"]
response = split(response, "}")[1] * "}"
@show response
@show jsonresponse = JSON3.read(response)
score = jsonresponse["Score"]
return score
end

View File

@@ -817,10 +817,13 @@ function replaceHeaders(text::T, headers, step::Int) where {T<:AbstractString}
header = i[1:end-1] # not include ":"
if occursin(header, newtext)
startind = findfirst(header, newtext)[1]
stopind = findnext(":", newtext, startind+1)[end] #BUG MethodError: no method matching lastindex(::Nothing)
stopind = findnext(":", newtext, startind+1)[end]
word = newtext[startind: stopind]
newword = "$header $step:"
newtext = replace(newtext, word=> newword)
if header == "Thought:"
error(1)
end
end
end