update
This commit is contained in:
53
src/utils.jl
53
src/utils.jl
@@ -3,7 +3,8 @@ module utils
|
||||
export makeSummary, sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalStepInPlan,
|
||||
detectCharacters, findDetectedCharacter, extract_number, toolNameBeingCalled,
|
||||
isUseTools, conversationSummary, checkReasonableness, replaceHeaders,
|
||||
addShortMem!, splittext, dictToString, removeHeaders, keepOnlyKeys, experience
|
||||
addShortMem!, splittext, dictToString, removeHeaders, keepOnlyKeys, experience,
|
||||
messagesToString
|
||||
|
||||
using UUIDs, Dates, DataStructures
|
||||
using CommUtils, GeneralUtils
|
||||
@@ -501,7 +502,7 @@ function conversationSummary(a::T) where {T<:agent}
|
||||
|
||||
prompt = replace(prompt, "{conversation}" => conversation)
|
||||
result = sendReceivePrompt(a, prompt)
|
||||
summary = result === nothing ? "" : result
|
||||
summary = result === nothing ? "N/A" : result
|
||||
summary = split(summary, "<|im_end|>")[1]
|
||||
if summary[1:1] == "\n"
|
||||
summary = summary[2:end]
|
||||
@@ -511,7 +512,55 @@ function conversationSummary(a::T) where {T<:agent}
|
||||
return summary
|
||||
end
|
||||
|
||||
""" Convert a vector of dict into 1-continous string.
|
||||
|
||||
Arguments:
|
||||
vecofdict, a vector of dict
|
||||
|
||||
Return:
|
||||
1-continous string
|
||||
|
||||
# Example
|
||||
```jldoctest
|
||||
julia> using ChatAgent
|
||||
julia> agent = ChatAgent.agentReflex("Jene")
|
||||
julia> agent.messages = [Dict(:role=> "user", :content=> "Hi there."),
|
||||
Dict(:role=> "assistant", :content=> "Hello! How can I assist you today?"),]
|
||||
|
||||
julia> messagesToString(agent.messages)
|
||||
"<|im_start|>user: Hi there.\n<|im_end|><|im_start|>assistant: Hello! How can I assist you today?\n<|im_end|>"
|
||||
```
|
||||
""" #WORKING
|
||||
function messagesToString(messages::AbstractVector{T}; addressAIas="assistant") where {T<:AbstractDict}
|
||||
conversation = ""
|
||||
if length(messages)!= 0
|
||||
for msg in messages
|
||||
role = msg[:role]
|
||||
content = msg[:content]
|
||||
|
||||
nouse = 0
|
||||
for i in reverse(content)
|
||||
if i == '\n' || i == ' '
|
||||
nouse += 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if role == "user"
|
||||
conversation *= "<|im_start|>$role: $(content[1:end-nouse])\n<|im_end|>"
|
||||
elseif role == "assistant"
|
||||
conversation *= "<|im_start|>$addressAIas: $(content[1:end-nouse])\n<|im_end|>"
|
||||
else
|
||||
error("undefied condition role = $role $(@__LINE__)")
|
||||
end
|
||||
end
|
||||
else
|
||||
conversation = "N/A"
|
||||
end
|
||||
|
||||
return conversation
|
||||
end
|
||||
|
||||
#TODO
|
||||
function checkReasonableness(userMsg::String, context::String, tools)
|
||||
|
||||
Reference in New Issue
Block a user