update
This commit is contained in:
74
src/utils.jl
74
src/utils.jl
@@ -2,7 +2,7 @@ module utils
|
||||
|
||||
export makeSummary, sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalStepInPlan,
|
||||
detectCharacters, findDetectedCharacter, extract_number, toolNameBeingCalled,
|
||||
chooseThinkingMode, conversationSummary, checkReasonableness, addStepNumber,
|
||||
chooseThinkingMode, conversationSummary, checkReasonableness, replaceHeaders,
|
||||
addShortMem!, splittext
|
||||
|
||||
using UUIDs, Dates, DataStructures
|
||||
@@ -344,6 +344,7 @@ function chooseThinkingMode(a::agentReflex, usermsg::String)
|
||||
Choose one of the following choices:
|
||||
If you don't need to use tools or actions to respond to the stimulus say, "{no}".
|
||||
If you need tools or actions to respond to the stimulus say, "{yes}".
|
||||
If the user want to get wine say, "{yes}".
|
||||
<|im_end|>
|
||||
|
||||
<|im_start|>user
|
||||
@@ -485,21 +486,6 @@ function checkReasonableness(userMsg::String, context::String, tools)
|
||||
|
||||
end
|
||||
|
||||
"""
|
||||
Add step number to header in a text
|
||||
"""
|
||||
function addStepNumber(text::T, headers, step::Int) where {T<:AbstractString}
|
||||
newtext = text
|
||||
for i in headers
|
||||
if occursin(i[:char], newtext)
|
||||
new = replace(i[:char], ":"=> " $step:")
|
||||
newtext = replace(newtext, i[:char]=>new )
|
||||
end
|
||||
end
|
||||
return newtext
|
||||
end
|
||||
|
||||
|
||||
|
||||
""" Add chunked text to a short term memory of a chat agent
|
||||
|
||||
@@ -559,20 +545,62 @@ end
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Add step number to header in a text
|
||||
"""
|
||||
function addStepNumber(text::T, headers, step::Int) where {T<:AbstractString}
|
||||
newtext = text
|
||||
for i in headers
|
||||
if occursin(i[:char], newtext)
|
||||
new = replace(i[:char], ":"=> " $step:")
|
||||
newtext = replace(newtext, i[:char]=>new )
|
||||
end
|
||||
end
|
||||
return newtext
|
||||
end
|
||||
function addStepNumber(text::T, headers, step::Int, substep::Int) where {T<:AbstractString}
|
||||
newtext = text
|
||||
for i in headers
|
||||
if occursin(i[:char], newtext)
|
||||
new = replace(i[:char], ":"=> " $step-$substep:")
|
||||
newtext = replace(newtext, i[:char]=>new )
|
||||
end
|
||||
end
|
||||
return newtext
|
||||
end
|
||||
|
||||
|
||||
""" Add step number to header in a text
|
||||
|
||||
Args:
|
||||
text = a text you want to split
|
||||
headers = a list of keywords you want to add step and substep to
|
||||
|
||||
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"]
|
||||
|
||||
```
|
||||
"""
|
||||
function replaceHeaders(text::T, headers, attempt::Int, step::Int, substep::Int) where {T<:AbstractString}
|
||||
newtext = text
|
||||
for i in headers
|
||||
header = i[:char][1:end-1]
|
||||
if occursin(header, newtext)
|
||||
startind = findfirst(i[:char], newtext)[1]
|
||||
stopind = findnext(":", newtext, startind+1)[end]
|
||||
word = newtext[startind: stopind]
|
||||
newtext = replace(newtext, word=> "$header $attempt-$step-$substep:")
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return newtext
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user