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:"]

View File

@@ -89,7 +89,35 @@ end
"""
Arguments:
Return:
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)
```
"""
function winestockDB(a::agentReflex, phrase::T) where {T<:AbstractString}
return result
end

View File

@@ -12,7 +12,7 @@ abstract type agent end
""" A LLM agent with self reflect capabilities.
# Example
Example:
```jldoctest
julia> using ChatAgent
julia> mqttClientSpec = (

View File

@@ -326,12 +326,12 @@ end
""" Determine from a user message whether an assistant need to use tools.
Arguments:
a, one of ChatAgent's agent.
Arguments:
a, one of ChatAgent's agent.
Return:
1. true/false # is LLM going to use tools
2. objective # what LLM going to do
Return:
1. true/false # is LLM going to use tools
2. objective # what LLM going to do
"""
function isUsePlans(a::agentReflex)
toollines = ""
@@ -443,22 +443,22 @@ end
""" Convert a vector of dict into 1-continous string.
Arguments:
vecofdict, a vector of dict
Arguments:
vecofdict, a vector of dict
Return:
1-continous string
Return:
1-continous string
# Example
```jldoctest
julia> using ChatAgent
julia> agent = ChatAgent.agentReflex("Jene")
julia> agent.messages = [Dict(:role=> "user", :content=> "Hi there."),
Dict(:role=> "assistant", :content=> "Hello! How can I assist you today?"),]
Example:
```jldoctest
julia> using ChatAgent
julia> agent = ChatAgent.agentReflex("Jene")
julia> agent.messages = [Dict(:role=> "user", :content=> "Hi there."),
Dict(:role=> "assistant", :content=> "Hello! How can I assist you today?"),]
julia> messagesToString(agent.messages)
"<|im_start|>user: Hi there.\n<|im_end|><|im_start|>assistant: Hello! How can I assist you today?\n<|im_end|>"
```
julia> messagesToString(agent.messages)
"<|im_start|>user: Hi there.\n<|im_end|><|im_start|>assistant: Hello! How can I assist you today?\n<|im_end|>"
```
"""
function messagesToString(messages::AbstractVector{T}; addressAIas="assistant") where {T<:AbstractDict}
conversation = ""
@@ -523,22 +523,22 @@ end
""" Convert a vector of dict into 1-continous string.
Arguments:
vecofdict, a vector of dict
Arguments:
vecofdict, a vector of dict
Return:
1-continous string
Return:
1-continous string
# Example
```jldoctest
julia> using ChatAgent
julia> agent = ChatAgent.agentReflex("Jene")
julia> agent.messages = [Dict(:role=> "user", :content=> "Hi there."),
Dict(:role=> "assistant", :content=> "Hello! How can I assist you today?"),]
Example:
```jldoctest
julia> using ChatAgent
julia> agent = ChatAgent.agentReflex("Jene")
julia> agent.messages = [Dict(:role=> "user", :content=> "Hi there."),
Dict(:role=> "assistant", :content=> "Hello! How can I assist you today?"),]
julia> messagesToString(agent.messages)
"user: Hi there.\nassistant: Hello! How can I assist you today?\n"
```
julia> messagesToString(agent.messages)
"user: Hi there.\nassistant: Hello! How can I assist you today?\n"
```
"""
function messagesToString_nomark(messages::AbstractVector{T}; addressAIas="assistant") where {T<:AbstractDict}
conversation = ""
@@ -599,20 +599,20 @@ end
""" Remove trailing characters from text.
Arguments:
text, text you want to remove trailing characters
charTobeRemoved, a list of characters to be removed
Arguments:
text, text you want to remove trailing characters
charTobeRemoved, a list of characters to be removed
Return:
text with specified trailing characters removed
Return:
text with specified trailing characters removed
# Example
```jldoctest
julia> text = "Hello! How can I assist you today?\n\n "
julia> removelist = ['\n', ' ',]
julia> removeTrailingCharacters(text, charTobeRemoved=removelist)
"Hello! How can I assist you today?"
```
Example:
```jldoctest
julia> text = "Hello! How can I assist you today?\n\n "
julia> removelist = ['\n', ' ',]
julia> removeTrailingCharacters(text, charTobeRemoved=removelist)
"Hello! How can I assist you today?"
```
"""
function removeTrailingCharacters(text; charTobeRemoved::AbstractVector{T}=['\n', ' ',]) where {T<:Char}
nouse = 0
@@ -674,25 +674,25 @@ end
""" Add chunked text to a short term memory of a chat agent
Arguments:
shortMem = short memory of a chat agent,
chunkedtext = a dict contains text
Arguments:
shortMem = short memory of a chat agent,
chunkedtext = a dict contains text
Return: no return
Return: no return
# Example
```jldoctest
julia> chunkedtext = OrderedDict{String, String}(
"Thought 1:" => " I should always think about...",
"Act 1:" => " wikisearch",
"Actinput 1:" => " latest AMD GPU",)
julia> shortMem = OrderedDict{String, Any}()
julia> addShortMem!(shortMem, chunkedtext)
OrderedDict{String, Any} with 3 entries:
"Thought 1:" => " I should always think about..."
"Act 1:" => " wikisearch"
"Actinput 1:" => " latest AMD GPU"
```
Example:
```jldoctest
julia> chunkedtext = OrderedDict{String, String}(
"Thought 1:" => " I should always think about...",
"Act 1:" => " wikisearch",
"Actinput 1:" => " latest AMD GPU",)
julia> shortMem = OrderedDict{String, Any}()
julia> addShortMem!(shortMem, chunkedtext)
OrderedDict{String, Any} with 3 entries:
"Thought 1:" => " I should always think about..."
"Act 1:" => " wikisearch"
"Actinput 1:" => " latest AMD GPU"
```
"""
function addShortMem!(shortMem::OrderedDict{String, Any}, chunkedtext::T) where {T<:AbstractDict}
for (k, v) in chunkedtext
@@ -706,19 +706,19 @@ end
""" Split text using all keywords in a list. Start spliting from rightmost of the text.
Arguments:
text = a text you want to split
list = a list of keywords you want to split
Arguments:
text = a text you want to split
list = a list of keywords you want to split
Return:
a leftmost text after split
Return:
a leftmost text after split
# Example
```jldoctest
julia> text = "Consider the type of food, occasion and temperature at the serving location."
julia> list = ["at", "and"]
"Consider the type of food, occasion "
```
Example:
```jldoctest
julia> text = "Consider the type of food, occasion and temperature at the serving location."
julia> list = ["at", "and"]
"Consider the type of food, occasion "
```
"""
function splittext(text, list)
newtext = text
@@ -757,20 +757,20 @@ end
""" Add step number to header in a text
Arguments:
text = a text you want to split
headers = a list of keywords you want to add step and substep to
step = a number you want to add
Arguments:
text = a text you want to split
headers = a list of keywords you want to add step and substep to
step = a number you want to add
Return:
a leftmost text after split
Return:
a leftmost text after split
# Example
```jldoctest
julia> text = "Consider the type of food, occasion and temperature at the serving location."
julia> headers = ["Thought", "Act"]
Example:
```jldoctest
julia> text = "Consider the type of food, occasion and temperature at the serving location."
julia> headers = ["Thought", "Act"]
```
```
"""
function replaceHeaders(text::T, headers, step::Int) where {T<:AbstractString}
newtext = text
@@ -794,39 +794,39 @@ end
""" Remove headers of specific step from memory.
Arguments:
shortMemory = a short term memory of a ChatAgent's agent
skipHeaders = a list of keys in memory you want to skip
step = a step number you want to remove
Arguments:
shortMemory = a short term memory of a ChatAgent's agent
skipHeaders = a list of keys in memory you want to skip
step = a step number you want to remove
Return:
a short term memory
Return:
a short term memory
# Example
```jldoctest
julia> shortMemory = OrderedDict(
"user:" => "May I try this one?",
"Plan 1:" => "testing a small portion of icecream",
"Thought 1:" => "I like it.",
"Act 1:" => "chatbox",
"Actinput 1:" => "I get this one.",
"Plan 2:" => "I'm meeting my wife this afternoon",
"Thought 2:" => "I also want it for my wife",
"Act 2:" => "chatbox",
"Actinput 2:" => "I would like to get 2 more",
)
julia> skipHeaders = ["Plan"]
julia> step = 2
julia> removeHeaders(shortMemory, step, skipHeaders)
OrderedDict(
"user:" => "May I try this one?",
"Plan 1:" => "testing a small portion of icecream",
"Thought 1:" => "I like it.",
"Act 1:" => "chatbox",
"Actinput 1:" => "I get this one.",
"Plan 2:" => "I'm meeting my wife this afternoon",
)
```
Example:
```jldoctest
julia> shortMemory = OrderedDict(
"user:" => "May I try this one?",
"Plan 1:" => "testing a small portion of icecream",
"Thought 1:" => "I like it.",
"Act 1:" => "chatbox",
"Actinput 1:" => "I get this one.",
"Plan 2:" => "I'm meeting my wife this afternoon",
"Thought 2:" => "I also want it for my wife",
"Act 2:" => "chatbox",
"Actinput 2:" => "I would like to get 2 more",
)
julia> skipHeaders = ["Plan"]
julia> step = 2
julia> removeHeaders(shortMemory, step, skipHeaders)
OrderedDict(
"user:" => "May I try this one?",
"Plan 1:" => "testing a small portion of icecream",
"Thought 1:" => "I like it.",
"Act 1:" => "chatbox",
"Actinput 1:" => "I get this one.",
"Plan 2:" => "I'm meeting my wife this afternoon",
)
```
"""
function removeHeaders(shortMemory::OrderedDict, step::Int,
skipHeaders::Union{Array{String}, Array{Symbol}, Nothing}=nothing)
@@ -859,32 +859,32 @@ end
""" Keep only specified keys in a dictionary. All non-specified keys will be removed.
Arguments:
dict = a dictionary
keys = keys you want to keep in a dict
Arguments:
dict = a dictionary
keys = keys you want to keep in a dict
Return:
a dict with all non-specified keys removed
Return:
a dict with all non-specified keys removed
# Example
```jldoctest
julia> dict = OrderedDict(
"user:" => "May I try this one?",
"Plan 1:" => "testing a small portion of icecream",
"Thought 1:" => "I like it.",
"Act 1:" => "chatbox",
"Actinput 1:" => "I get this one.",
"Plan 2:" => "I'm meeting my wife this afternoon",
"Thought 2:" => "I also want it for my wife",
"Act 2:" => "chatbox",
"Actinput 2:" => "I would like to get 2 more",
)
julia> keys = ["user:"]
julia> keepOnlyKeys(dict, keys)
OrderedDict(
"user:" => "May I try this one?",
)
```
Example:
```jldoctest
julia> dict = OrderedDict(
"user:" => "May I try this one?",
"Plan 1:" => "testing a small portion of icecream",
"Thought 1:" => "I like it.",
"Act 1:" => "chatbox",
"Actinput 1:" => "I get this one.",
"Plan 2:" => "I'm meeting my wife this afternoon",
"Thought 2:" => "I also want it for my wife",
"Act 2:" => "chatbox",
"Actinput 2:" => "I would like to get 2 more",
)
julia> keys = ["user:"]
julia> keepOnlyKeys(dict, keys)
OrderedDict(
"user:" => "May I try this one?",
)
```
"""
function keepOnlyKeys(dict::T1, keys::T2) where {T1<:AbstractDict, T2<:AbstractVector}
newdict = similar(dict)
@@ -899,20 +899,20 @@ end
""" Convert experience dict into 1 string for LLM to use.
Arguments:
dict = a dictionary contain past experience
Arguments:
dict = a dictionary contain past experience
Return:
An experience in 1 string without context keys.
Return:
An experience in 1 string without context keys.
# Example
```jldoctest
julia> dict = OrderedDict{String, Any}(
" This lesson can be applied to various situations => " Gathering accurate and relevant information about the user's preferences, budget, and event details is crucial for providing personalized recommendations.\n"
)
julia> experience(dict)
Example:
```jldoctest
julia> dict = OrderedDict{String, Any}(
" This lesson can be applied to various situations => " Gathering accurate and relevant information about the user's preferences, budget, and event details is crucial for providing personalized recommendations.\n"
)
julia> experience(dict)
```
```
"""
function experience(dict::T) where {T<:AbstractDict}
s = ""
@@ -925,18 +925,17 @@ end
""" Get the latest step number of short term memory
Arguments:
dict = a dictionary contain past experience
Arguments:
dict = a dictionary contain past experience
Return:
latest step number
Return:
latest step number
# Example
```jldoctest
julia> dict = OrderedDict(
"Plan 1:" => "1. Ask about the type of food that will be served at the wedding party.")
julia>shortMemLatestTask(dict)
1
Example:
```jldoctest
julia> dict = OrderedDict(
"Plan 1:" => "1. Ask about the type of food that will be served at the wedding party.")
julia>shortMemLatestTask(dict)
"""
function shortMemLatestTask(dict::T) where {T<:AbstractDict}
_latest_step = keys(dict)