update
This commit is contained in:
@@ -183,7 +183,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
|
|||||||
2) Thanks the user when they don't need any further assistance and invite them to comeback next time
|
2) Thanks the user when they don't need any further assistance and invite them to comeback next time
|
||||||
|
|
||||||
Your responsibility does NOT includes:
|
Your responsibility does NOT includes:
|
||||||
1) Asking the user to place an order or make a purchase. 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.
|
||||||
|
|
||||||
@@ -968,9 +968,9 @@ function generatechat(a::sommelier, thoughtDict)
|
|||||||
1) Given the situation, convey your thoughts to the user.
|
1) Given the situation, convey your thoughts to the user.
|
||||||
|
|
||||||
Your responsibility does NOT includes:
|
Your responsibility does NOT includes:
|
||||||
1) Asking the user to place an order or make a purchase. 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 current situation:
|
At each round of conversation, you will be given the current situation:
|
||||||
Your ongoing conversation with the user: ...
|
Your ongoing conversation with the user: ...
|
||||||
@@ -1011,11 +1011,21 @@ function generatechat(a::sommelier, thoughtDict)
|
|||||||
errornote = ""
|
errornote = ""
|
||||||
response = nothing # placeholder for show when error msg show up
|
response = nothing # placeholder for show when error msg show up
|
||||||
|
|
||||||
|
yourthought = "$(thoughtDict[:understanding]) $(thoughtDict[:reasoning]) $(thoughtDict[:plan])"
|
||||||
|
yourthought1 = nothing
|
||||||
|
|
||||||
for attempt in 1:10
|
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 = """
|
usermsg = """
|
||||||
Your ongoing conversation with the user: $chathistory
|
Your ongoing conversation with the user: $chathistory
|
||||||
Contex: $context
|
Contex: $context
|
||||||
Your thoughts: $(thoughtDict[:understanding]) $(thoughtDict[:reasoning]) $(thoughtDict[:plan])
|
Your thoughts: $yourthought1
|
||||||
$errornote
|
$errornote
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -1177,9 +1187,9 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
|
|||||||
1) Ask yourself what to do about the current situation
|
1) Ask yourself what to do about the current situation
|
||||||
|
|
||||||
Your responsibility does NOT includes:
|
Your responsibility does NOT includes:
|
||||||
1) Asking the user to place an order or make a purchase. 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 current situation:
|
At each round of conversation, you will be given the current situation:
|
||||||
Recap: recap of what has happened so far
|
Recap: recap of what has happened so far
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ module llmfunction
|
|||||||
|
|
||||||
export virtualWineUserChatbox, jsoncorrection, checkinventory, # recommendbox,
|
export virtualWineUserChatbox, jsoncorrection, checkinventory, # recommendbox,
|
||||||
virtualWineUserRecommendbox, userChatbox, userRecommendbox, extractWineAttributes_1,
|
virtualWineUserRecommendbox, userChatbox, userRecommendbox, extractWineAttributes_1,
|
||||||
extractWineAttributes_2
|
extractWineAttributes_2, paraphrase
|
||||||
|
|
||||||
using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs, Dates
|
using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs, Dates
|
||||||
using GeneralUtils, SQLLLM
|
using GeneralUtils, SQLLLM
|
||||||
@@ -307,8 +307,6 @@ function checkinventory(a::T1, input::T2
|
|||||||
println("\n~~~ checkinventory result ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
println("\n~~~ checkinventory result ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||||
println(textresult)
|
println(textresult)
|
||||||
|
|
||||||
#[WORKING] when rawresponse is nothing, AI get errors
|
|
||||||
|
|
||||||
return (result=textresult, rawresponse=rawresponse, success=true, errormsg=nothing)
|
return (result=textresult, rawresponse=rawresponse, success=true, errormsg=nothing)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -684,168 +682,110 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2<
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# function concept(a::sommelier, thoughtDict)
|
function paraphrase(text2textInstructLLM::Function, text::String)
|
||||||
# systemmsg =
|
systemmsg =
|
||||||
# """
|
"""
|
||||||
# Your name: N/A
|
Your name: N/A
|
||||||
# Situation:
|
Your vision:
|
||||||
# - You are a helpful assistant
|
- You are a helpful assistant who help the user to paraphrase their text.
|
||||||
# Your vision:
|
Your mission:
|
||||||
# - This is a good opportunity to help the user
|
- To help paraphrase the user's text
|
||||||
# Your mission:
|
Mission's objective includes:
|
||||||
# - To describe the concept of a conversation
|
- To help paraphrase the user's text
|
||||||
# Mission's objective includes:
|
Your responsibility includes:
|
||||||
# - To
|
1) To help paraphrase the user's text
|
||||||
# Your responsibility includes:
|
Your responsibility does NOT includes:
|
||||||
# 1) Given the situation, convey your thoughts to the user.
|
1) N/A
|
||||||
# Your responsibility excludes:
|
Your profile:
|
||||||
# 1) Asking or guiding the user to make a purchase
|
- N/A
|
||||||
# 2) Processing sales orders or engaging in any other sales-related activities
|
Additional information:
|
||||||
# 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.
|
- N/A
|
||||||
# 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.
|
|
||||||
|
|
||||||
# At each round of conversation, you will be given the following information:
|
At each round of conversation, you will be given the following information:
|
||||||
# Your ongoing conversation with the user: ...
|
Text: The user's given text
|
||||||
# Context: ...
|
|
||||||
# Your thoughts: Your current thoughts in your mind
|
|
||||||
|
|
||||||
# You MUST follow the following guidelines:
|
You MUST follow the following guidelines:
|
||||||
# - Do not offer additional services you didn't thought.
|
- N/A
|
||||||
|
|
||||||
# You should follow the following guidelines:
|
You should follow the following guidelines:
|
||||||
# - Focus on the latest conversation.
|
- N/A
|
||||||
# - If the user interrupts, prioritize the user
|
|
||||||
# - Medium and full-bodied red wines should not be paired with spicy foods.
|
|
||||||
|
|
||||||
# You should then respond to the user with:
|
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?
|
1) Paraphrase: Paraphrased text
|
||||||
|
|
||||||
# You should only respond in format as described below:
|
You should only respond in format as described below:
|
||||||
# Chat: ...
|
Paraphrase: ...
|
||||||
|
|
||||||
# Here are some examples of response format:
|
Let's begin!
|
||||||
# Chat: "I see. Let me think about it. I'll get back to you with my recommendation."
|
"""
|
||||||
|
|
||||||
# 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)
|
for attempt in 1:10
|
||||||
# errornote = ""
|
usermsg = """
|
||||||
# response = nothing # placeholder for show when error msg show up
|
Text: $text
|
||||||
|
$errornote
|
||||||
|
"""
|
||||||
|
|
||||||
# for attempt in 1:10
|
_prompt =
|
||||||
# usermsg = """
|
[
|
||||||
# Your ongoing conversation with the user: $chathistory
|
Dict(:name => "system", :text => systemmsg),
|
||||||
# Contex: $context
|
Dict(:name => "user", :text => usermsg)
|
||||||
# Your thoughts: $(thoughtDict[:understanding]) $(thoughtDict[:reasoning]) $(thoughtDict[:plan])
|
]
|
||||||
# $errornote
|
|
||||||
# """
|
|
||||||
|
|
||||||
# _prompt =
|
# put in model format
|
||||||
# [
|
prompt = GeneralUtils.formatLLMtext(_prompt; formatname="llama3instruct")
|
||||||
# Dict(:name => "system", :text => systemmsg),
|
prompt *= """
|
||||||
# Dict(:name => "user", :text => usermsg)
|
<|start_header_id|>assistant<|end_header_id|>
|
||||||
# ]
|
"""
|
||||||
|
|
||||||
# # put in model format
|
try
|
||||||
# prompt = GeneralUtils.formatLLMtext(_prompt; formatname="llama3instruct")
|
response = text2textInstructLLM(prompt)
|
||||||
# prompt *= """
|
# sometime the model response like this "here's how I would respond: ..."
|
||||||
# <|start_header_id|>assistant<|end_header_id|>
|
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
|
for i ∈ [:paraphrase]
|
||||||
# response = a.func[:text2textInstructLLM](prompt)
|
if length(JSON3.write(responsedict[i])) == 0
|
||||||
# # sometime the model response like this "here's how I would respond: ..."
|
error("$i is empty ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||||
# if occursin("respond:", response)
|
end
|
||||||
# errornote = "You don't need to intro your response"
|
end
|
||||||
# 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 ∈ [:chat]
|
# check if there are more than 1 key per categories
|
||||||
# if length(JSON3.write(responsedict[i])) == 0
|
for i ∈ [:paraphrase]
|
||||||
# error("$i is empty ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
matchkeys = GeneralUtils.findMatchingDictKey(responsedict, i)
|
||||||
# end
|
if length(matchkeys) > 1
|
||||||
# end
|
error("paraphrase() has more than one key per categories")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# # check if there are more than 1 key per categories
|
println("\n~~~ paraphrase() ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||||
# for i ∈ [:chat]
|
pprintln(Dict(responsedict))
|
||||||
# matchkeys = GeneralUtils.findMatchingDictKey(responsedict, i)
|
|
||||||
# if length(matchkeys) > 1
|
|
||||||
# error("generatechat has more than one key per categories")
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # check if Context: is in chat
|
result = responsedict[:paraphrase]
|
||||||
# if occursin("Context:", responsedict[:chat])
|
|
||||||
# error("Context: is in text. This is not allowed")
|
|
||||||
# end
|
|
||||||
|
|
||||||
# println("\n~~~ generatechat() ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
return result
|
||||||
# pprintln(Dict(responsedict))
|
catch e
|
||||||
|
io = IOBuffer()
|
||||||
# # check whether an agent recommend wines before checking inventory or recommend wines
|
showerror(io, e)
|
||||||
# # outside its inventory
|
errorMsg = String(take!(io))
|
||||||
# # ask LLM whether there are any winery mentioned in the response
|
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||||
# mentioned_winery = detectWineryName(a, responsedict[:chat])
|
println("\nAttempt $attempt. Error occurred: $errorMsg\n$st ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||||
# if mentioned_winery != "None"
|
end
|
||||||
# mentioned_winery = String.(strip.(split(mentioned_winery, ",")))
|
end
|
||||||
|
error("generatechat failed to generate a response")
|
||||||
# # check whether the wine is in event
|
end
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user