This commit is contained in:
narawat lamaiin
2025-01-21 08:28:26 +07:00
parent bb81b973d3
commit d89d425885
2 changed files with 10 additions and 9 deletions

View File

@@ -237,7 +237,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
chathistory = chatHistoryToText(a.chathistory) chathistory = chatHistoryToText(a.chathistory)
# check if winename in shortmem occurred in chathistory. if not, skip decision and imediately use PRESENTBOX # check if winename in shortmem occurred in chathistory. if not, skip decision and imediately use PRESENTBOX
if haskey(a.memory[:shortmem], :available_wine) if length(a.memory[:shortmem][:available_wine]) != 0
# check if wine name mentioned in recentevents, only check first wine name is enough # check if wine name mentioned in recentevents, only check first wine name is enough
# because agent will recommend every wines it found each time. # because agent will recommend every wines it found each time.
winenames = [] winenames = []
@@ -263,7 +263,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
end end
context = # may b add wine name instead of the hold wine data is better context = # may b add wine name instead of the hold wine data is better
if haskey(a.memory[:shortmem], :available_wine) if length(a.memory[:shortmem][:available_wine]) != 0
winenames = [] winenames = []
for (i, wine) in enumerate(a.memory[:shortmem][:available_wine]) for (i, wine) in enumerate(a.memory[:shortmem][:available_wine])
name = "$i) $(wine["wine_name"]) " name = "$i) $(wine["wine_name"]) "
@@ -872,11 +872,11 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
elseif actionname == "CHECKINVENTORY" elseif actionname == "CHECKINVENTORY"
if rawresponse !== nothing if rawresponse !== nothing
if haskey(a.memory[:shortmem], :available_wine)
vd = GeneralUtils.dfToVectorDict(rawresponse) vd = GeneralUtils.dfToVectorDict(rawresponse)
a.memory[:shortmem][:available_wine] = vcat(vd, rawresponse) if length(a.memory[:shortmem][:available_wine]) == 0
a.memory[:shortmem][:available_wine] = vcat(a.memory[:shortmem][:available_wine], vd)
else else
a.memory[:shortmem][:available_wine] = GeneralUtils.dfToVectorDict(rawresponse) a.memory[:shortmem][:available_wine] = vd
end end
else else
println("checkinventory return nothing") println("checkinventory return nothing")
@@ -965,7 +965,7 @@ function generatechat(a::sommelier, thoughtDict)
# a.memory[:shortmem][:available_wine] is a vector of dictionary # a.memory[:shortmem][:available_wine] is a vector of dictionary
context = context =
if haskey(a.memory[:shortmem], :available_wine) if length(a.memory[:shortmem][:available_wine]) != 0
"Wines previously found in your inventory: $(availableWineToText(a.memory[:shortmem][:available_wine]))" "Wines previously found in your inventory: $(availableWineToText(a.memory[:shortmem][:available_wine]))"
else else
"N/A" "N/A"

View File

@@ -180,10 +180,11 @@ function sommelier(
memory = Dict{Symbol, Any}( memory = Dict{Symbol, Any}(
:chatbox=> "", :chatbox=> "",
:shortmem=> OrderedDict{Symbol, Any}(), :shortmem=> OrderedDict{Symbol, Any}(
:available_wine=> [],
),
:events=> Vector{Dict{Symbol, Any}}(), :events=> Vector{Dict{Symbol, Any}}(),
:state=> Dict{Symbol, Any}( :state=> Dict{Symbol, Any}(
:wine_presented_to_user=> "None",
), ),
:recap=> OrderedDict{Symbol, Any}(), :recap=> OrderedDict{Symbol, Any}(),
) )