This commit is contained in:
narawat lamaiin
2025-05-17 12:18:25 +07:00
parent 3e79c0bfed
commit 68c2c2f12b
3 changed files with 133 additions and 91 deletions
+42 -32
View File
@@ -97,7 +97,7 @@ julia> output_thoughtDict = Dict(
# Signature
"""
function decisionMaker(a::T; recentevents::Integer=10, maxattempt=10
function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
) where {T<:agent}
# lessonDict = copy(JSON3.read("lesson.json"))
@@ -133,13 +133,8 @@ function decisionMaker(a::T; recentevents::Integer=10, maxattempt=10
includelatest=true)
recentchat = createChatLog(a.chathistory; index=recentchat_ind)
# recentEventsDict = createEventsLog(recentevents; index=recent_ind)
#BUG timeline only cover event 1-9 out of 10 events while recentchat cover 1-9 because
# recent_ind is based on chathistory. i should ind based on events. The reason is events always
# have more than chathistory due to CHECKINVENTORY() function which store in events BUT NOT in
# chathistory
# # recap as caching
# # query similar result from vectorDB
# recapkeys = keys(a.memory[:recap])
@@ -215,7 +210,7 @@ function decisionMaker(a::T; recentevents::Integer=10, maxattempt=10
- Vintage 0 means non-vintage.
</Store guidelines>
At each round of conversation, you will be given the following information:
Database search result: the result of a database search using SQL commands you have found so far
context: additional information about the current situation
You should then respond to the user with interleaving Plan, Action_name, Action_input:
1) plan: Based on the current situation, state a complete action plan to complete the task. Be specific.
@@ -253,14 +248,14 @@ function decisionMaker(a::T; recentevents::Integer=10, maxattempt=10
"""
<context>
<Available tools>
- CHATBOX which you can use to talk with the user. The input is your intentions for the dialogue. Be specific.
- CHATBOX which you can use to talk with the user. Be specific.
- CHECKINVENTORY allows you to check information about wines you want in your inventory's database. The input must be supported search criteria includeing: wine price, winery, name, vintage, region, country, type, grape varietal, tasting notes, occasion, food pairing, intensity, tannin, sweetness, and acidity.
Example query: "Dry, full-bodied red wine from Burgundy, France or Tuscany, Italy. Merlot varietal. price 100 to 1000 USD."
- PRESENTBOX which you can use to present wines you have found in your inventory to the user. The input are wine names that you want to present.
- ENDCONVERSATION which you can use to properly end the conversation with the user. Input is "NA".
- ENDCONVERSATION which you can use to properly end the conversation with the user. Input is a dialogue where you wrap up the conversation, thank the user, and invite them to return next time.
</Available tools>
$(a.memory[:shortmem][:scratchpad])
Remark: $errornote
Database search result: $database_search_result
</context>
"""
@@ -1123,22 +1118,22 @@ julia>
"""
function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} where {T<:agent}
# a.memory[:recap] = generateSituationReport(a, a.func[:text2textInstructLLM]; skiprecent=0)
thoughtDict = decisionMaker(a; recentevents=5)
thoughtDict = decisionMaker(a)
actionname = thoughtDict[:action_name]
actioninput = thoughtDict[:action_input]
# map action and input() to llm function
response =
if actionname == "CHATBOX"
if actionname == "CHATBOX" || actionname == "ENDCONVERSATION"
(result=thoughtDict[:plan], errormsg=nothing, success=true)
elseif actionname == "CHECKINVENTORY"
checkinventory(a, actioninput)
elseif actionname == "PRESENTBOX"
(result=actioninput, errormsg=nothing, success=true)
elseif actionname == "ENDCONVERSATION"
x = "Conclude the conversation, thanks the user then goodbye and inviting them to return next time."
(result=actioninput, errormsg=nothing, success=true)
# elseif actionname == "ENDCONVERSATION"
# x = "Conclude the conversation, thanks the user then goodbye and inviting them to return next time."
# (result=actioninput, errormsg=nothing, success=true)
else
error("undefined LLM function. Requesting $actionname")
end
@@ -1166,7 +1161,7 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
# )
# )
# result = chatresponse
if actionname ["CHATBOX"]
if actionname ["CHATBOX", "ENDCONVERSATION"]
push!(a.memory[:events],
eventdict(;
event_description="the assistant talks to the user.",
@@ -1178,19 +1173,19 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
)
)
result = actioninput
elseif actionname ["ENDCONVERSATION"]
chatresponse = generatechat(a, thoughtDict)
push!(a.memory[:events],
eventdict(;
event_description="the assistant talks to the user.",
timestamp=Dates.now(),
subject="assistant",
thought=thoughtDict,
actionname=actionname,
actioninput=chatresponse,
)
)
result = chatresponse
# elseif actionname ∈ ["ENDCONVERSATION"]
# chatresponse = generatechat(a, thoughtDict)
# push!(a.memory[:events],
# eventdict(;
# event_description="the assistant talks to the user.",
# timestamp=Dates.now(),
# subject="assistant",
# thought=thoughtDict,
# actionname=actionname,
# actioninput=chatresponse,
# )
# )
# result = chatresponse
elseif actionname ["PRESENTBOX"]
chatresponse = presentbox(a, thoughtDict)
push!(a.memory[:events],
@@ -1215,6 +1210,21 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
else
a.memory[:shortmem][:db_search_result] = vd
end
# add to scratchpad
a.memory[:shortmem][:scratchpad] *=
"""
<database_search_result>
I searched the database with this search term: $actioninput This is what I found: $result
</database_search_result>
"""
else
a.memory[:shortmem][:scratchpad] *=
"""
<database_search_result>
I searched the database with this search term: $actioninput This is what I found: $result
</database_search_result>
"""
end
push!(a.memory[:events],
@@ -1224,7 +1234,7 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
subject= "assistant",
thought=thoughtDict,
actionname=actionname,
actioninput= "I found something in the database using this SQL: $actioninput",
actioninput= "I search the database with this search term: $actioninput",
outcome= "This is what I found:, $result"
)
)
@@ -1296,7 +1306,7 @@ function presentbox(a::sommelier, thoughtDict; maxtattempt::Integer=10, recentev
"""
<context>
Name of the wines that needs to be introduced: $(thoughtDict[:action_input])
Database search result: $database_search_result
$(a.memory[:shortmem][:scratchpad])
P.S. $errornote
</context>
"""