This commit is contained in:
narawat lamaiin
2024-08-22 10:59:47 +07:00
parent 9e13990007
commit 1c21fb5f0a

View File

@@ -952,7 +952,7 @@ function think(a::T)::NamedTuple{(:actionname, :result), Tuple{String, String}}
elseif actionname == "PRESENTBOX" elseif actionname == "PRESENTBOX"
x = """ x = """
1) Provide detailed introductions of $actioninput to help the user make an informed choice. 1) Provide detailed introductions of $actioninput to help the user make an informed choice.
2) Offer a thorough comparison of each option, highlighting their differences. 2) If there are multiple wines, offer a thorough comparison of each option, highlighting their differences.
3) Explain the potential impact each option could bring to the user. 3) Explain the potential impact each option could bring to the user.
""" """
# x = """ # x = """
@@ -1086,14 +1086,14 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F
responsedict = GeneralUtils.textToDict(response,["Mentioning_wine", "Chat"], responsedict = GeneralUtils.textToDict(response,["Mentioning_wine", "Chat"],
rightmarker=":", symbolkey=true, lowercasekey=true) rightmarker=":", symbolkey=true, lowercasekey=true)
for i [:Chat] for i [:chat]
if length(JSON3.write(responsedict[i])) == 0 if length(JSON3.write(responsedict[i])) == 0
error("$i is empty ", @__LINE__) error("$i is empty ", @__LINE__)
end end
end end
# check if there are more than 1 key per categories # check if there are more than 1 key per categories
for i [:Chat] for i [:chat]
matchkeys = GeneralUtils.findMatchingDictKey(responsedict, i) matchkeys = GeneralUtils.findMatchingDictKey(responsedict, i)
if length(matchkeys) > 1 if length(matchkeys) > 1
error("generatechat has more than one key per categories") error("generatechat has more than one key per categories")
@@ -1101,7 +1101,7 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F
end end
# check if Context: is in chat # check if Context: is in chat
if occursin("Context:", responsedict[:Chat]) if occursin("Context:", responsedict[:chat])
error("Context: is in text. This is not allowed") error("Context: is in text. This is not allowed")
end end
@@ -1114,8 +1114,8 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F
if occursin("Yes", responsedict[:mentioning_wine]) && isMemEmpty if occursin("Yes", responsedict[:mentioning_wine]) && isMemEmpty
errornote = "Note: You can't recommend wines yet. You must check your inventory before recommending wine to the user." errornote = "Note: You can't recommend wines yet. You must check your inventory before recommending wine to the user."
error( "You must check your inventory before recommending wine") error( "You must check your inventory before recommending wine")
elseif occursin("(check", chatresponse) || occursin("*check", chatresponse) || elseif occursin("(check", responsedict[:chat]) || occursin("*check", responsedict[:chat]) ||
occursin("inventory)", chatresponse) || occursin("inventory*", chatresponse) occursin("inventory)", responsedict[:chat]) || occursin("inventory*", responsedict[:chat])
errornote = "Note: You can't recommend wines yet. You must check your inventory before recommending wine to the user." errornote = "Note: You can't recommend wines yet. You must check your inventory before recommending wine to the user."
error( "You must check your inventory before recommending wine") error( "You must check your inventory before recommending wine")
@@ -1125,7 +1125,7 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F
memory[:CHATBOX] = "" # delete content because it no longer used. memory[:CHATBOX] = "" # delete content because it no longer used.
delete!(responsedict, :mentioning_wine) delete!(responsedict, :mentioning_wine)
result = responsedict[:Chat] result = responsedict[:chat]
return result return result
catch e catch e
@@ -1298,14 +1298,14 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
try try
response = text2textInstructLLM(prompt) response = text2textInstructLLM(prompt)
q_number = count("Q", response) q_number = count("Q", response)
if q_number < 5 if q_number < 3
error("too few questions only $q_number questions are generated ", @__FILE__, " ", @__LINE__) error("too few questions only $q_number questions are generated ", @__FILE__, " ", @__LINE__)
end end
# response = string(split(response, "Please")[1]) # LLM usually add comments which is no need. # response = string(split(response, "Please")[1]) # LLM usually add comments which is no need.
responsedict = GeneralUtils.textToDict(response, responsedict = GeneralUtils.textToDict(response,
["Understanding", "Q1", "Note"], ["Understanding", "Q1", "Note"],
rightmarker=":", symbolkey=true, lowercasekey=true) rightmarker=":", symbolkey=true, lowercasekey=true)
response = "Q1: " * responsedict[:Q1] response = "Q1: " * responsedict[:q1]
println("--> generatequestion ", @__FILE__, " ", @__LINE__) println("--> generatequestion ", @__FILE__, " ", @__LINE__)
pprintln(response) pprintln(response)
return response return response