This commit is contained in:
2024-01-11 03:01:29 +00:00
parent 14db6ec6f1
commit e495a801f8
4 changed files with 332 additions and 306 deletions

View File

@@ -755,22 +755,22 @@ end
""" Write evaluation guideline.
Arguments:
a, one of ChatAgent's agent.
usermsg, stimulus e.g. question, task and etc.
Arguments:
a, one of ChatAgent's agent.
usermsg, stimulus e.g. question, task and etc.
Return:
An evaluation guideline used to guage AI's work.
Return:
An evaluation guideline used to guage AI's work.
# Example
Example:
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> usermsg = "What's AMD latest product?"
"
julia> evaluationGuideLine = writeEvaluationGuideline(agent, usermsg)
```
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> usermsg = "What's AMD latest product?"
"
julia> evaluationGuideLine = writeEvaluationGuideline(agent, usermsg)
```
"""
function writeEvaluationGuideline(a::agentReflex)
prompt =
@@ -798,32 +798,31 @@ end
""" Determine a score out of 10 according to evaluation guideline.
Arguments:
a, one of ChatAgent's agent.
guidelines, an evaluation guideline.
shorttermMemory, a short term memory that logs what happened.
Arguments:
a, one of ChatAgent's agent.
guidelines, an evaluation guideline.
shorttermMemory, a short term memory that logs what happened.
Return:
A score out of 10 based on guideline.
Return:
A score out of 10 based on guideline.
# Example
Example:
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> shorttermMemory = OrderedDict{String, Any}(
"user" => "What's the latest AMD GPU?",
"Plan 1:" => " To answer this question, I will need to search for the latest AMD GPU using the wikisearch tool.\n",
"Act 1:" => " wikisearch\n",
"Actinput 1:" => " amd gpu latest\n",
"Obs 1:" => "No info available for your search query.",
"Act 2:" => " wikisearch\n",
"Actinput 2:" => " amd graphics card latest\n",
"Obs 2:" => "No info available for your search query.")
julia> guideline = "\nEvaluation Guideline:\n1. Check if the user's question has been understood correctly.\n2. Evaluate the tasks taken to provide the information requested by the user.\n3. Assess whether the correct tools were used for the task.\n4. Determine if the user's request was successfully fulfilled.\n5. Identify any potential improvements or alternative approaches that could be used in the future.\n\nThe response should include:\n1. A clear understanding of the user's question.\n2. The tasks taken to provide the information requested by the user.\n3. An evaluation of whether the correct tools were used for the task.\n4. A confirmation or explanation if the user's request was successfully fulfilled.\n5. Any potential improvements or alternative approaches that could be used in the future."
julia> score = grading(agent, guideline, shorttermMemory)
2
```
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> shorttermMemory = OrderedDict{String, Any}(
"user" => "What's the latest AMD GPU?",
"Plan 1:" => " To answer this question, I will need to search for the latest AMD GPU using the wikisearch tool.\n",
"Act 1:" => " wikisearch\n",
"Actinput 1:" => " amd gpu latest\n",
"Obs 1:" => "No info available for your search query.",
"Act 2:" => " wikisearch\n",
"Actinput 2:" => " amd graphics card latest\n",
"Obs 2:" => "No info available for your search query.")
julia> guideline = "\nEvaluation Guideline:\n1. Check if the user's question has been understood correctly.\n2. Evaluate the tasks taken to provide the information requested by the user.\n3. Assess whether the correct tools were used for the task.\n4. Determine if the user's request was successfully fulfilled.\n5. Identify any potential improvements or alternative approaches that could be used in the future.\n\nThe response should include:\n1. A clear understanding of the user's question.\n2. The tasks taken to provide the information requested by the user.\n3. An evaluation of whether the correct tools were used for the task.\n4. A confirmation or explanation if the user's request was successfully fulfilled.\n5. Any potential improvements or alternative approaches that could be used in the future."
julia> score = grading(agent, guideline, shorttermMemory)
```
"""
function grading(a, guideline::T, text::T) where {T<:AbstractString}
prompt =
@@ -867,28 +866,28 @@ end
""" Analize work.
Arguments:
a, one of ChatAgent's agent.
Arguments:
a, one of ChatAgent's agent.
Return:
A report of analized work.
Return:
A report of analized work.
# Example
Example:
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> shorttermMemory = OrderedDict{String, Any}(
"user:" => "What's the latest AMD GPU?",
"Plan 1:" => " To answer this question, I will need to search for the latest AMD GPU using the wikisearch tool.\n",
"Act 1:" => " wikisearch\n",
"Actinput 1:" => " amd gpu latest\n",
"Obs 1:" => "No info available for your search query.",
"Act 2:" => " wikisearch\n",
"Actinput 2:" => " amd graphics card latest\n",
"Obs 2:" => "No info available for your search query.")
julia> report = analyze(agent, shorttermMemory)
```
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> shorttermMemory = OrderedDict{String, Any}(
"user:" => "What's the latest AMD GPU?",
"Plan 1:" => " To answer this question, I will need to search for the latest AMD GPU using the wikisearch tool.\n",
"Act 1:" => " wikisearch\n",
"Actinput 1:" => " amd gpu latest\n",
"Obs 1:" => "No info available for your search query.",
"Act 2:" => " wikisearch\n",
"Actinput 2:" => " amd graphics card latest\n",
"Obs 2:" => "No info available for your search query.")
julia> report = analyze(agent, shorttermMemory)
```
"""
function analyze(a)
shorttermMemory = dictToString(a.memory[:shortterm])
@@ -920,35 +919,35 @@ end
""" Write a lesson drawn from evaluation.
Arguments:
a, one of ChatAgent's agent.
report, a report resulted from analyzing shorttermMemory
Arguments:
a, one of ChatAgent's agent.
report, a report resulted from analyzing shorttermMemory
Return:
A lesson.
Return:
A lesson.
# Example
Example:
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> report =
"What happened: I tried to search for AMD's latest product using the wikisearch tool,
but no information was available in the search results.
Cause and effect relationships:
1. Searching \"AMD latest product\" -> No info available.
2. Searching \"most recent product release\" -> No info available.
3. Searching \"latest product\" -> No info available.
Analysis of each relationship:
1. The search for \"AMD latest product\" did not provide any information because the wikisearch tool could not find relevant results for that query.
2. The search for \"most recent product release\" also did not yield any results, indicating that there might be no recent product releases available or that the information is not accessible through the wikisearch tool.
3. The search for \"latest product\" similarly resulted in no information being found, suggesting that either the latest product is not listed on the encyclopedia or it is not easily identifiable using the wikisearch tool.
Improvements: To improve the response, I could try searching for AMD's products on a different
source or search engine to find the most recent product release. Additionally, I could ask
the user for more context or clarify their question to better understand what they are
looking for."
julia> lesson = selfReflext(agent, report)
```
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> report =
"What happened: I tried to search for AMD's latest product using the wikisearch tool,
but no information was available in the search results.
Cause and effect relationships:
1. Searching \"AMD latest product\" -> No info available.
2. Searching \"most recent product release\" -> No info available.
3. Searching \"latest product\" -> No info available.
Analysis of each relationship:
1. The search for \"AMD latest product\" did not provide any information because the wikisearch tool could not find relevant results for that query.
2. The search for \"most recent product release\" also did not yield any results, indicating that there might be no recent product releases available or that the information is not accessible through the wikisearch tool.
3. The search for \"latest product\" similarly resulted in no information being found, suggesting that either the latest product is not listed on the encyclopedia or it is not easily identifiable using the wikisearch tool.
Improvements: To improve the response, I could try searching for AMD's products on a different
source or search engine to find the most recent product release. Additionally, I could ask
the user for more context or clarify their question to better understand what they are
looking for."
julia> lesson = selfReflext(agent, report)
```
"""
function selfReflext(a, analysis::T) where {T<:AbstractString}
prompt =
@@ -974,28 +973,28 @@ end
""" Formulate a response from work for user's stimulus.
Arguments:
a, one of ChatAgent's agent.
Arguments:
a, one of ChatAgent's agent.
Return:
A response for user's stimulus.
Return:
A response for user's stimulus.
# Example
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> shorttermMemory = OrderedDict{String, Any}(
"user:" => "What's the latest AMD GPU?",
"Plan 1:" => " To answer this question, I will need to search for the latest AMD GPU using the wikisearch tool.\n",
"Act 1:" => " wikisearch\n",
"Actinput 1:" => " amd gpu latest\n",
"Obs 1:" => "No info available for your search query.",
"Act 2:" => " wikisearch\n",
"Actinput 2:" => " amd graphics card latest\n",
"Obs 2:" => "No info available for your search query.")
Example:
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> shorttermMemory = OrderedDict{String, Any}(
"user:" => "What's the latest AMD GPU?",
"Plan 1:" => " To answer this question, I will need to search for the latest AMD GPU using the wikisearch tool.\n",
"Act 1:" => " wikisearch\n",
"Actinput 1:" => " amd gpu latest\n",
"Obs 1:" => "No info available for your search query.",
"Act 2:" => " wikisearch\n",
"Actinput 2:" => " amd graphics card latest\n",
"Obs 2:" => "No info available for your search query.")
julia> report = formulateUserresponse(agent, shorttermMemory)
```
julia> report = formulateUserresponse(agent, shorttermMemory)
```
"""
function formulateUserresponse(a)
conversation = messagesToString_nomark(a.messages, addressAIas="I")
@@ -1029,21 +1028,21 @@ end
""" Extract important info from text into key-value pair text.
Arguments:
a, one of ChatAgent's agent.
text, a text you want to extract info
Arguments:
a, one of ChatAgent's agent.
text, a text you want to extract info
Return:
key-value pair text.
Return:
key-value pair text.
# Example
```jldoctest
julia> using ChatAgent
julia> agent = ChatAgent.agentReflex("Jene")
julia> text = "We are holding a wedding party at the beach."
julia> extract(agent, text)
"location=beach, event=wedding party"
```
Example:
```jldoctest
julia> using ChatAgent
julia> agent = ChatAgent.agentReflex("Jene")
julia> text = "We are holding a wedding party at the beach."
julia> extract(agent, text)
"location=beach, event=wedding party"
```
"""
function extractinfo(a, text::T) where {T<:AbstractString}
# determine whether there are any important info in an input text
@@ -1081,22 +1080,22 @@ end
""" Update important info from key-value pair text into another key-value pair text.
Arguments:
a, one of ChatAgent's agent
text, a key-value pair text
Arguments:
a, one of ChatAgent's agent
text, a key-value pair text
Return:
updated key-value pair text
Return:
updated key-value pair text
# Example
```jldoctest
julia> using ChatAgent
julia> agent = ChatAgent.agentReflex("Jene")
julia> currentinfo = "location=beach, event=wedding party"
julia> newinfo = "wine_type=full body, dry and medium tannin\nprice_range=50 dollars"
julia> updateEnvState(agent, currentinfo, newinfo)
" location=beach, event=wedding party, wine_type=full body, dry and medium tannin, price_range=50 dollars"
```
Example:
```jldoctest
julia> using ChatAgent
julia> agent = ChatAgent.agentReflex("Jene")
julia> currentinfo = "location=beach, event=wedding party"
julia> newinfo = "wine_type=full body, dry and medium tannin\nprice_range=50 dollars"
julia> updateEnvState(agent, currentinfo, newinfo)
" location=beach, event=wedding party, wine_type=full body, dry and medium tannin, price_range=50 dollars"
```
"""
function updateEnvState(a, newinfo)
prompt =
@@ -1121,29 +1120,29 @@ end
""" Determine whether LLM should go to next task.
Arguments:
a, one of ChatAgent's agent.
Arguments:
a, one of ChatAgent's agent.
Return:
"Yes" or "no" decision to go next task.
Return:
"Yes" or "no" decision to go next task.
# Example
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> shorttermMemory = OrderedDict{String, Any}(
"user:" => "What's the latest AMD GPU?",
"Plan 1:" => " To answer this question, I will need to search for the latest AMD GPU using the wikisearch tool.\n",
"Act 1:" => " wikisearch\n",
"Actinput 1:" => " amd gpu latest\n",
"Obs 1:" => "No info available for your search query.",
"Act 2:" => " wikisearch\n",
"Actinput 2:" => " amd graphics card latest\n",
"Obs 2:" => "No info available for your search query.")
Example:
```jldoctest
julia> using ChatAgent, CommUtils
julia> agent = ChatAgent.agentReflex("Jene")
julia> shorttermMemory = OrderedDict{String, Any}(
"user:" => "What's the latest AMD GPU?",
"Plan 1:" => " To answer this question, I will need to search for the latest AMD GPU using the wikisearch tool.\n",
"Act 1:" => " wikisearch\n",
"Actinput 1:" => " amd gpu latest\n",
"Obs 1:" => "No info available for your search query.",
"Act 2:" => " wikisearch\n",
"Actinput 2:" => " amd graphics card latest\n",
"Obs 2:" => "No info available for your search query.")
julia> decision = checkTaskCompletion(agent)
"Yes"
```
julia> decision = checkTaskCompletion(agent)
"Yes"
```
"""
function checkTaskCompletion(a)
@show a.memory[:shortterm]["Plan 1:"]