3 Commits

Author SHA1 Message Date
narawat lamaiin
a5c6360b4e update 2025-06-03 10:08:54 +07:00
narawat lamaiin
03f50379c9 mark new version 2025-05-26 07:14:19 +07:00
ton
a7da0b8123 Merge pull request 'v0.3.0' (#5) from v0.3.0 into main
Reviewed-on: #5
2025-05-26 00:07:21 +00:00
4 changed files with 144 additions and 121 deletions

View File

@@ -1,7 +1,7 @@
name = "YiemAgent" name = "YiemAgent"
uuid = "e012c34b-7f78-48e0-971c-7abb83b6f0a2" uuid = "e012c34b-7f78-48e0-971c-7abb83b6f0a2"
authors = ["narawat lamaiin <narawat@outlook.com>"] authors = ["narawat lamaiin <narawat@outlook.com>"]
version = "0.3.0" version = "0.4.0"
[deps] [deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"

View File

@@ -129,10 +129,10 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
includelatest=true) includelatest=true)
timeline = createTimeline(a.memory[:events]; eventindex=recentevents_ind) timeline = createTimeline(a.memory[:events]; eventindex=recentevents_ind)
recentchat_ind = GeneralUtils.recentElementsIndex(length(a.chathistory), recentevents; # recentchat_ind = GeneralUtils.recentElementsIndex(length(a.chathistory), recentevents;
includelatest=true) # includelatest=true)
recentchat = createChatLog(a.chathistory; index=recentchat_ind) # recentchat = createChatLog(a.chathistory; index=recentchat_ind)
# recentEventsDict = createEventsLog(recentevents; index=recent_ind) recentEvents = createEventsLog(a.memory[:events]; index=recentevents_ind)
# # recap as caching # # recap as caching
@@ -180,43 +180,51 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
systemmsg = systemmsg =
""" """
<your role>
Your name is $(a.name). You are a sommelier for website-based $(a.retailername)'s wine store. You are working under your mentor supervision. Your name is $(a.name). You are a sommelier for website-based $(a.retailername)'s wine store. You are working under your mentor supervision.
Your goal includes: </your role>
1) Establish a connection with the customer by greeting them warmly <situation>
2) Guide them to select the best wines only from your store's inventory that align with their preferences. Your customer is coming into the store
</situation>
Your responsibility includes: <your mission>
1) Establish a connection with the customer by talking to them politely and showing your enthusiasm for their wine preferences.
2) Provide relevant information and guide them to select the best wines only from your store's inventory that align with their preferences.
</your mission>
<your responsibility includes>
1) According to the store's policy and guidelines, make an informed decision about what you need to do to achieve the goal 1) According to the store's policy and guidelines, make an informed decision about what you need to do to achieve the goal
2) Value your mentor's suggestions. 2) Keep the conversation with the customer going smoothly
2) Obey your mentor's suggestions.
Your responsibility does NOT includes: </your responsibility includes>
<your responsibility does NOT includes>
1) Requesting the user to place an order, make a purchase, or confirm the order. These are the job of our sales team at the store. 1) Requesting the user to place an order, make a purchase, or confirm the order. These are the job of our sales team at the store.
2) Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store. 2) Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store.
3) Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store. 3) Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store.
At each round of conversation, you will be given the following information: </your responsibility does NOT includes>
<at each round of conversation, you will be given the following information>
context: additional information about the current situation context: additional information about the current situation
</at each round of conversation, you will be given the following information>
You should then respond to the user with interleaving Plan, Action_name, Action_input: <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. 1) plan: Based on the current situation, state a complete action plan to complete the task. Be specific.
2) action_name: (Typically corresponds to the execution of the first step in your plan) Can be one of the available tool name 2) action_name: (Typically corresponds to the execution of the first step in your plan) Can be one of the available tool name
3) action_input: The input to the action you are about to perform according to your plan. 3) action_input: The input to the action you are about to perform according to your plan.
</you should then respond to the user with interleaving Plan, Action_name, Action_input>
You should only respond in JSON format as described below: <you should only respond in format as described below>
{ {
"plan": "...", "plan": "...",
"action_name": "...", "action_name": "...",
"action_input": "..." "action_input": "..."
} }
</you should only respond in format as described below>
Let's begin! Let's begin!
""" """
requiredKeys = [:plan, :action_name, :action_input] requiredKeys = [:plan, :action_name, :action_input]
database_search_result = # database_search_result =
if length(a.memory[:shortmem][:db_search_result]) != 0 # if length(a.memory[:shortmem][:db_search_result]) != 0
availableWineToText(a.memory[:shortmem][:db_search_result]) # availableWineToText(a.memory[:shortmem][:db_search_result])
else # else
"N/A" # "N/A"
end # end
errornote = "N/A" errornote = "N/A"
response = nothing # placeholder for show when error msg show up response = nothing # placeholder for show when error msg show up
@@ -233,27 +241,32 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
<context> <context>
<Store_policy> <Store_policy>
- Generally speaking, the store inventory has some wines from France, the United States, Australia, Spain, and Italy, but you won't know exactly until you check your inventory. - Generally speaking, the store inventory has some wines from France, the United States, Australia, Spain, and Italy, but you won't know exactly until you check your inventory.
- If you found wines in the store's database, they are in stock - If you found wines in the store's database, they are in stock.
- Approach each customer with open-ended questions to understand their preferences, budget, and occasion. Once you have these information, you can check your inventory. - You can only recommend wines that are currently in our inventory
- Do not ask the user about wine's flavor e.g. floral, citrusy, nutty or some thing similar as these terms cannot be used to search the database. Other wine characteristics useful for CHECKINVENTORY tools are allowed. - Before searching the database for wine, ensure you have at least the following information: 1) budget, 2) wine type, and 3) occasion. Additional details are always helpful. If the user is unsure, provide relevant information and gather insights to make reasonable inferences.
- Ask the user one question at a time.
- Do not ask the user about wine's flavor e.g. floral, citrusy, nutty or some thing similar as these terms cannot be used to search the database.
- Once the user has selected their wine, if you haven't already, ask the user whether they need any further assistance. Do not offer any additional services. - Once the user has selected their wine, if you haven't already, ask the user whether they need any further assistance. Do not offer any additional services.
- If the user is ending the conversation, say goodbye and invite them to come back next time. - Only end the conversation when the user explicitly intends to do so. When ending, ensure a polite farewell and an invitation to return in the future.
- Spicy foods should not be paired with medium and full-bodied red wines. - Spicy foods should be paired only with light red wines.
- We do not sell organic, sustainability and sulfite wine. - We do not sell organic, sustainable, gluten-free, and sulfite-free wine. Inform the user imediately if they are looking for these types of wines. Do not sell our wines as such.
- Gift box, gift card, and custom messages are available. Inform the user to contact our sales team. - Gift box, gift card, and custom messages are available. Inform the user to contact our sales team.
</Store_policy> </Store_policy>
<Store_guidelines> <Store_guidelines>
- Greeting the customer warmly by ask them how could you help. Do not ask any other questions during this greeting.
- Encourage the customer to explore different options and try new things. - Encourage the customer to explore different options and try new things.
- If you are unable to locate the desired item in the database after 2 attempts, it may not be available in your inventory. In such cases, inform the user that the item is unavailable and suggest an alternative instead. - If you are unable to locate the desired item in the database after 2 attempts, it may not be available in your inventory. In such cases, inform the user that the item is unavailable and suggest an alternative instead.
- Your store carries only wine. - Your store carries only wine.
- Vintage 0 means non-vintage. - Vintage 0 means non-vintage.
</Store_guidelines> - Start searching the database as broadly as possible within the given information boundary to maximize the chances of finding. Avoid unnecessary parameters unless specified by the user. Refine the search subsequently.
</Store_guidelines>Search the database as broad as possible under the informantion you have will increase the chance to find wine. Avoid uneccessary parameter such as region, country, tasting notes unless the user specify
<Available tools> <Available tools>
- CHATBOX which you can use to talk with the user. Be specific. - CHATBOX which you can use to talk with the user. Be specific.
- CHECKWINE 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. - CHECKWINE 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 1: "Dry, full-bodied red wine from Burgundy region, France or Tuscany region, Italy. Merlot varietal. price 100 to 1000 USD." Example query 1: "Dry, full-bodied red wine from 1) region: Burgundy, country: France or 2) region: Tuscany, country: Italy. Grape varietal: Merlot or Syrah. price 100 to 1000 USD."
Example query 2: "Red wine, bold intensity, price under 300 USD" Example query 2: "Red or white wine, medium tannin, price under 700 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. Example query 3: "white wine, region: Tuscany or Bordeaux, country: Italy or France
- 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. The output is presentation of the wines.
- 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. - 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> </Available tools>
$(a.memory[:shortmem][:scratchpad]) $(a.memory[:shortmem][:scratchpad])
@@ -266,7 +279,7 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
Dict(:name => "system", :text => systemmsg), Dict(:name => "system", :text => systemmsg),
] ]
unformatPrompt = vcat(unformatPrompt, recentchat) unformatPrompt = vcat(unformatPrompt, recentEvents)
# put in model format # put in model format
prompt = GeneralUtils.formatLLMtext(unformatPrompt, a.llmFormatName) prompt = GeneralUtils.formatLLMtext(unformatPrompt, a.llmFormatName)
# add info # add info
@@ -387,7 +400,7 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
isWineInEvent = false isWineInEvent = false
for winename in mentioned_winery for winename in mentioned_winery
for event in a.memory[:events] for event in a.memory[:events]
if event[:outcome] !== nothing && occursin(winename, event[:outcome]) if event[:observation] !== nothing && occursin(winename, event[:observation])
isWineInEvent = true isWineInEvent = true
break break
end end
@@ -405,17 +418,14 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
delete!(responsedict, :mentioned_winery) delete!(responsedict, :mentioned_winery)
# check whether responsedict[:action_input] is the same as previous dialogue # check whether responsedict[:action_input] is the same as previous dialogue
if responsedict[:action_input] == a.chathistory[end][:text] if !isempty(a.chathistory) && responsedict[:action_input] == a.chathistory[end][:text]
errornote = "In your previous attempt, you repeated the previous dialogue. Please try again." errornote = "In your previous attempt, you repeated the previous dialogue. Please try again."
println("\nERROR YiemAgent decisionMaker() $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") println("\nERROR YiemAgent decisionMaker() $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue continue
end end
println("\nYiemAgent decisionMaker() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
println("\n$response")
evaluationdict = evaluator(a, timeline, responsedict, context) evaluationdict = evaluator(a, timeline, responsedict, context)
if evaluationdict[:approved] == "no" if evaluationdict[:approval] == "no"
mentor_comment = evaluationdict[:suggestion] mentor_comment = evaluationdict[:suggestion]
errornote = "Your previous attempt was not good enough. Please try again. Here is the mentor's suggestion: $mentor_comment" errornote = "Your previous attempt was not good enough. Please try again. Here is the mentor's suggestion: $mentor_comment"
println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)--> \n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)--> \n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
@@ -425,7 +435,7 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
# store for later training # store for later training
responsedict[:system] = systemmsg responsedict[:system] = systemmsg
responsedict[:unformatPrompt] = unformatPrompt responsedict[:unformatPrompt] = unformatPrompt
responsedict[:recentchat] = recentchat # responsedict[:recentchat] = recentchat
responsedict[:prompt] = prompt responsedict[:prompt] = prompt
responsedict[:context] = context responsedict[:context] = context
responsedict[:think] = think responsedict[:think] = think
@@ -747,7 +757,7 @@ end
# isWineInEvent = false # isWineInEvent = false
# for winename in mentioned_winery # for winename in mentioned_winery
# for event in a.memory[:events] # for event in a.memory[:events]
# if event[:outcome] !== nothing && occursin(winename, event[:outcome]) # if event[:observation] !== nothing && occursin(winename, event[:observation])
# isWineInEvent = true # isWineInEvent = true
# break # break
# end # end
@@ -804,10 +814,6 @@ serving as a heuristic to steer the search algorithm towards the most promising
julia> julia>
``` ```
# TODO
- [WORKING] Implement the function.
# Signature # Signature
""" """
function evaluator(a::T1, timeline, decisiondict, evaluateecontext function evaluator(a::T1, timeline, decisiondict, evaluateecontext
@@ -848,7 +854,7 @@ function evaluator(a::T1, timeline, decisiondict, evaluateecontext
2) decision_evaluation: 2) decision_evaluation:
- Examine how the trainee's decisions align with the store's policies and guidelines before proceeding. - Examine how the trainee's decisions align with the store's policies and guidelines before proceeding.
3) suggestion: Based store policy and guidelines, provide a suggestion for the immediate decision step only. 3) suggestion: Based store policy and guidelines, provide a suggestion for the immediate decision step only.
4) approved: Based on suggestion, decide whether to let the trainee proceed with the decision. Can be "yes" or "no" 4) approval: Can be "yes" or "no". "no" if the suggestion contradict the trainee's decision; otherwise, it is "yes".
</You should then respond to the user with> </You should then respond to the user with>
<You should only respond in JSON format as described below> <You should only respond in JSON format as described below>
@@ -856,13 +862,13 @@ function evaluator(a::T1, timeline, decisiondict, evaluateecontext
"trajectory_evaluation": "...", "trajectory_evaluation": "...",
"decision_evaluation": "...", "decision_evaluation": "...",
"suggestion": "...", "suggestion": "...",
"approved": "...", "approval": "...",
} }
</You should only respond in format as described below> </You should only respond in format as described below>
Let's begin! Let's begin!
""" """
requiredKeys = [:trajectory_evaluation, :decision_evaluation, :approved, :suggestion] requiredKeys = [:trajectory_evaluation, :decision_evaluation, :approval, :suggestion]
errornote = "N/A" errornote = "N/A"
for attempt in 1:10 for attempt in 1:10
@@ -1016,18 +1022,31 @@ julia> response = ChatAgent.conversation(newAgent, "Hi! how are you?")
# Signature # Signature
""" """
function conversation(a::sommelier, userinput::Dict; maximumMsg=50) function conversation(a::sommelier; userinput::Union{Dict, Nothing}=nothing,
maximumMsg=50)
#[WORKING] add the ability to start the conversation by sommelier
# place holder # place holder
actionname = nothing actionname = nothing
result = nothing result = nothing
chatresponse = nothing chatresponse = nothing
userinput[:text] = GeneralUtils.remove_french_accents(userinput[:text])
if userinput[:text] == "newtopic" if userinput === nothing
# thinking loop until AI wants to communicate with the user
chatresponse = nothing
while chatresponse === nothing
actionname, result = think(a)
if actionname ["CHATBOX", "PRESENTBOX", "ENDCONVERSATION"]
chatresponse = result
end
end
addNewMessage(a, "assistant", chatresponse; maximumMsg=maximumMsg)
return chatresponse
elseif userinput[:text] == "newtopic"
clearhistory(a) clearhistory(a)
return "Okay. What shall we talk about?" return "Okay. What shall we talk about?"
else else
userinput[:text] = GeneralUtils.remove_french_accents(userinput[:text])
# add usermsg to a.chathistory # add usermsg to a.chathistory
addNewMessage(a, "user", userinput[:text]; maximumMsg=maximumMsg) addNewMessage(a, "user", userinput[:text]; maximumMsg=maximumMsg)
@@ -1037,8 +1056,8 @@ function conversation(a::sommelier, userinput::Dict; maximumMsg=50)
event_description="the user talks to the assistant.", event_description="the user talks to the assistant.",
timestamp=Dates.now(), timestamp=Dates.now(),
subject="user", subject="user",
actionname="CHATBOX", action_name="CHATBOX",
actioninput=userinput[:text], action_input=userinput[:text],
) )
) )
@@ -1075,7 +1094,8 @@ function conversation(a::Union{companion, virtualcustomer}, userinput::Dict;
event_description="the user talks to the assistant.", event_description="the user talks to the assistant.",
timestamp=Dates.now(), timestamp=Dates.now(),
subject="user", subject="user",
actioninput=userinput[:text], action_name="CHATBOX",
action_input=userinput[:text],
) )
) )
chatresponse = generatechat(a; converPartnerName=converPartnerName, recentEventNum=20) chatresponse = generatechat(a; converPartnerName=converPartnerName, recentEventNum=20)
@@ -1087,7 +1107,8 @@ function conversation(a::Union{companion, virtualcustomer}, userinput::Dict;
event_description="the assistant talks to the user.", event_description="the assistant talks to the user.",
timestamp=Dates.now(), timestamp=Dates.now(),
subject="assistant", subject="assistant",
actioninput=chatresponse, action_name="CHATBOX",
action_input=chatresponse,
) )
) )
return chatresponse return chatresponse
@@ -1162,8 +1183,8 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
timestamp=Dates.now(), timestamp=Dates.now(),
subject="assistant", subject="assistant",
thought=thoughtDict, thought=thoughtDict,
actionname=actionname, action_name=actionname,
actioninput=actioninput, action_input=actioninput,
) )
) )
result = actioninput result = actioninput
@@ -1188,8 +1209,8 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
timestamp=Dates.now(), timestamp=Dates.now(),
subject="assistant", subject="assistant",
thought=thoughtDict, thought=thoughtDict,
actionname=actionname, action_name=actionname,
actioninput=chatresponse, action_input=chatresponse,
) )
) )
result = chatresponse result = chatresponse
@@ -1197,7 +1218,7 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
elseif actionname == "CHECKWINE" elseif actionname == "CHECKWINE"
if rawresponse !== nothing if rawresponse !== nothing
vd = GeneralUtils.dfToVectorDict(rawresponse) # comes in dataframe format vd = GeneralUtils.dfToVectorDict(rawresponse) # comes in dataframe format
a.memory[:shortmem][:found_wine] = vd # used by decisionMaker() as a short note # a.memory[:shortmem][:found_wine] = vd # used by decisionMaker() as a short note
#[PENDING] a.memory[:shortmem][:available_wine] should be OrderedDict instead of vector dict so that no duplicate item are listed? #[PENDING] a.memory[:shortmem][:available_wine] should be OrderedDict instead of vector dict so that no duplicate item are listed?
if length(a.memory[:shortmem][:db_search_result]) != 0 if length(a.memory[:shortmem][:db_search_result]) != 0
a.memory[:shortmem][:db_search_result] = vcat(a.memory[:shortmem][:db_search_result], vd) a.memory[:shortmem][:db_search_result] = vcat(a.memory[:shortmem][:db_search_result], vd)
@@ -1205,20 +1226,20 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
a.memory[:shortmem][:db_search_result] = vd a.memory[:shortmem][:db_search_result] = vd
end end
# add to scratchpad # # add to scratchpad
a.memory[:shortmem][:scratchpad] *= # a.memory[:shortmem][:scratchpad] *=
""" # """
<database_search_result> # <database_search_result>
I searched the database with this search term: $actioninput \nThis is what I found: $result # I searched the database with this search term: $actioninput \nThis is what I found: $result
</database_search_result> # </database_search_result>
""" # """
else else
a.memory[:shortmem][:scratchpad] *= # a.memory[:shortmem][:scratchpad] *=
""" # """
<database_search_result> # <database_search_result>
I searched the database with this search term: $actioninput \nThis is what I found: $result # I searched the database with this search term: $actioninput \nThis is what I found: $result
</database_search_result> # </database_search_result>
""" # """
end end
push!(a.memory[:events], push!(a.memory[:events],
@@ -1227,9 +1248,9 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
timestamp= Dates.now(), timestamp= Dates.now(),
subject= "assistant", subject= "assistant",
thought=thoughtDict, thought=thoughtDict,
actionname=actionname, action_name=actionname,
actioninput= "I search the database with this search term: $actioninput", action_input= "I search the database with this search term: $actioninput",
outcome= "This is what I found:, $result" observation= "This is what I found:, $result"
) )
) )
@@ -1399,7 +1420,7 @@ function presentbox(a::sommelier, thoughtDict; maxtattempt::Integer=10, recentev
isWineInEvent = false isWineInEvent = false
for winename in mentioned_winery for winename in mentioned_winery
for event in a.memory[:events] for event in a.memory[:events]
if event[:outcome] !== nothing && occursin(winename, event[:outcome]) if event[:observation] !== nothing && occursin(winename, event[:observation])
isWineInEvent = true isWineInEvent = true
break break
end end
@@ -1580,7 +1601,7 @@ end
# isWineInEvent = false # isWineInEvent = false
# for winename in mentioned_winery # for winename in mentioned_winery
# for event in a.memory[:events] # for event in a.memory[:events]
# if event[:outcome] !== nothing && occursin(winename, event[:outcome]) # if event[:observation] !== nothing && occursin(winename, event[:observation])
# isWineInEvent = true # isWineInEvent = true
# break # break
# end # end
@@ -1791,7 +1812,7 @@ function generatechat(a::sommelier, thoughtDict; maxattempt::Integer=10)
isWineInEvent = false isWineInEvent = false
for winename in mentioned_winery for winename in mentioned_winery
for event in a.memory[:events] for event in a.memory[:events]
if event[:outcome] !== nothing && occursin(winename, event[:outcome]) if event[:observation] !== nothing && occursin(winename, event[:observation])
isWineInEvent = true isWineInEvent = true
break break
end end
@@ -1997,7 +2018,7 @@ function generatechat(a::virtualcustomer;
end end
# check if the dialogue is the same as the previous one # check if the dialogue is the same as the previous one
if responsedict[:dialogue] == a.chathistory[end][:text] if length(responsedict[:dialogue]) != 0 && responsedict[:dialogue] == a.chathistory[end][:text]
errornote = "In your previous attempt you said $(responsedict[:dialogue]) which was the same as the previous one." errornote = "In your previous attempt you said $(responsedict[:dialogue]) which was the same as the previous one."
println("\nYiemAgent generatechat() $errornote:\n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") println("\nYiemAgent generatechat() $errornote:\n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue continue
@@ -2195,7 +2216,7 @@ function generatequestion(a, text2textInstructLLM::Function, timeline)::String
isWineInEvent = false isWineInEvent = false
for winename in mentioned_winery for winename in mentioned_winery
for event in a.memory[:events] for event in a.memory[:events]
if event[:outcome] !== nothing && occursin(winename, event[:outcome]) if event[:observation] !== nothing && occursin(winename, event[:observation])
isWineInEvent = true isWineInEvent = true
break break
end end

View File

@@ -373,8 +373,8 @@ function extractWineAttributes_1(a::T1, input::T2; maxattempt=10
wine_name: name of the wine wine_name: name of the wine
winery: name of the winery winery: name of the winery
vintage: the year of the wine vintage: the year of the wine
region: a region, such as Burgundy, Bordeaux, Champagne, Napa Valley, Tuscany, California, Oregon, etc region: a region, such as Burgundy, Bordeaux, Champagne, Napa Valley, Tuscany, California, Oregon, etc. Use "or" if there are multiple regions.
country: a country where wine is produced. Can be "Austria", "Australia", "France", "Germany", "Italy", "Portugal", "Spain", "United States" country: a country where wine is produced. Can be "Austria", "Australia", "France", "Germany", "Italy", "Portugal", "Spain", "United States". Use "or" if there are multiple countries.
wine_type: can be one of: "red", "white", "sparkling", "rose", "dessert" or "fortified" wine_type: can be one of: "red", "white", "sparkling", "rose", "dessert" or "fortified"
grape_varietal: the name of the primary grape used to make the wine grape_varietal: the name of the primary grape used to make the wine
tasting_notes: a word describe the wine's flavor, such as "butter", "oak", "fruity", "raspberry", "earthy", "floral", etc tasting_notes: a word describe the wine's flavor, such as "butter", "oak", "fruity", "raspberry", "earthy", "floral", etc
@@ -866,8 +866,7 @@ function paraphrase(text2textInstructLLM::Function, text::String)
Let's begin! Let's begin!
""" """
#[WORKING] use JSON3 the same as extractWineAttributes_1 is better #[PENDING] use JSON3 the same as extractWineAttributes_1 is better. change this function to use the same format use decisionMaker
#[WORKING] change this function to use the same format use decisionMater
header = ["Paraphrase:"] header = ["Paraphrase:"]
dictkey = ["paraphrase"] dictkey = ["paraphrase"]

View File

@@ -231,12 +231,12 @@ function eventdict(;
timestamp::Union{DateTime, Nothing}=nothing, timestamp::Union{DateTime, Nothing}=nothing,
subject::Union{String, Nothing}=nothing, subject::Union{String, Nothing}=nothing,
thought::Union{AbstractDict, Nothing}=nothing, thought::Union{AbstractDict, Nothing}=nothing,
actionname::Union{String, Nothing}=nothing, # "CHAT", "CHECKINVENTORY", "PRESENTBOX", etc action_name::Union{String, Nothing}=nothing, # "CHAT", "CHECKINVENTORY", "PRESENTBOX", etc
actioninput::Union{String, Nothing}=nothing, action_input::Union{String, Nothing}=nothing,
location::Union{String, Nothing}=nothing, location::Union{String, Nothing}=nothing,
equipment_used::Union{String, Nothing}=nothing, equipment_used::Union{String, Nothing}=nothing,
material_used::Union{String, Nothing}=nothing, material_used::Union{String, Nothing}=nothing,
outcome::Union{String, Nothing}=nothing, observation::Union{String, Nothing}=nothing,
note::Union{String, Nothing}=nothing, note::Union{String, Nothing}=nothing,
) )
@@ -245,12 +245,12 @@ function eventdict(;
:timestamp=> timestamp, :timestamp=> timestamp,
:subject=> subject, :subject=> subject,
:thought=> thought, :thought=> thought,
:actionname=> actionname, :action_name=> action_name,
:actioninput=> actioninput, :action_input=> action_input,
:location=> location, :location=> location,
:equipment_used=> equipment_used, :equipment_used=> equipment_used,
:material_used=> material_used, :material_used=> material_used,
:outcome=> outcome, :observation=> observation,
:note=> note, :note=> note,
) )
@@ -266,7 +266,7 @@ end
Each event dictionary should have the following keys: Each event dictionary should have the following keys:
- :subject - The subject or entity performing the action - :subject - The subject or entity performing the action
- :actioninput - The action or input performed by the subject - :actioninput - The action or input performed by the subject
- :outcome - (Optional) The result or outcome of the action - :observation - (Optional) The result or outcome of the action
# Returns # Returns
- `timeline::String` - `timeline::String`
@@ -276,8 +276,8 @@ end
# Example # Example
events = [ events = [
Dict(:subject => "User", :actioninput => "Hello", :outcome => nothing), Dict(:subject => "User", :actioninput => "Hello", :observation => nothing),
Dict(:subject => "Assistant", :actioninput => "Hi there!", :outcome => "with a smile") Dict(:subject => "Assistant", :actioninput => "Hi there!", :observation => "with a smile")
] ]
timeline = createTimeline(events) timeline = createTimeline(events)
# 1) User> Hello # 1) User> Hello
@@ -297,19 +297,19 @@ function createTimeline(events::T1; eventindex::Union{UnitRange, Nothing}=nothin
1:length(events) 1:length(events)
end end
#[WORKING] Iterate through events and format each one # Iterate through events and format each one
for i in ind for i in ind
event = events[i] event = events[i]
# If no outcome exists, format without outcome # If no outcome exists, format without outcome
# if event[:actionname] == "CHATBOX" # if event[:actionname] == "CHATBOX"
# timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput])\n" # timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput])\n"
# elseif event[:actionname] == "CHECKINVENTORY" && event[:outcome] === nothing # elseif event[:actionname] == "CHECKINVENTORY" && event[:observation] === nothing
# timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: Not done yet.\n" # timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: Not done yet.\n"
# If outcome exists, include it in formatting # If outcome exists, include it in formatting
if event[:actionname] == "CHECKWINE" if event[:action_name] == "CHECKWINE"
timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: $(event[:outcome])\n" timeline *= "Event_$i $(event[:subject])> action_name: $(event[:action_name]), action_input: $(event[:action_input]), observation: $(event[:observation])\n"
else else
timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput])\n" timeline *= "Event_$i $(event[:subject])> action_name: $(event[:action_name]), action_input: $(event[:action_input])\n"
end end
end end
@@ -333,11 +333,11 @@ end
# for i in ind # for i in ind
# event = events[i] # event = events[i]
# # If no outcome exists, format without outcome # # If no outcome exists, format without outcome
# if event[:outcome] === nothing # if event[:observation] === nothing
# timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: Not done yet.\n" # timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: Not done yet.\n"
# # If outcome exists, include it in formatting # # If outcome exists, include it in formatting
# else # else
# timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: $(event[:outcome])\n" # timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: $(event[:observation])\n"
# end # end
# end # end
@@ -363,16 +363,19 @@ function createEventsLog(events::T1; index::Union{UnitRange, Nothing}=nothing
for i in ind for i in ind
event = events[i] event = events[i]
# If no outcome exists, format without outcome # If no outcome exists, format without outcome
if event[:outcome] === nothing if event[:observation] === nothing
subject = event[:subject] subject = event[:subject]
actioninput = event[:actioninput] action_name = event[:action_name]
d = Dict{Symbol, String}(:name=>subject, :text=>actioninput) action_input = event[:action_input]
str = "Action_name: $action_name, Action_input: $action_input"
d = Dict{Symbol, String}(:name=>subject, :text=>str)
push!(log, d) push!(log, d)
else else
subject = event[:subject] subject = event[:subject]
actioninput = event[:actioninput] action_name = event[:action_name]
outcome = event[:outcome] action_input = event[:action_input]
str = "Action: $actioninput Outcome: $outcome" observation = event[:observation]
str = "Action_name: $action_name, Action_input: $action_input, Observation: $observation"
d = Dict{Symbol, String}(:name=>subject, :text=>str) d = Dict{Symbol, String}(:name=>subject, :text=>str)
push!(log, d) push!(log, d)
end end