This commit is contained in:
2023-11-29 04:14:16 +00:00
parent 6ae189e701
commit 6a8e24f20f
4 changed files with 175 additions and 71 deletions

View File

@@ -2,9 +2,10 @@ module utils
export makeSummary, sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalStepInPlan,
detectCharacters, findDetectedCharacter, extract_number, toolNameBeingCalled,
chooseThinkingMode, conversationSummary, checkReasonableness, addStepNumber
chooseThinkingMode, conversationSummary, checkReasonableness, addStepNumber,
addShortMem!
using UUIDs, Dates
using UUIDs, Dates, DataStructures
using CommUtils, GeneralUtils
using ..type
@@ -181,13 +182,14 @@ end
(char = "user", start = 56, stop = 59)
(char = "Then", start = 102, stop = 105)
julia> chunkedtext = ChatAgent.chunktext(text, headers)
2-element Vector{Any}:
(header = "First", body = ", we need to find out what kind of wine the ")
(header = "user", body = " wants.")
OrderedDict{String, String} with 3 entries:
"Act 1:" => " wikisearch"
"ActInput 1:" => " latest AMD GPU"
"Thought 1:" => " I should always think about..."
```
"""
function chunktext(text::T, headers) where {T<:AbstractString}
result = Dict()
function chunktext(text::T1, headers::T2) where {T1<:AbstractString, T2<:AbstractVector}
result = OrderedDict{String, Any}()
for (i, v) in enumerate(headers)
if i < length(headers)
@@ -230,7 +232,9 @@ function extractStepFromPlan(a::agent, plan::T, step::Int) where {T<:AbstractStr
return respond
end
function checkTotalStepInPlan(a::agent, plan::T) where {T<:AbstractString}
function checkTotalStepInPlan(a::agent)
p = a.memory[:shortterm]["Plan 1:"]
plan = "Plan 1: $p"
prompt =
"""
<|im_start|>system
@@ -430,12 +434,12 @@ function conversationSummary(a::T) where {T<:agent}
prompt = replace(prompt, "{conversation}" => conversation)
result = sendReceivePrompt(a, prompt)
summary = result === nothing ? "nothing" : result
summary = replace(summary, "<|im_end|>" => "")
summary = split(summary, "<|im_end|>")[1]
if summary[1:1] == "\n"
summary = summary[2:end]
end
end
println("conversation summary: $summary")
@show summary
return summary
end
@@ -500,6 +504,34 @@ end
""" Add chunked text to a short term memory of a chat agent
Args:
shortMem = short memory of a chat agent,
chunkedtext = a dict contains text
Return: no return
# Example
```jldoctest
julia> chunkedtext = OrderedDict{String, String}(
"Thought 1:" => " I should always think about...",
"Act 1:" => " wikisearch",
"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"
```
"""
function addShortMem!(shortMem::OrderedDict{String, Any}, chunkedtext::T) where {T<:AbstractDict}
for (k, v) in chunkedtext
shortMem[k] = v
end
return shortMem
end