This commit is contained in:
2023-12-05 09:12:23 +00:00
parent ec8cc6bbf9
commit 6ece544cc8
2 changed files with 69 additions and 54 deletions

View File

@@ -3,7 +3,7 @@ module utils
export makeSummary, sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalStepInPlan,
detectCharacters, findDetectedCharacter, extract_number, toolNameBeingCalled,
chooseThinkingMode, conversationSummary, checkReasonableness, replaceHeaders,
addShortMem!, splittext, shortMemoryToString
addShortMem!, splittext, shortMemoryToString, removeHeaders
using UUIDs, Dates, DataStructures
using CommUtils, GeneralUtils
@@ -622,7 +622,7 @@ end
""" Convert short term memory into 1 continous string.
Args:
shortMemory = a short memory of a ChatAgent's agent
shortMemory = a short term memory of a ChatAgent's agent
skiplist = a list of keys in memory you want to skip
Return:
@@ -631,13 +631,15 @@ Return:
# Example
```jldoctest
julia> shortMemory = OrderedDict(
"Thought" => "I like it.",
"Act" => "chatbox",
"ActInput" => "I get this one.",
"user:" => "Umm",
"Thought 1:" => "I like it.",
"Act 1:" => "chatbox",
"ActInput 1:" => "I get this one.",
)
julia> headers = ["user:"]
julia> shortMemoryToString(shortMemory, headers)
"Thought 1: I like it.\nAct 1: chatbox\nActInput 1: I get this one.\n"
```
"""
function shortMemoryToString(shortMemory::OrderedDict,
@@ -658,8 +660,67 @@ function shortMemoryToString(shortMemory::OrderedDict,
end
""" Remove headers of specific step from memory.
Args:
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
# 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",
)
```
""" #WORKING
function removeHeaders(shortMemory::OrderedDict, step::Int,
skipHeaders::Union{Array{String}, Array{Symbol}, Nothing}=nothing)
newdict = similar(shortMemory)
for (k, v) in shortMemory
if occursin("$step", k)
if skipHeaders !== nothing
for i in skipHeaders
if occursin(i, k)
newdict[k] = v
else
# skip, not copy
end
end
else
# no copy
end
else
newdict[k] = v
end
end
return newdict
end