update
This commit is contained in:
54
src/utils.jl
54
src/utils.jl
@@ -3,7 +3,7 @@ module utils
|
||||
export makeSummary, sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalStepInPlan,
|
||||
detectCharacters, findDetectedCharacter, extract_number, toolNameBeingCalled,
|
||||
chooseThinkingMode, conversationSummary, checkReasonableness, replaceHeaders,
|
||||
addShortMem!, splittext, shortMemoryToString, removeHeaders
|
||||
addShortMem!, splittext, shortMemoryToString, removeHeaders, keepOnlyKeys
|
||||
|
||||
using UUIDs, Dates, DataStructures
|
||||
using CommUtils, GeneralUtils
|
||||
@@ -181,7 +181,7 @@ end
|
||||
julia> chunkedtext = ChatAgent.chunktext(text, headers)
|
||||
OrderedDict{String, String} with 3 entries:
|
||||
"Act 1:" => " wikisearch"
|
||||
"ActInput 1:" => " latest AMD GPU"
|
||||
"Actinput 1:" => " latest AMD GPU"
|
||||
"Thought 1:" => " I should always think about..."
|
||||
```
|
||||
"""
|
||||
@@ -515,13 +515,13 @@ Return: no return
|
||||
julia> chunkedtext = OrderedDict{String, String}(
|
||||
"Thought 1:" => " I should always think about...",
|
||||
"Act 1:" => " wikisearch",
|
||||
"ActInput 1:" => " latest AMD GPU",)
|
||||
"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"
|
||||
"Actinput 1:" => " latest AMD GPU"
|
||||
```
|
||||
"""
|
||||
function addShortMem!(shortMem::OrderedDict{String, Any}, chunkedtext::T) where {T<:AbstractDict}
|
||||
@@ -634,12 +634,12 @@ julia> shortMemory = OrderedDict(
|
||||
"user:" => "Umm",
|
||||
"Thought 1:" => "I like it.",
|
||||
"Act 1:" => "chatbox",
|
||||
"ActInput 1:" => "I get this one.",
|
||||
"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"
|
||||
"Thought 1: I like it.\nAct 1: chatbox\nActinput 1: I get this one.\n"
|
||||
```
|
||||
"""
|
||||
function shortMemoryToString(shortMemory::OrderedDict,
|
||||
@@ -677,11 +677,11 @@ julia> shortMemory = OrderedDict(
|
||||
"Plan 1:" => "testing a small portion of icecream",
|
||||
"Thought 1:" => "I like it.",
|
||||
"Act 1:" => "chatbox",
|
||||
"ActInput 1:" => "I get this one.",
|
||||
"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",
|
||||
"Actinput 2:" => "I would like to get 2 more",
|
||||
)
|
||||
julia> skipHeaders = ["Plan"]
|
||||
julia> step = 2
|
||||
@@ -691,7 +691,7 @@ OrderedDict(
|
||||
"Plan 1:" => "testing a small portion of icecream",
|
||||
"Thought 1:" => "I like it.",
|
||||
"Act 1:" => "chatbox",
|
||||
"ActInput 1:" => "I get this one.",
|
||||
"Actinput 1:" => "I get this one.",
|
||||
"Plan 2:" => "I'm meeting my wife this afternoon",
|
||||
)
|
||||
```
|
||||
@@ -725,10 +725,44 @@ end
|
||||
|
||||
|
||||
|
||||
""" Keep only specified keys in a dictionary. All non-specified keys will be removed.
|
||||
|
||||
Args:
|
||||
dict = a dictionary
|
||||
keys = keys you want to keep in a dict
|
||||
|
||||
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?",
|
||||
)
|
||||
```
|
||||
"""
|
||||
function keepOnlyKeys(dict::T1, keys::T2) where {T1<:AbstractDict, T2<:AbstractVector}
|
||||
newdict = similar(dict)
|
||||
for (k, v) in dict
|
||||
if k ∈ keys
|
||||
newdict[k] = v
|
||||
end
|
||||
end
|
||||
return newdict
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user