use Dict string key
This commit is contained in:
+55
-56
@@ -26,16 +26,16 @@ julia> client, connection = MakeConnection("test.mosquitto.org", 1883)
|
||||
julia> connect(client, connection)
|
||||
julia> msgMeta = GeneralUtils.generate_msgMeta("testtopic")
|
||||
julia> agentConfig = Dict(
|
||||
:receiveprompt=>Dict(
|
||||
:mqtttopic=> "testtopic/receive",
|
||||
),
|
||||
:receiveinternal=>Dict(
|
||||
:mqtttopic=> "testtopic/internal",
|
||||
),
|
||||
:text2text=>Dict(
|
||||
:mqtttopic=> "testtopic/text2text",
|
||||
),
|
||||
)
|
||||
"receiveprompt"=>Dict(
|
||||
"mqtttopic"=> "testtopic/receive",
|
||||
),
|
||||
"receiveinternal"=>Dict(
|
||||
"mqtttopic"=> "testtopic/internal",
|
||||
),
|
||||
"text2text"=>Dict(
|
||||
"mqtttopic"=> "testtopic/text2text",
|
||||
),
|
||||
)
|
||||
julia> a = YiemAgent.sommelier(
|
||||
client,
|
||||
msgMeta,
|
||||
@@ -52,9 +52,9 @@ julia> YiemAgent.clearhistory(a)
|
||||
"""
|
||||
function clearhistory(a::T) where {T<:agent}
|
||||
empty!(a.chathistory)
|
||||
empty!(a.memory[:shortmem])
|
||||
empty!(a.memory[:events])
|
||||
a.memory[:chatbox] = ""
|
||||
empty!(a.memory["shortmem"])
|
||||
empty!(a.memory["events"])
|
||||
a.memory["chatbox"] = ""
|
||||
end
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ This function takes in a vector of dictionaries and outputs a single string wher
|
||||
|
||||
julia> using Revise
|
||||
julia> using GeneralUtils
|
||||
julia> vecd = [Dict(:name => "John", :text => "Hello"), Dict(:name => "Jane", :text => "Goodbye")]
|
||||
julia> vecd = [Dict("name" => "John", "text" => "Hello"), Dict("name" => "Jane", "text" => "Goodbye")]
|
||||
julia> GeneralUtils.vectorOfDictToText(vecd, withkey=true)
|
||||
"John> Hello\nJane> Goodbye\n"
|
||||
```
|
||||
@@ -233,17 +233,17 @@ function eventdict(;
|
||||
)
|
||||
|
||||
d = Dict{String, Any}(
|
||||
:event_description=> event_description,
|
||||
:timestamp=> timestamp,
|
||||
:subject=> subject,
|
||||
:thought=> thought,
|
||||
:actionname=> actionname,
|
||||
:actioninput=> actioninput,
|
||||
:location=> location,
|
||||
:equipment_used=> equipment_used,
|
||||
:material_used=> material_used,
|
||||
:observation=> observation,
|
||||
:note=> note,
|
||||
"event_description"=> event_description,
|
||||
"timestamp"=> timestamp,
|
||||
"subject"=> subject,
|
||||
"thought"=> thought,
|
||||
"actionname"=> actionname,
|
||||
"actioninput"=> actioninput,
|
||||
"location"=> location,
|
||||
"equipment_used"=> equipment_used,
|
||||
"material_used"=> material_used,
|
||||
"observation"=> observation,
|
||||
"note"=> note,
|
||||
)
|
||||
|
||||
return d
|
||||
@@ -268,8 +268,8 @@ end
|
||||
# Example
|
||||
|
||||
events = [
|
||||
Dict(:subject => "User", :actioninput => "Hello", :observation => nothing),
|
||||
Dict(:subject => "Assistant", :actioninput => "Hi there!", :observation => "with a smile")
|
||||
Dict("subject" => "User", "actioninput" => "Hello", "observation" => nothing),
|
||||
Dict("subject" => "Assistant", "actioninput" => "Hi there!", "observation" => "with a smile")
|
||||
]
|
||||
timeline = createTimeline(events)
|
||||
# 1) User> Hello
|
||||
@@ -293,16 +293,15 @@ function createTimeline(events::T1; eventindex::Union{UnitRange, Nothing}=nothin
|
||||
for i in ind
|
||||
event = events[i]
|
||||
# If no outcome exists, format without outcome
|
||||
# if event[:actionname] == "CHATBOX"
|
||||
# timeline *= "Event_$i $(event[:subject])> actionname: $(event[:actionname]), actioninput: $(event[:actioninput])\n"
|
||||
# elseif event[:actionname] == "CHECKINVENTORY" && event[:observation] === nothing
|
||||
# timeline *= "Event_$i $(event[:subject])> actionname: $(event[:actionname]), actioninput: $(event[:actioninput]), observation: Not done yet.\n"
|
||||
# If outcome exists, include it in formatting
|
||||
if event[:actionname] == "CHECKWINE"
|
||||
timeline *= "Event_$i $(event[:subject])> actionname: $(event[:actionname]), actioninput: $(event[:actioninput]), observation: $(event[:observation])\n"
|
||||
# if event["actionname"] == "CHATBOX"
|
||||
# timeline *= "Event_$i $(event["subject"])> actionname: $(event["actionname"]), actioninput: $(event["actioninput"])\n"
|
||||
# elseif event["actionname"] == "CHECKINVENTORY" && event["observation"] === nothing
|
||||
# timeline *= "Event_$i $(event["subject"])> actionname: $(event["actionname"]), actioninput: $(event["actioninput"]), observation: Not done yet.\n"
|
||||
if event["actionname"] == "CHECKWINE"
|
||||
timeline *= "Event_$i $(event["subject"])> actionname: $(event["actionname"]), actioninput: $(event["actioninput"]), observation: $(event["observation"])\\n"
|
||||
else
|
||||
timeline *= "Event_$i $(event[:subject])> actionname: $(event[:actionname]), actioninput: $(event[:actioninput])\n"
|
||||
end
|
||||
timeline *= "Event_$i $(event["subject"])> actionname: $(event["actionname"]), actioninput: $(event["actioninput"])\\n"
|
||||
end
|
||||
end
|
||||
|
||||
# Return formatted timeline string
|
||||
@@ -325,11 +324,11 @@ end
|
||||
# for i in ind
|
||||
# event = events[i]
|
||||
# # If no outcome exists, format without outcome
|
||||
# if event[:observation] === nothing
|
||||
# timeline *= "Event_$i $(event[:subject])> actionname: $(event[:actionname]), actioninput: $(event[:actioninput]), observation: Not done yet.\n"
|
||||
# # If outcome exists, include it in formatting
|
||||
# else
|
||||
# timeline *= "Event_$i $(event[:subject])> actionname: $(event[:actionname]), actioninput: $(event[:actioninput]), observation: $(event[:observation])\n"
|
||||
# if event["observation"] === nothing
|
||||
# timeline *= "Event_$i $(event["subject"])> actionname: $(event["actionname"]), actioninput: $(event["actioninput"]), observation: Not done yet.\n"
|
||||
# # If outcome exists, include it in formatting
|
||||
# else
|
||||
# timeline *= "Event_$i $(event["subject"])> actionname: $(event["actionname"]), actioninput: $(event["actioninput"]), observation: $(event["observation"])\\n"
|
||||
# end
|
||||
# end
|
||||
|
||||
@@ -341,7 +340,7 @@ end
|
||||
function createEventsLog(events::T1; index::Union{UnitRange, Nothing}=nothing
|
||||
) where {T1<:AbstractVector}
|
||||
# Initialize empty log array
|
||||
log = Dict{Symbol, String}[]
|
||||
log = Dict{String, String}[]
|
||||
|
||||
# Determine which indices to use - either provided range or full length
|
||||
ind =
|
||||
@@ -355,20 +354,20 @@ function createEventsLog(events::T1; index::Union{UnitRange, Nothing}=nothing
|
||||
for i in ind
|
||||
event = events[i]
|
||||
# If no outcome exists, format without outcome
|
||||
if event[:observation] === nothing
|
||||
subject = event[:subject]
|
||||
actionname = event[:actionname]
|
||||
actioninput = event[:actioninput]
|
||||
if event["observation"] === nothing
|
||||
subject = event["subject"]
|
||||
actionname = event["actionname"]
|
||||
actioninput = event["actioninput"]
|
||||
str = "actionname: $actionname, actioninput: $actioninput"
|
||||
d = Dict{Symbol, String}(:name=>subject, :text=>str)
|
||||
d = Dict{String, String}("name"=>subject, "text"=>str)
|
||||
push!(log, d)
|
||||
else
|
||||
subject = event[:subject]
|
||||
actionname = event[:actionname]
|
||||
actioninput = event[:actioninput]
|
||||
observation = event[:observation]
|
||||
subject = event["subject"]
|
||||
actionname = event["actionname"]
|
||||
actioninput = event["actioninput"]
|
||||
observation = event["observation"]
|
||||
str = "actionname: $actionname, actioninput: $actioninput, observation: $observation"
|
||||
d = Dict{Symbol, String}(:name=>subject, :text=>str)
|
||||
d = Dict{String, String}("name"=>subject, "text"=>str)
|
||||
push!(log, d)
|
||||
end
|
||||
end
|
||||
@@ -380,7 +379,7 @@ end
|
||||
function createChatLog(chatdict::T1; index::Union{UnitRange, Nothing}=nothing
|
||||
) where {T1<:AbstractVector}
|
||||
# Initialize empty log array
|
||||
log = Dict{Symbol, String}[]
|
||||
log = Dict{String, String}[]
|
||||
|
||||
# Determine which indices to use - either provided range or full length
|
||||
ind =
|
||||
@@ -393,9 +392,9 @@ function createChatLog(chatdict::T1; index::Union{UnitRange, Nothing}=nothing
|
||||
# Iterate through events and format each one
|
||||
for i in ind
|
||||
event = chatdict[i]
|
||||
subject = event[:name]
|
||||
text = event[:text]
|
||||
d = Dict{Symbol, String}(:name=>subject, :text=>text)
|
||||
subject = event["name"]
|
||||
text = event["text"]
|
||||
d = Dict{String, String}("name"=>subject, "text"=>text)
|
||||
push!(log, d)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user