This commit is contained in:
2023-11-26 14:35:05 +00:00
parent efd01cb525
commit da983f2874
3 changed files with 69 additions and 19 deletions

View File

@@ -644,7 +644,8 @@ function work(a::agentReflex, usermsg::String)
elseif actorstate == "all steps done"
println("all steps done")
#WORKING give answer to the question
respond = formulateRespond()
respond = formulateRespond(a, a.memory[:shortterm])
a.memory[:shortterm] *= "Respond: $respond\n"
#TODO evaluate. if score < 8/10 try again.
headerToDetect = ["user:", "assistant:", ]
@@ -652,13 +653,13 @@ function work(a::agentReflex, usermsg::String)
chunkedtext = chunktext(a.memory[:shortterm], headers)
stimulus = chunkedtext["user:"]
guideline = writeEvaluationGuideline(a, stimulus)
score = grading(a, guideline, a.memory[:shortterm])
@show guideline
score = grading(a, guideline, respond)
@show score
if score >= 8 # good enough answer
@show a.memory[:shortterm]
a.memory[:shortterm] = ""
a.thoughtlog = ""
respond = msgToUser
# a.memory[:shortterm] = ""
# a.thoughtlog = ""
break
else # self evaluate and reflect then try again
report = analyze(a, a.memory[:shortterm])
@@ -831,7 +832,7 @@ julia> score = grading(agent, guideline, shorttermMemory)
2
```
"""
function grading(a, guideline::T, shorttermMemory::T) where {T<:AbstractString}
function grading(a, guideline::T, text::T) where {T<:AbstractString}
prompt =
"""
<|im_start|>system
@@ -839,21 +840,21 @@ function grading(a, guideline::T, shorttermMemory::T) where {T<:AbstractString}
chatbox: 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.
Evaluation guideline:
$guideline
Your work:
$shorttermMemory
Your respond: $text
You job are:
1. Evaluate your work using the evaluation guideline.
2. Give yourself a score out of 10 for your work.
Use the following format to answer: Score {}/10.
1. Evaluate your respond using the evaluation guideline and an example respond.
2. Give yourself a score out of 10 for your respond.
Use the following format to answer:
{Evaluation} Score {}/10.
<|im_end|>
"""
println("prompt 11 ", prompt)
respond = sendReceivePrompt(a, prompt)
println("grading = ", respond)
println("grading respond 11 = $respond")
_score = split(respond[end-5:end], "/")[1]
_score = split(_score, " ")[end]
score = parse(Int, _score)
@@ -967,10 +968,59 @@ function selfReflext(a, report::T) where {T<:AbstractString}
end
"""
""" #WORKING
""" Formulate a respond from work for user's stimulus.
Args:
a, one of ChatAgent's agent.
Return:
A respond for user's stimulus.
# Example
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> shorttermMemory =
"
user: What's AMD latest product?
assistant: Plan 1: To provide the user with information about AMD's latest product, I will search for the most recent product release from AMD.
1. Search for \"AMD latest product\" using wikisearch tool.
2. Identify the most recent product release mentioned in the search results.
3. Provide the user with the name of the latest product.
Thought 1: The user wants to know about the latest AMD products, so I should use the wikisearch tool to find information on this topic.
Act 1: wikisearch
ActInput 1: \"AMD latest product\"
Obs 1: No info available."
julia> report = formulateRespond(agent, shorttermMemory)
```
"""
function formulateRespond(a, shorttermMemory::T) where {T<:AbstractString}
prompt =
"""
<|im_start|>system
You have access to the following tools:
chatbox: 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.
Symbol:
Stimulus: the input user gives to you and you must respond
Plan: a plan
Thought: your thought
Act: the action you took
ActInput: the input to the action
Obs: the result of the action
Your work:
$shorttermMemory
From your work, formulate a respond for user's stimulus.
<|im_end|>
"""
respond = sendReceivePrompt(a, prompt)
return respond
end