use Dict string key
This commit is contained in:
+53
-54
@@ -37,10 +37,10 @@ function virtualWineUserRecommendbox(a::T1, input
|
||||
)::Union{Tuple{String, Number, Number, Bool}, Tuple{String, Nothing, Number, Bool}} where {T1<:agent}
|
||||
|
||||
# put in model format
|
||||
virtualWineCustomer = a.config[:externalservice][:virtualWineCustomer_1]
|
||||
llminfo = virtualWineCustomer[:llminfo]
|
||||
virtualWineCustomer = a.config["externalservice"]["virtualWineCustomer_1"]
|
||||
llminfo = virtualWineCustomer["llminfo"]
|
||||
prompt =
|
||||
if llminfo[:name] == "llama3instruct"
|
||||
if llminfo["name"] == "llama3instruct"
|
||||
formatLLMtext_llama3instruct("assistant", input)
|
||||
else
|
||||
error("llm model name is not defied yet $(@__LINE__)")
|
||||
@@ -48,26 +48,26 @@ function virtualWineUserRecommendbox(a::T1, input
|
||||
|
||||
# send formatted input to user using GeneralUtils.sendReceiveMqttMsg
|
||||
msgMeta = GeneralUtils.generate_msgMeta(
|
||||
virtualWineCustomer[:mqtttopic],
|
||||
virtualWineCustomer["mqtttopic"],
|
||||
senderName= "virtualWineUserRecommendbox",
|
||||
senderId= a.id,
|
||||
receiverName= "virtualWineCustomer",
|
||||
mqttBroker= a.config[:mqttServerInfo][:broker],
|
||||
mqttBrokerPort= a.config[:mqttServerInfo][:port],
|
||||
mqttBroker= a.config["mqttServerInfo"]["broker"],
|
||||
mqttBrokerPort= a.config["mqttServerInfo"]["port"],
|
||||
msgId = "dummyid" #CHANGE remove after testing finished
|
||||
)
|
||||
|
||||
outgoingMsg = Dict(
|
||||
:msgMeta=> msgMeta,
|
||||
:payload=> Dict(
|
||||
:text=> prompt,
|
||||
"msgMeta"=> msgMeta,
|
||||
"payload"=> Dict(
|
||||
"text"=> prompt,
|
||||
)
|
||||
)
|
||||
|
||||
result = GeneralUtils.sendReceiveMqttMsg(outgoingMsg; timeout=120)
|
||||
response = result[:response]
|
||||
response = result["response"]
|
||||
|
||||
return (response[:text], response[:select], response[:reward], response[:isterminal])
|
||||
return (response["text"], response["select"], response["reward"], response["isterminal"])
|
||||
end
|
||||
|
||||
|
||||
@@ -171,26 +171,26 @@ function virtualWineUserChatbox(config::T1, input::T2, virtualCustomerChatHistor
|
||||
Let's begin!
|
||||
"""
|
||||
|
||||
pushfirst!(virtualCustomerChatHistory, Dict(:name=> "system", :text=> systemmsg))
|
||||
pushfirst!(virtualCustomerChatHistory, Dict("name"=> "system", "text"=> systemmsg))
|
||||
|
||||
# replace the :user key in chathistory to allow the virtual wine customer AI roleplay
|
||||
chathistory::Vector{Dict{String, Any}} = Vector{Dict{String, Any}}()
|
||||
for i in virtualCustomerChatHistory
|
||||
newdict = Dict()
|
||||
newdict[:name] =
|
||||
if i[:name] == "user"
|
||||
newdict["name"] =
|
||||
if i["name"] == "user"
|
||||
"you"
|
||||
elseif i[:name] == "assistant"
|
||||
elseif i["name"] == "assistant"
|
||||
"sommelier"
|
||||
else
|
||||
i[:name]
|
||||
i["name"]
|
||||
end
|
||||
|
||||
newdict[:text] = i[:text]
|
||||
newdict["text"] = i["text"]
|
||||
push!(chathistory, newdict)
|
||||
end
|
||||
|
||||
push!(chathistory, Dict(:name=> "assistant", :text=> input))
|
||||
push!(chathistory, Dict("name"=> "assistant", "text"=> input))
|
||||
|
||||
# put in model format
|
||||
prompt = formatLLMtext(chathistory, "llama3instruct")
|
||||
@@ -201,23 +201,23 @@ function virtualWineUserChatbox(config::T1, input::T2, virtualCustomerChatHistor
|
||||
"""
|
||||
|
||||
pprint(prompt)
|
||||
externalService = config[:externalservice][:text2textinstruct]
|
||||
externalService = config["externalservice"]["text2textinstruct"]
|
||||
|
||||
# send formatted input to user using GeneralUtils.sendReceiveMqttMsg
|
||||
msgMeta = GeneralUtils.generate_msgMeta(
|
||||
externalService[:mqtttopic],
|
||||
externalService["mqtttopic"],
|
||||
senderName= "virtualWineUserChatbox",
|
||||
senderId= string(uuid4()),
|
||||
receiverName= "text2textinstruct",
|
||||
mqttBroker= config[:mqttServerInfo][:broker],
|
||||
mqttBrokerPort= config[:mqttServerInfo][:port],
|
||||
mqttBroker= config["mqttServerInfo"]["broker"],
|
||||
mqttBrokerPort= config["mqttServerInfo"]["port"],
|
||||
msgId = string(uuid4()) #CHANGE remove after testing finished
|
||||
)
|
||||
|
||||
outgoingMsg = Dict(
|
||||
:msgMeta=> msgMeta,
|
||||
:payload=> Dict(
|
||||
:text=> prompt,
|
||||
"msgMeta"=> msgMeta,
|
||||
"payload"=> Dict(
|
||||
"text"=> prompt,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -225,7 +225,7 @@ function virtualWineUserChatbox(config::T1, input::T2, virtualCustomerChatHistor
|
||||
for attempt in 1:5
|
||||
try
|
||||
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg; timeout=120)
|
||||
_responseJsonStr = response[:response][:text]
|
||||
_responseJsonStr = response["response"]["text"]
|
||||
expectedJsonExample =
|
||||
"""
|
||||
Here is an expected JSON format:
|
||||
@@ -239,10 +239,10 @@ function virtualWineUserChatbox(config::T1, input::T2, virtualCustomerChatHistor
|
||||
responseJsonStr = jsoncorrection(config, _responseJsonStr, expectedJsonExample)
|
||||
responseDict = copy(JSON.parsefile(responseJsonStr))
|
||||
|
||||
text::AbstractString = responseDict[:text]
|
||||
select::Union{Nothing, Number} = responseDict[:select] == "null" ? nothing : responseDict[:select]
|
||||
reward::Number = responseDict[:reward]
|
||||
isterminal::Bool = responseDict[:isterminal]
|
||||
text::AbstractString = responseDict["text"]
|
||||
select::Union{Nothing, Number} = responseDict["select"] == "null" ? nothing : responseDict["select"]
|
||||
reward::Number = responseDict["reward"]
|
||||
isterminal::Bool = responseDict["isterminal"]
|
||||
|
||||
if text != ""
|
||||
# pass test
|
||||
@@ -455,8 +455,8 @@ function extractWineAttributes_1(a::T1, input::T2; maxattempt=10
|
||||
|
||||
unformatPrompt =
|
||||
[
|
||||
Dict(:name=> "system", :text=> systemmsg),
|
||||
Dict(:name=> "user", :text=> usermsg)
|
||||
Dict("name"=> "system", "text"=> systemmsg),
|
||||
Dict("name"=> "user", "text"=> usermsg)
|
||||
]
|
||||
|
||||
# put in model format
|
||||
@@ -544,21 +544,20 @@ function extractWineAttributes_1(a::T1, input::T2; maxattempt=10
|
||||
if j ∉ removekeys
|
||||
# in case j is wine_price it needs to be checked differently because its value is ranged
|
||||
if j == :wine_price
|
||||
if responsedict[:wine_price] != "N/A"
|
||||
# check whether wine_price is in ranged number
|
||||
if !occursin("to", responsedict[:wine_price])
|
||||
errornote = "In your previous attempt, the 'wine_price' was set to $(responsedict[:wine_price]) which is not a correct format. Please adjust it accordingly."
|
||||
if responsedict["wine_price"] != "N/A"
|
||||
if !occursin("to", responsedict["wine_price"])
|
||||
errornote = "In your previous attempt, the 'wine_price' was set to $(responsedict["wine_price"]) which is not a correct format. Please adjust it accordingly."
|
||||
println("\nERROR YiemAgent extractWineAttributes_1() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||
checkFlag = true
|
||||
break
|
||||
end
|
||||
|
||||
# # check whether max wine_price is in the input
|
||||
# pricerange = split(responsedict[:wine_price], '-')
|
||||
# pricerange = split(responsedict["wine_price"], '-')
|
||||
# minprice = pricerange[1]
|
||||
# maxprice = pricerange[end]
|
||||
# if !occursin(maxprice, input)
|
||||
# responsedict[:wine_price] = "N/A"
|
||||
# responsedict["wine_price"] = "N/A"
|
||||
# end
|
||||
# # price range like 100-100 is not good
|
||||
# if minprice == maxprice
|
||||
@@ -735,7 +734,7 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2<
|
||||
|
||||
unformatPrompt =
|
||||
[
|
||||
Dict(:name=> "system", :text=> systemmsg),
|
||||
Dict("name"=> "system", "text"=> systemmsg),
|
||||
]
|
||||
|
||||
# put in model format
|
||||
@@ -883,8 +882,8 @@ function paraphrase(text2textInstructLLM::Function, text::String)
|
||||
|
||||
_prompt =
|
||||
[
|
||||
Dict(:name => "system", :text => systemmsg),
|
||||
Dict(:name => "user", :text => usermsg)
|
||||
Dict("name" => "system", "text" => systemmsg),
|
||||
Dict("name" => "user", "text" => usermsg)
|
||||
]
|
||||
|
||||
# put in model format
|
||||
@@ -935,7 +934,7 @@ function paraphrase(text2textInstructLLM::Function, text::String)
|
||||
println("\nparaphrase() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||
pprintln(Dict(responsedict))
|
||||
|
||||
result = responsedict[:paraphrase]
|
||||
result = responsedict["paraphrase"]
|
||||
|
||||
return result
|
||||
catch e
|
||||
@@ -1004,10 +1003,10 @@ function jsoncorrection(config::T1, input::T2, correctJsonExample::T3;
|
||||
"""
|
||||
|
||||
# apply LLM specific instruct format
|
||||
externalService = config[:externalservice][:text2textinstruct]
|
||||
llminfo = externalService[:llminfo]
|
||||
externalService = config["externalservice"]["text2textinstruct"]
|
||||
llminfo = externalService["llminfo"]
|
||||
prompt =
|
||||
if llminfo[:name] == "llama3instruct"
|
||||
if llminfo["name"] == "llama3instruct"
|
||||
formatLLMtext_llama3instruct("system", _prompt)
|
||||
else
|
||||
error("llm model name is not defied yet $(@__LINE__)")
|
||||
@@ -1015,21 +1014,21 @@ function jsoncorrection(config::T1, input::T2, correctJsonExample::T3;
|
||||
|
||||
# send formatted input to user using GeneralUtils.sendReceiveMqttMsg
|
||||
msgMeta = GeneralUtils.generate_msgMeta(
|
||||
externalService[:mqtttopic],
|
||||
externalService["mqtttopic"],
|
||||
senderName= "jsoncorrection",
|
||||
senderId= string(uuid4()),
|
||||
receiverName= "text2textinstruct",
|
||||
mqttBroker= config[:mqttServerInfo][:broker],
|
||||
mqttBrokerPort= config[:mqttServerInfo][:port],
|
||||
mqttBroker= config["mqttServerInfo"]["broker"],
|
||||
mqttBrokerPort= config["mqttServerInfo"]["port"],
|
||||
)
|
||||
|
||||
outgoingMsg = Dict(
|
||||
:msgMeta=> msgMeta,
|
||||
:payload=> Dict(
|
||||
:text=> prompt,
|
||||
:kwargs=> Dict(
|
||||
:max_tokens=> 512,
|
||||
:stop=> ["<|eot_id|>"],
|
||||
"msgMeta"=> msgMeta,
|
||||
"payload"=> Dict(
|
||||
"text"=> prompt,
|
||||
"kwargs"=> Dict(
|
||||
"max_tokens"=> 512,
|
||||
"stop"=> ["<|eot_id|>"],
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user