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
end
timeline = ""
recentevents = ""
for (i, event) in enumerate(a.memory[:events][ind])
if event[:outcome] === nothing
timeline *= "$i) $(event[:subject])> $(event[:actioninput])\n"
recentevents *= "$i) $(event[:subject])> $(event[:actioninput])\n"
else
timeline *= "$i) $(event[:subject])> $(event[:actioninput]) $(event[:outcome])\n"
recentevents *= "$i) $(event[:subject])> $(event[:actioninput]) $(event[:outcome])\n"
end
end
#[TESTING] recap as caching
# 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
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
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.
df = a.memory[:shortmem][:available_wine]
winenames = df[:, :wine_name]
@@ -242,7 +264,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
usermsg =
"""
Your recent events: $timeline
Your recent events: $recentevents
Your Q&A: $QandA)
$errornote
"""
@@ -345,15 +367,6 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
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
end
error("DecisionMaker failed to generate a thought ", response)
@@ -1223,18 +1236,23 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
errornote = ""
response = nothing # store for show when error msg show up
#[WORKING]
recap =
if a.memory[:recap] === nothing
if length(a.memory[:recap]) <= recent
"None"
else
if length(a.memory[:events]) > recent
GeneralUtils.dictToString(a.memory[:recap][1:end-recent])
else
"None"
recapkeys = keys(a.memory[:recap])
recapkeys_vec = [i for i in recapkeys]
recapkeys_vec = recapkeys_vec[1:end-recent]
tempmem = OrderedDict()
for (k, v) in a.memory[:recap]
if k recapkeys_vec
tempmem[k] = v
end
end
GeneralUtils.dictToString(tempmem)
end
for attempt in 1:10
usermsg =
"""
@@ -1373,7 +1391,7 @@ end
# end
function generateSituationReport(a, text2textInstructLLM::Function; skiprecent::Integer=0
)::Dict
)::OrderedDict
systemmsg =
"""
@@ -1404,16 +1422,7 @@ function generateSituationReport(a, text2textInstructLLM::Function; skiprecent::
return nothing
end
# events = deepcopy(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
events = a.memory[:events][1:end-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:
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
{"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
else
content = responsedict[j]
if occursin(",", content)
if occursin(',', content)
content = split(content, ",") # sometime AI generates multiple values e.g. "Chenin Blanc, Riesling"
content = strip.(content)
else

View File

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

View File

@@ -199,15 +199,6 @@ end
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]
timeline = ""