update
This commit is contained in:
75
src/utils.jl
75
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, keepOnlyKeys
|
||||
addShortMem!, splittext, dictToString, removeHeaders, keepOnlyKeys, experience
|
||||
|
||||
using UUIDs, Dates, DataStructures
|
||||
using CommUtils, GeneralUtils
|
||||
@@ -431,7 +431,7 @@ function conversationSummary(a::T) where {T<:agent}
|
||||
conversation = ""
|
||||
summary = "nothing"
|
||||
if length(a.messages)!= 0
|
||||
for msg in a.messages
|
||||
for msg in a.messages[1:end-1]
|
||||
role = msg[:role]
|
||||
content = msg[:content]
|
||||
|
||||
@@ -638,7 +638,7 @@ julia> shortMemory = OrderedDict(
|
||||
)
|
||||
|
||||
julia> headers = ["user:"]
|
||||
julia> shortMemoryToString(shortMemory, headers)
|
||||
julia> dictToString(shortMemory, headers)
|
||||
"Thought 1: I like it.\nAct 1: chatbox\nActinput 1: I get this one.\n"
|
||||
```
|
||||
"""
|
||||
@@ -660,6 +660,24 @@ function shortMemoryToString(shortMemory::OrderedDict,
|
||||
end
|
||||
|
||||
|
||||
function dictToString(dict::T,
|
||||
skiplist::Union{Array{String}, Array{Symbol}}) where {T<:AbstractDict}
|
||||
s = ""
|
||||
for (k, v) in dict
|
||||
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
|
||||
|
||||
|
||||
""" Remove headers of specific step from memory.
|
||||
|
||||
Args:
|
||||
@@ -764,6 +782,57 @@ function keepOnlyKeys(dict::T1, keys::T2) where {T1<:AbstractDict, T2<:AbstractV
|
||||
return newdict
|
||||
end
|
||||
|
||||
|
||||
""" Convert experience dict into 1 string for LLM to use.
|
||||
|
||||
Args:
|
||||
dict = a dictionary contain past experience
|
||||
|
||||
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)
|
||||
|
||||
```
|
||||
"""
|
||||
function experience(dict::T) where {T<:AbstractDict}
|
||||
s = ""
|
||||
for (k, v) in dict
|
||||
s *= v
|
||||
end
|
||||
|
||||
return s
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user