Compare commits
3 Commits
v0.1.2-dev
...
v0.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 724b092bdb | |||
| c56c3d02b0 | |||
|
|
a7f3e29e9c |
106
src/interface.jl
106
src/interface.jl
@@ -182,11 +182,10 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
|
||||
1) Make an informed decision about what you need to do to achieve the goal
|
||||
2) Thanks the user when they don't need any further assistance and invite them to comeback next time
|
||||
|
||||
Your responsibility excludes:
|
||||
1) Asking or guiding the user to make an order or purchase
|
||||
2) Processing sales orders or engaging in any other sales-related activities
|
||||
3) Answering questions beyond just recommendations.
|
||||
4) Offering additional services beyond just recommendations.
|
||||
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.
|
||||
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.
|
||||
|
||||
At each round of conversation, you will be given the current situation:
|
||||
Your recent events: latest 5 events of the situation
|
||||
@@ -195,7 +194,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
|
||||
You must follow the following guidelines:
|
||||
- Generally speaking, your inventory has some wines from France, the United States, Australia, Spain, and Italy, but you won't know exactly until you check your inventory.
|
||||
- All wines in your inventory are always in stock.
|
||||
- Engage in conversation to indirectly investigate the customer's intention, budget and preferences before checking your inventory.
|
||||
- Approach each customer with open-ended questions to understand their preferences, budget, and occasion. This will help you guide the conversation naturally while gathering essential insights. Once you have this information, you can efficiently check your inventory for the best match.
|
||||
- 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, ask the user if they need any further assistance. Do not offer any additional services. If the user doesn't need any further assistance, say goodbye and invite them to come back next time.
|
||||
- Medium and full-bodied red wines should not be paired with spicy foods.
|
||||
@@ -204,11 +203,10 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
|
||||
- When searching an inventory, search as broadly as possible based on the information you have gathered so far.
|
||||
- Encourage the customer to explore different options and try new things.
|
||||
- Sometimes, the item a user desires might not be available in your inventory. In such cases, inform the user that the item is unavailable and suggest an alternative instead.
|
||||
- If a customer requests information about discounts, quantity, rewards programs, promotions, delivery options, boxes, gift wrapping, packaging, or personalized messages, please inform them that they can contact our sales team at the store.
|
||||
- Do not discuss other stores with the user except for your own.
|
||||
|
||||
For your information:
|
||||
- vintage 0 means non-vintage.
|
||||
- Your store carries only wine.
|
||||
- Vintage 0 means non-vintage.
|
||||
|
||||
You should then respond to the user with interleaving Understanding, Reasoning, Plan, Action:
|
||||
1) Understanding:
|
||||
@@ -221,7 +219,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
|
||||
- CHATBOX which you can use to talk with the user. The input is your intentions for the dialogue. Be specific.
|
||||
- CHECKINVENTORY which you can use to check info about wine you want in your inventory. The input is a search term in verbal English.
|
||||
Good query example: white wine, full-bodied, France, less than 2000 USD.
|
||||
- ENDCONVERSATION which you can use when you believe the user has concluded their interaction, to properly end the conversation with them. Input is "NA".
|
||||
- ENDCONVERSATION which you can use when the user has finished their conversation with you, so that you can properly end the conversation. Input is "NA".
|
||||
5) Action_input: input of the action
|
||||
|
||||
You should only respond in format as described below:
|
||||
@@ -233,7 +231,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
|
||||
|
||||
Let's begin!
|
||||
"""
|
||||
|
||||
|
||||
chathistory = chatHistoryToText(a.chathistory)
|
||||
|
||||
# check if winename in shortmem occurred in chathistory. if not, skip decision and imediately use PRESENTBOX
|
||||
@@ -271,7 +269,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
|
||||
push!(winenames, name)
|
||||
end
|
||||
availableWineName = join(winenames, ',')
|
||||
"You found information about the following wines in your inventory: $availableWineName"
|
||||
"Available wines you've found in your inventory so far: $availableWineName"
|
||||
else
|
||||
""
|
||||
end
|
||||
@@ -862,16 +860,49 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
|
||||
actionname=actionname,
|
||||
actioninput=chatresponse,
|
||||
)
|
||||
|
||||
# eventdict(;
|
||||
# event_description="the assistant talks to the user.",
|
||||
# timestamp=Dates.now(),
|
||||
# subject="assistant",
|
||||
# actioninput=chatresponse,
|
||||
# )
|
||||
)
|
||||
result = chatresponse
|
||||
|
||||
# # store thoughtDict after the conversation finish
|
||||
# if a.memory[:events][end][:thought][:action_name] == "ENDCONVERSATION"
|
||||
# # generateSituationReport in the agent didn't include the last conversation
|
||||
# # so the function will be called here
|
||||
# a.memory[:recap] = generateSituationReport(a, a.func[:text2textInstructLLM]; skiprecent=0)
|
||||
|
||||
# for (i, event) in enumerate(a.memory[:events])
|
||||
# if event[:subject] == "assistant"
|
||||
# # create timeline of the last 3 conversation except the last one.
|
||||
# # The former will be used as caching key and the latter will be the caching target
|
||||
# # in vector database
|
||||
# all_recapkeys = keys(a.memory[:recap]) # recap as caching
|
||||
# all_recapkeys_vec = [r for r in all_recapkeys] # convert to a vector
|
||||
|
||||
# # select from 1 to 2nd-to-lase event (i.e. excluding the latest which is assistant's response)
|
||||
# _recapkeys_vec = all_recapkeys_vec[1:i-1]
|
||||
|
||||
# # select only previous 3 recaps
|
||||
# recapkeys_vec =
|
||||
# if length(_recapkeys_vec) <= 3 # 1st message is a user's hello msg
|
||||
# _recapkeys_vec # choose all
|
||||
# else
|
||||
# _recapkeys_vec[end-2:end]
|
||||
# end
|
||||
# #[PENDING] if there is specific data such as number, donot store in database
|
||||
# tempmem = DataStructures.OrderedDict()
|
||||
# for k in recapkeys_vec
|
||||
# tempmem[k] = a.memory[:recap][k]
|
||||
# end
|
||||
|
||||
# recap = GeneralUtils.dictToString_noKey(tempmem)
|
||||
# thoughtDict = a.memory[:events][i][:thought] # latest assistant thoughtDict
|
||||
# a.func[:insertSommelierDecision](recap, thoughtDict)
|
||||
# else
|
||||
# # skip
|
||||
# end
|
||||
# end
|
||||
# println("Caching conversation done")
|
||||
# end
|
||||
|
||||
elseif actionname == "CHECKINVENTORY"
|
||||
if rawresponse !== nothing
|
||||
vd = GeneralUtils.dfToVectorDict(rawresponse)
|
||||
@@ -936,11 +967,10 @@ function generatechat(a::sommelier, thoughtDict)
|
||||
Your responsibility includes:
|
||||
1) Given the situation, convey your thoughts to the user.
|
||||
|
||||
Your responsibility excludes:
|
||||
1) Asking or guiding the user to make an order or purchase
|
||||
2) Processing sales orders or engaging in any other sales-related activities
|
||||
3) Answering questions beyond just recommendations.
|
||||
4) Offering additional services beyond just recommendations.
|
||||
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.
|
||||
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.
|
||||
|
||||
At each round of conversation, you will be given the current situation:
|
||||
Your ongoing conversation with the user: ...
|
||||
@@ -949,13 +979,13 @@ function generatechat(a::sommelier, thoughtDict)
|
||||
|
||||
You MUST follow the following guidelines:
|
||||
- Do not offer additional services you didn't thought.
|
||||
- Focus on plan.
|
||||
|
||||
You should follow the following guidelines:
|
||||
- Focus on the latest conversation.
|
||||
- If the user interrupts, prioritize the user
|
||||
- Be honest
|
||||
- Medium and full-bodied red wines should not be paired with spicy foods.
|
||||
- Do not discuss other stores with the user except for your own.
|
||||
|
||||
You should then respond to the user with:
|
||||
1) Chat: Given the situation, How would you respond to the user to express your thoughts honestly and keep the conversation going smoothly?
|
||||
@@ -981,11 +1011,21 @@ function generatechat(a::sommelier, thoughtDict)
|
||||
errornote = ""
|
||||
response = nothing # placeholder for show when error msg show up
|
||||
|
||||
yourthought = "$(thoughtDict[:understanding]) $(thoughtDict[:reasoning]) $(thoughtDict[:plan])"
|
||||
yourthought1 = nothing
|
||||
|
||||
for attempt in 1:10
|
||||
|
||||
if attempt > 1 # use to prevent LLM generate the same respond over and over
|
||||
yourthought1 = paraphrase(a.func[:text2textInstructLLM], yourthought)
|
||||
else
|
||||
yourthought1 = yourthought
|
||||
end
|
||||
|
||||
usermsg = """
|
||||
Your ongoing conversation with the user: $chathistory
|
||||
Contex: $context
|
||||
Your thoughts: $(thoughtDict[:understanding]) $(thoughtDict[:reasoning]) $(thoughtDict[:plan])
|
||||
Your thoughts: $yourthought1
|
||||
$errornote
|
||||
"""
|
||||
|
||||
@@ -1146,9 +1186,10 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
|
||||
Your responsibility includes:
|
||||
1) Ask yourself what to do about the current situation
|
||||
|
||||
Your responsibility does not include:
|
||||
1) Processing sales orders or engaging in any other sales-related activities.
|
||||
2) Answering questions and offering additional services beyond just recommendations.
|
||||
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.
|
||||
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.
|
||||
|
||||
At each round of conversation, you will be given the current situation:
|
||||
Recap: recap of what has happened so far
|
||||
@@ -1180,7 +1221,7 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
|
||||
- State your understanding about the current situation
|
||||
2) Q: Given the situation, "ask yourself" at least five, but no more than ten, questions
|
||||
3) A: Given the situation, "answer to yourself" the best you can
|
||||
- Do not generate any text after the last answer.
|
||||
- Do not generate any extra text after you finish answering all questions
|
||||
|
||||
You must only respond in format as described below:
|
||||
Understanding: ...
|
||||
@@ -1234,7 +1275,7 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
|
||||
|
||||
context =
|
||||
if length(a.memory[:shortmem][:available_wine]) != 0
|
||||
"Wines previously found in your inventory: $(availableWineToText(a.memory[:shortmem][:available_wine]))"
|
||||
"Available wines you've found in your inventory so far: $(availableWineToText(a.memory[:shortmem][:available_wine]))"
|
||||
else
|
||||
"N/A"
|
||||
end
|
||||
@@ -1350,6 +1391,9 @@ function generateSituationReport(a, text2textInstructLLM::Function; skiprecent::
|
||||
Events timeline: ...
|
||||
Context: ...
|
||||
|
||||
You should follow the following guidelines:
|
||||
- Use the word "user" and "assistant" instead of their name in the report
|
||||
|
||||
You should then respond to the user with:
|
||||
event: a detailed summary for each event without exaggerated details.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ module llmfunction
|
||||
|
||||
export virtualWineUserChatbox, jsoncorrection, checkinventory, # recommendbox,
|
||||
virtualWineUserRecommendbox, userChatbox, userRecommendbox, extractWineAttributes_1,
|
||||
extractWineAttributes_2
|
||||
extractWineAttributes_2, paraphrase
|
||||
|
||||
using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs, Dates
|
||||
using GeneralUtils, SQLLLM
|
||||
@@ -307,8 +307,6 @@ function checkinventory(a::T1, input::T2
|
||||
println("\n~~~ checkinventory result ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
println(textresult)
|
||||
|
||||
#[WORKING] when rawresponse is nothing, AI get errors
|
||||
|
||||
return (result=textresult, rawresponse=rawresponse, success=true, errormsg=nothing)
|
||||
end
|
||||
|
||||
@@ -441,10 +439,19 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
|
||||
end
|
||||
|
||||
# check whether max wine_price is in the input
|
||||
maxprice = split(responsedict[:wine_price], '-')[end]
|
||||
pricerange = split(responsedict[:wine_price], '-')
|
||||
minprice = pricerange[1]
|
||||
maxprice = pricerange[end]
|
||||
if !occursin(maxprice, input)
|
||||
responsedict[:wine_price] = "NA"
|
||||
end
|
||||
# price range like 100-100 is not good
|
||||
if minprice == maxprice
|
||||
errornote = "wine_price with minimum equals to maximum is not valid"
|
||||
println("Attempt $attempt $errornote ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
checkFlag = true
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
content = responsedict[j]
|
||||
@@ -457,7 +464,7 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
|
||||
content = [content]
|
||||
end
|
||||
|
||||
for x in content #BUG why x is "0-1500"
|
||||
for x in content #check whether price are mentioned in the input
|
||||
if !occursin("NA", responsedict[j]) && !occursin(x, input)
|
||||
errornote = "$x is not mentioned in the user query, you must only use the info from the query."
|
||||
println("Attempt $attempt $errornote ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
@@ -468,7 +475,7 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
|
||||
end
|
||||
end
|
||||
end
|
||||
checkFlag == true ? continue : nothing
|
||||
checkFlag == true ? continue : nothing # skip the rest code if true
|
||||
|
||||
# remove (some text)
|
||||
for (k, v) in responsedict
|
||||
@@ -675,168 +682,110 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2<
|
||||
end
|
||||
|
||||
|
||||
# function concept(a::sommelier, thoughtDict)
|
||||
# systemmsg =
|
||||
# """
|
||||
# Your name: N/A
|
||||
# Situation:
|
||||
# - You are a helpful assistant
|
||||
# Your vision:
|
||||
# - This is a good opportunity to help the user
|
||||
# Your mission:
|
||||
# - To describe the concept of a conversation
|
||||
# Mission's objective includes:
|
||||
# - To
|
||||
# Your responsibility includes:
|
||||
# 1) Given the situation, convey your thoughts to the user.
|
||||
# Your responsibility excludes:
|
||||
# 1) Asking or guiding the user to make a purchase
|
||||
# 2) Processing sales orders or engaging in any other sales-related activities
|
||||
# 3) Answering questions and offering additional services beyond just recommendations, such as delivery, box, gift wrapping, personalized messages. Customers can reach out to our sales at the store.
|
||||
# Your profile:
|
||||
# - You are a young professional in a big company.
|
||||
# - You are avid party goer
|
||||
# - You like beer.
|
||||
# - You know nothing about wine.
|
||||
# - You have a budget of 1500usd.
|
||||
# Additional information:
|
||||
# - your boss like spicy food.
|
||||
# - your boss is a middle-aged man.
|
||||
function paraphrase(text2textInstructLLM::Function, text::String)
|
||||
systemmsg =
|
||||
"""
|
||||
Your name: N/A
|
||||
Your vision:
|
||||
- You are a helpful assistant who help the user to paraphrase their text.
|
||||
Your mission:
|
||||
- To help paraphrase the user's text
|
||||
Mission's objective includes:
|
||||
- To help paraphrase the user's text
|
||||
Your responsibility includes:
|
||||
1) To help paraphrase the user's text
|
||||
Your responsibility does NOT includes:
|
||||
1) N/A
|
||||
Your profile:
|
||||
- N/A
|
||||
Additional information:
|
||||
- N/A
|
||||
|
||||
# At each round of conversation, you will be given the following information:
|
||||
# Your ongoing conversation with the user: ...
|
||||
# Context: ...
|
||||
# Your thoughts: Your current thoughts in your mind
|
||||
At each round of conversation, you will be given the following information:
|
||||
Text: The user's given text
|
||||
|
||||
# You MUST follow the following guidelines:
|
||||
# - Do not offer additional services you didn't thought.
|
||||
You MUST follow the following guidelines:
|
||||
- N/A
|
||||
|
||||
# You should follow the following guidelines:
|
||||
# - Focus on the latest conversation.
|
||||
# - If the user interrupts, prioritize the user
|
||||
# - Medium and full-bodied red wines should not be paired with spicy foods.
|
||||
You should follow the following guidelines:
|
||||
- N/A
|
||||
|
||||
# You should then respond to the user with:
|
||||
# 1) Chat: Given the situation, How would you respond to the user to express your thoughts honestly and keep the conversation going smoothly?
|
||||
You should then respond to the user with:
|
||||
1) Paraphrase: Paraphrased text
|
||||
|
||||
# You should only respond in format as described below:
|
||||
# Chat: ...
|
||||
You should only respond in format as described below:
|
||||
Paraphrase: ...
|
||||
|
||||
# Here are some examples of response format:
|
||||
# Chat: "I see. Let me think about it. I'll get back to you with my recommendation."
|
||||
Let's begin!
|
||||
"""
|
||||
|
||||
# Let's begin!
|
||||
# """
|
||||
errornote = ""
|
||||
response = nothing # placeholder for show when error msg show up
|
||||
|
||||
# # a.memory[:shortmem][:available_wine] is a dataframe.
|
||||
# context =
|
||||
# if haskey(a.memory[:shortmem], :available_wine)
|
||||
# "Available wines $(GeneralUtils.dfToString(a.memory[:shortmem][:available_wine]))"
|
||||
# else
|
||||
# "None"
|
||||
# end
|
||||
|
||||
# chathistory = vectorOfDictToText(a.chathistory)
|
||||
# errornote = ""
|
||||
# response = nothing # placeholder for show when error msg show up
|
||||
for attempt in 1:10
|
||||
usermsg = """
|
||||
Text: $text
|
||||
$errornote
|
||||
"""
|
||||
|
||||
# for attempt in 1:10
|
||||
# usermsg = """
|
||||
# Your ongoing conversation with the user: $chathistory
|
||||
# Contex: $context
|
||||
# Your thoughts: $(thoughtDict[:understanding]) $(thoughtDict[:reasoning]) $(thoughtDict[:plan])
|
||||
# $errornote
|
||||
# """
|
||||
_prompt =
|
||||
[
|
||||
Dict(:name => "system", :text => systemmsg),
|
||||
Dict(:name => "user", :text => usermsg)
|
||||
]
|
||||
|
||||
# _prompt =
|
||||
# [
|
||||
# Dict(:name => "system", :text => systemmsg),
|
||||
# Dict(:name => "user", :text => usermsg)
|
||||
# ]
|
||||
# put in model format
|
||||
prompt = GeneralUtils.formatLLMtext(_prompt; formatname="llama3instruct")
|
||||
prompt *= """
|
||||
<|start_header_id|>assistant<|end_header_id|>
|
||||
"""
|
||||
|
||||
# # put in model format
|
||||
# prompt = GeneralUtils.formatLLMtext(_prompt; formatname="llama3instruct")
|
||||
# prompt *= """
|
||||
# <|start_header_id|>assistant<|end_header_id|>
|
||||
# """
|
||||
try
|
||||
response = text2textInstructLLM(prompt)
|
||||
# sometime the model response like this "here's how I would respond: ..."
|
||||
if occursin("respond:", response)
|
||||
errornote = "You don't need to intro your response"
|
||||
error("\n~~~ paraphrase() response contain : ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
end
|
||||
response = GeneralUtils.remove_french_accents(response)
|
||||
response = replace(response, '*'=>"")
|
||||
response = replace(response, '$' => "USD")
|
||||
response = replace(response, '`' => "")
|
||||
response = GeneralUtils.remove_french_accents(response)
|
||||
responsedict = GeneralUtils.textToDict(response, ["Paraphrase"],
|
||||
rightmarker=":", symbolkey=true, lowercasekey=true)
|
||||
|
||||
# try
|
||||
# response = a.func[:text2textInstructLLM](prompt)
|
||||
# # sometime the model response like this "here's how I would respond: ..."
|
||||
# if occursin("respond:", response)
|
||||
# errornote = "You don't need to intro your response"
|
||||
# error("generatechat() response contain : ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
# end
|
||||
# response = GeneralUtils.remove_french_accents(response)
|
||||
# response = replace(response, '*'=>"")
|
||||
# response = replace(response, '$' => "USD")
|
||||
# response = replace(response, '`' => "")
|
||||
# response = GeneralUtils.remove_french_accents(response)
|
||||
# responsedict = GeneralUtils.textToDict(response, ["Chat"],
|
||||
# rightmarker=":", symbolkey=true, lowercasekey=true)
|
||||
for i ∈ [:paraphrase]
|
||||
if length(JSON3.write(responsedict[i])) == 0
|
||||
error("$i is empty ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
end
|
||||
end
|
||||
|
||||
# for i ∈ [:chat]
|
||||
# if length(JSON3.write(responsedict[i])) == 0
|
||||
# error("$i is empty ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
# end
|
||||
# end
|
||||
# check if there are more than 1 key per categories
|
||||
for i ∈ [:paraphrase]
|
||||
matchkeys = GeneralUtils.findMatchingDictKey(responsedict, i)
|
||||
if length(matchkeys) > 1
|
||||
error("paraphrase() has more than one key per categories")
|
||||
end
|
||||
end
|
||||
|
||||
# # check if there are more than 1 key per categories
|
||||
# for i ∈ [:chat]
|
||||
# matchkeys = GeneralUtils.findMatchingDictKey(responsedict, i)
|
||||
# if length(matchkeys) > 1
|
||||
# error("generatechat has more than one key per categories")
|
||||
# end
|
||||
# end
|
||||
println("\n~~~ paraphrase() ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
pprintln(Dict(responsedict))
|
||||
|
||||
# # check if Context: is in chat
|
||||
# if occursin("Context:", responsedict[:chat])
|
||||
# error("Context: is in text. This is not allowed")
|
||||
# end
|
||||
result = responsedict[:paraphrase]
|
||||
|
||||
# println("\n~~~ generatechat() ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
# pprintln(Dict(responsedict))
|
||||
|
||||
# # check whether an agent recommend wines before checking inventory or recommend wines
|
||||
# # outside its inventory
|
||||
# # ask LLM whether there are any winery mentioned in the response
|
||||
# mentioned_winery = detectWineryName(a, responsedict[:chat])
|
||||
# if mentioned_winery != "None"
|
||||
# mentioned_winery = String.(strip.(split(mentioned_winery, ",")))
|
||||
|
||||
# # check whether the wine is in event
|
||||
# isWineInEvent = false
|
||||
# for winename in mentioned_winery
|
||||
# for event in a.memory[:events]
|
||||
# if event[:outcome] !== nothing && occursin(winename, event[:outcome])
|
||||
# isWineInEvent = true
|
||||
# break
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# # if wine is mentioned but not in timeline or shortmem,
|
||||
# # then the agent is not supposed to recommend the wine
|
||||
# if isWineInEvent == false
|
||||
|
||||
# errornote = "Previously: You recommend a wine that is not in your inventory which is not allowed."
|
||||
# error("Previously: You recommend a wine that is not in your inventory which is not allowed.")
|
||||
# end
|
||||
# end
|
||||
|
||||
# result = responsedict[:chat]
|
||||
|
||||
# return result
|
||||
# catch e
|
||||
# io = IOBuffer()
|
||||
# showerror(io, e)
|
||||
# errorMsg = String(take!(io))
|
||||
# st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||
# println("\nAttempt $attempt. Error occurred: $errorMsg\n$st ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
# end
|
||||
# end
|
||||
# error("generatechat failed to generate a response")
|
||||
# end
|
||||
return result
|
||||
catch e
|
||||
io = IOBuffer()
|
||||
showerror(io, e)
|
||||
errorMsg = String(take!(io))
|
||||
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||
println("\nAttempt $attempt. Error occurred: $errorMsg\n$st ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
end
|
||||
end
|
||||
error("generatechat failed to generate a response")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ function addNewMessage(a::T1, name::String, text::T2;
|
||||
error("name is not in agent.availableRole $(@__LINE__)")
|
||||
end
|
||||
|
||||
#[WORKING] summarize the oldest 10 message
|
||||
#[PENDING] summarize the oldest 10 message
|
||||
if length(a.chathistory) > maximumMsg
|
||||
summarize(a.chathistory)
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user