This commit is contained in:
2023-12-04 10:49:58 +00:00
parent 45bd332b6f
commit 479d17589e
3 changed files with 54 additions and 35 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
addShortMem!, splittext, shortMemoryToString
using UUIDs, Dates, DataStructures
using CommUtils, GeneralUtils
@@ -619,16 +619,43 @@ function replaceHeaders(text::T, headers, step::Int) where {T<:AbstractString}
end
""" Convert short term memory into 1 continous string.
Args:
shortMemory = a short memory of a ChatAgent's agent
skiplist = a list of keys in memory you want to skip
Return:
a short term memory in 1 countinuous string
# Example
```jldoctest
julia> shortMemory = OrderedDict(
"Thought" => "I like it.",
"Act" => "chatbox",
"ActInput" => "I get this one.",
)
julia> headers = ["user:"]
julia> shortMemoryToString(shortMemory, headers)
```
"""
function shortMemoryToString(shortMemory::OrderedDict,
skiplist::Union{Array{String}, Array{Symbol}})
s = ""
for (k, v) in shortMemory
if k skiplist
s1 = "$k $v"
s *= s1
# ensure a newline seperate each sentences
if s[end] != "\n"
s *= "\n"
end
end
end
return s
end