|
|
|
@@ -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 name is $(a.name). You are a sommelier for website-based $(a.retailername)'s wine store. You are working under your mentor supervision.
|
|
|
|
<your role>
|
|
|
|
Your goal includes:
|
|
|
|
Your name is $(a.name). You are a sommelier for website-based $(a.retailername)'s wine store. You are working under your mentor supervision.
|
|
|
|
1) Establish a connection with the customer by greeting them warmly
|
|
|
|
</your role>
|
|
|
|
2) Guide them to select the best wines only from your store's inventory that align with their preferences.
|
|
|
|
<situation>
|
|
|
|
|
|
|
|
Your customer is coming into the store
|
|
|
|
Your responsibility includes:
|
|
|
|
</situation>
|
|
|
|
1) According to the store's policy and guidelines, make an informed decision about what you need to do to achieve the goal
|
|
|
|
<your mission>
|
|
|
|
2) Value your mentor's suggestions.
|
|
|
|
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 responsibility does NOT includes:
|
|
|
|
</your mission>
|
|
|
|
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.
|
|
|
|
<your responsibility includes>
|
|
|
|
2) Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store.
|
|
|
|
1) According to the store's policy and guidelines, make an informed decision about what you need to do to achieve the goal
|
|
|
|
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.
|
|
|
|
2) Keep the conversation with the customer going smoothly
|
|
|
|
At each round of conversation, you will be given the following information:
|
|
|
|
2) Obey your mentor's suggestions.
|
|
|
|
context: additional information about the current situation
|
|
|
|
</your responsibility includes>
|
|
|
|
|
|
|
|
<your responsibility does NOT includes>
|
|
|
|
You should then respond to the user with interleaving Plan, Action_name, Action_input:
|
|
|
|
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) plan: Based on the current situation, state a complete action plan to complete the task. Be specific.
|
|
|
|
2) Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store.
|
|
|
|
2) action_name: (Typically corresponds to the execution of the first step in your plan) Can be one of the available tool name
|
|
|
|
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) action_input: The input to the action you are about to perform according to your plan.
|
|
|
|
</your responsibility does NOT includes>
|
|
|
|
|
|
|
|
<at each round of conversation, you will be given the following information>
|
|
|
|
You should only respond in JSON format as described below:
|
|
|
|
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>
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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 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"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1248,7 +1269,7 @@ function presentbox(a::sommelier, thoughtDict; maxtattempt::Integer=10, recentev
|
|
|
|
systemmsg =
|
|
|
|
systemmsg =
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
<Your role>
|
|
|
|
<Your role>
|
|
|
|
Your name is $(a.name). You are a helpful English-speaking assistant, acting as a polite, website-based sommelier for $(a.retailername)'s wine store.
|
|
|
|
Your name is $(a.name). You are a helpful English-speaking assistant, acting as a polite, website-based sommelier for $(a.retailername)'s wine store.
|
|
|
|
</Your role>
|
|
|
|
</Your role>
|
|
|
|
<Situation>
|
|
|
|
<Situation>
|
|
|
|
You have checked the inventory and found wines that may match what the user wants
|
|
|
|
You have checked the inventory and found wines that may match what the user wants
|
|
|
|
@@ -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
|
|
|
|
|