This commit is contained in:
narawat lamaiin
2025-01-16 07:40:39 +07:00
parent c7000f66b8
commit 3fdc0adf99
4 changed files with 44 additions and 44 deletions

View File

@@ -132,17 +132,39 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
1:totalevents 1:totalevents
end end
timeline = "" recentevents = ""
for (i, event) in enumerate(a.memory[:events][ind]) for (i, event) in enumerate(a.memory[:events][ind])
if event[:outcome] === nothing if event[:outcome] === nothing
timeline *= "$i) $(event[:subject])> $(event[:actioninput])\n" recentevents *= "$i) $(event[:subject])> $(event[:actioninput])\n"
else else
timeline *= "$i) $(event[:subject])> $(event[:actioninput]) $(event[:outcome])\n" recentevents *= "$i) $(event[:subject])> $(event[:actioninput]) $(event[:outcome])\n"
end end
end end
#[TESTING] recap as caching
# query similar result from vectorDB # query similar result from vectorDB
similarDecision = a.func[:similarSommelierDecision](timeline) recapkeys = keys(a.memory[:recap])
_recapkeys_vec = [i for i in recapkeys]
# select recent keys
_recentRecapKeys =
if length(a.memory[:recap]) <= 3 # 1st message is a user's hello msg
_recapkeys_vec
elseif length(a.memory[:recap]) > 3
l = length(a.memory[:recap])
_recapkeys_vec[l-2:l]
end
# get recent recap
_recentrecap = OrderedDict()
for (k, v) in a.memory[:recap]
if k _recentRecapKeys
_recentrecap[k] = v
end
end
recentrecap = GeneralUtils.dictToString_noKey(_recentrecap)
similarDecision = a.func[:similarSommelierDecision](recentrecap)
if similarDecision !== nothing if similarDecision !== nothing
responsedict = similarDecision responsedict = similarDecision
@@ -213,7 +235,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
# 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 haskey(a.memory[:shortmem], :available_wine)
# check if wine name mentioned in timeline, 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.
df = a.memory[:shortmem][:available_wine] df = a.memory[:shortmem][:available_wine]
winenames = df[:, :wine_name] winenames = df[:, :wine_name]
@@ -242,7 +264,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
usermsg = usermsg =
""" """
Your recent events: $timeline Your recent events: $recentevents
Your Q&A: $QandA) Your Q&A: $QandA)
$errornote $errornote
""" """
@@ -345,15 +367,6 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
delete!(responsedict, :mentioned_winery) delete!(responsedict, :mentioned_winery)
# #CHANGE cache decision dict into vectorDB, this should be after new message is added to a.memory[:events]
# println("\n~~~ Do you want to cache decision dict? (y/n)")
# user_answer = readline()
# if user_answer == "y"
# timeline = timeline
# decisiondict = responsedict
# a.func[:insertSommelierDecision](timeline, decisiondict)
# end
return responsedict return responsedict
end end
error("DecisionMaker failed to generate a thought ", response) error("DecisionMaker failed to generate a thought ", response)
@@ -1223,16 +1236,21 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
errornote = "" errornote = ""
response = nothing # store for show when error msg show up response = nothing # store for show when error msg show up
#[WORKING]
recap = recap =
if a.memory[:recap] === nothing if length(a.memory[:recap]) <= recent
"None" "None"
else else
if length(a.memory[:events]) > recent recapkeys = keys(a.memory[:recap])
GeneralUtils.dictToString(a.memory[:recap][1:end-recent]) recapkeys_vec = [i for i in recapkeys]
else recapkeys_vec = recapkeys_vec[1:end-recent]
"None" tempmem = OrderedDict()
for (k, v) in a.memory[:recap]
if k recapkeys_vec
tempmem[k] = v
end
end end
GeneralUtils.dictToString(tempmem)
end end
for attempt in 1:10 for attempt in 1:10
@@ -1373,7 +1391,7 @@ end
# end # end
function generateSituationReport(a, text2textInstructLLM::Function; skiprecent::Integer=0 function generateSituationReport(a, text2textInstructLLM::Function; skiprecent::Integer=0
)::Dict )::OrderedDict
systemmsg = systemmsg =
""" """
@@ -1404,16 +1422,7 @@ function generateSituationReport(a, text2textInstructLLM::Function; skiprecent::
return nothing return nothing
end end
# events = deepcopy(a.memory[:events][1:end-skiprecent]) events = a.memory[:events][1:end-skiprecent]
# timeline = ""
# for (i, event) in enumerate(events)
# if event[:outcome] === nothing
# timeline *= "$i) $(event[:subject])> $(event[:actioninput])\n"
# else
# timeline *= "$i) $(event[:subject])> $(event[:actioninput]) $(event[:outcome])\n"
# end
# end
timeline = createTimeline(a.memory[:events]; skiprecent=skiprecent) timeline = createTimeline(a.memory[:events]; skiprecent=skiprecent)

View File

@@ -364,7 +364,7 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
Here are some example: Here are some example:
User's query: red, Chenin Blanc, Riesling, 20 USD User's query: red, Chenin Blanc, Riesling, 20 USD
{"reasoning": ..., "winery": "NA", "wine_name": "NA", "vintage": "NA", "region": "NA", "country": "NA", "wine_type": "red", "grape_varietal": "Chenin Blanc, Riesling", "tasting_notes": "NA", "wine_price": "0-20", "occasion": "NA", "food_to_be_paired_with_wine": "NA"} {"reasoning": ..., "winery": "NA", "wine_name": "NA", "vintage": "NA", "region": "NA", "country": "NA", "wine_type": "red, white", "grape_varietal": "Chenin Blanc, Riesling", "tasting_notes": "NA", "wine_price": "0-20", "occasion": "NA", "food_to_be_paired_with_wine": "NA"}
User's query: Domaine du Collier Saumur Blanc 2019, France, white, Chenin Blanc User's query: Domaine du Collier Saumur Blanc 2019, France, white, Chenin Blanc
{"reasoning": ..., "winery": "Domaine du Collier", "wine_name": "Saumur Blanc", "vintage": "2019", "region": "Saumur", "country": "France", "wine_type": "white", "grape_varietal": "Chenin Blanc", "tasting_notes": "NA", "wine_price": "NA", "occasion": "NA", "food_to_be_paired_with_wine": "NA"} {"reasoning": ..., "winery": "Domaine du Collier", "wine_name": "Saumur Blanc", "vintage": "2019", "region": "Saumur", "country": "France", "wine_type": "white", "grape_varietal": "Chenin Blanc", "tasting_notes": "NA", "wine_price": "NA", "occasion": "NA", "food_to_be_paired_with_wine": "NA"}
@@ -444,7 +444,7 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
end end
else else
content = responsedict[j] content = responsedict[j]
if occursin(",", content) if occursin(',', content)
content = split(content, ",") # sometime AI generates multiple values e.g. "Chenin Blanc, Riesling" content = split(content, ",") # sometime AI generates multiple values e.g. "Chenin Blanc, Riesling"
content = strip.(content) content = strip.(content)
else else

View File

@@ -185,7 +185,7 @@ function sommelier(
:state=> Dict{Symbol, Any}( :state=> Dict{Symbol, Any}(
:wine_presented_to_user=> "None", :wine_presented_to_user=> "None",
), ),
:recap=> nothing, :recap=> OrderedDict{Symbol, Any}(),
) )
newAgent = sommelier( newAgent = sommelier(

View File

@@ -199,15 +199,6 @@ end
function createTimeline(memory::T1; skiprecent::Integer=0) where {T1<:AbstractVector} function createTimeline(memory::T1; skiprecent::Integer=0) where {T1<:AbstractVector}
# totalevents = length(memory)
# ind =
# if totalevents > skiprecent
# start = totalevents - skiprecent
# start:totalevents
# else
# 1:totalevents
# end
events = memory[1:end-skiprecent] events = memory[1:end-skiprecent]
timeline = "" timeline = ""