This commit is contained in:
narawat lamaiin
2024-05-09 13:08:31 +07:00
parent 78d69194e9
commit a4e7dee5bf
2 changed files with 98 additions and 94 deletions

View File

@@ -185,40 +185,41 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
) )
attempt = 0 attempt = 0
while attempt <= 5 while true
attempt += 1 attempt += 1
try if attempt <= 5
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg) try
_responseJsonStr = response[:response][:text] response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
expectedJsonExample = _responseJsonStr = response[:response][:text]
""" expectedJsonExample =
Here is an expected JSON format: """
{ Here is an expected JSON format:
"thought": "...", {
"action": {"name": "...", "input": "..."}, "thought": "...",
"observation": "..." "action": {"name": "...", "input": "..."},
} "observation": "..."
""" }
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample) """
thoughtDict = copy(JSON3.read(responseJsonStr)) responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
thoughtDict = copy(JSON3.read(responseJsonStr))
# check if dict has all required value # check if dict has all required value
dummya::AbstractString = thoughtDict[:thought] dummya::AbstractString = thoughtDict[:thought]
dummyb::AbstractString = thoughtDict[:action][:name] dummyb::AbstractString = thoughtDict[:action][:name]
dummyc::AbstractString = thoughtDict[:action][:input] dummyc::AbstractString = thoughtDict[:action][:input]
return thoughtDict return thoughtDict
catch e catch e
io = IOBuffer() io = IOBuffer()
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("") println("")
@warn "Error occurred: $errorMsg\n$st" @warn "Error occurred: $errorMsg\n$st"
println("") println("")
end end
if attempt > 5 else
error("DecisionMaker failed to generate a thought") error("DecisionMaker failed to generate a thought")
end end
end end
@@ -315,35 +316,36 @@ function progressValueEstimator(a::T1, state::T2)::Tuple{String, Integer} where
) )
attempt = 0 attempt = 0
while attempt <= 5 while true
attempt += 1 attempt += 1
try if attempt <= 5
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg) try
_responseJsonStr = response[:response][:text] response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
expectedJsonExample = _responseJsonStr = response[:response][:text]
""" expectedJsonExample =
Here is an expected JSON format: """
{"evaluation": "...", "score": "..."} Here is an expected JSON format:
""" {"evaluation": "...", "score": "..."}
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample) """
evaluationDict = copy(JSON3.read(responseJsonStr)) responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
evaluationDict = copy(JSON3.read(responseJsonStr))
# check if dict has all required value # check if dict has all required value
dummya::AbstractString = evaluationDict[:evaluation] dummya::AbstractString = evaluationDict[:evaluation]
dummyb::Integer = evaluationDict[:score] dummyb::Integer = evaluationDict[:score]
return (evaluationDict[:evaluation], evaluationDict[:score]) return (evaluationDict[:evaluation], evaluationDict[:score])
catch e catch e
io = IOBuffer() io = IOBuffer()
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("") println("")
@warn "Error occurred: $errorMsg\n$st" @warn "Error occurred: $errorMsg\n$st"
println("") println("")
end end
if attempt > 5 else
error("progressValueEstimator failed to generate an evaluation") error("progressValueEstimator failed to generate an evaluation")
end end
end end
@@ -451,34 +453,35 @@ function reflector(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractDict}
) )
attempt = 0 attempt = 0
while attempt <= 5 while true
attempt += 1 attempt += 1
try if attempt <= 5
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg) try
_responseJsonStr = response[:response][:text] response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
expectedJsonExample = _responseJsonStr = response[:response][:text]
""" expectedJsonExample =
Here is an expected JSON format: """
{"reflection": "..."} Here is an expected JSON format:
""" {"reflection": "..."}
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample) """
reflectionDict = copy(JSON3.read(responseJsonStr)) responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
reflectionDict = copy(JSON3.read(responseJsonStr))
# check if dict has all required value # check if dict has all required value
dummya::AbstractString = reflectionDict[:reflection] dummya::AbstractString = reflectionDict[:reflection]
return reflectionDict[:reflection] return reflectionDict[:reflection]
catch e catch e
io = IOBuffer() io = IOBuffer()
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("") println("")
@warn "Error occurred: $errorMsg\n$st" @warn "Error occurred: $errorMsg\n$st"
println("") println("")
end end
if attempt > 5 else
error("reflector failed to generate a thought") error("reflector failed to generate a thought")
end end
end end

View File

@@ -164,24 +164,25 @@ function virtualWineCustomerChatbox(a::T1, input::T2
) )
attempt = 0 attempt = 0
while attempt <= 5 while true
attempt += 1 attempt += 1
try if attempt <= 5
result = GeneralUtils.sendReceiveMqttMsg(outgoingMsg; timeout=120) try
response = result[:response] result = GeneralUtils.sendReceiveMqttMsg(outgoingMsg; timeout=120)
response = result[:response]
return (response[:text], response[:select], response[:reward], response[:isterminal]) return (response[:text], response[:select], response[:reward], response[:isterminal])
catch e catch e
io = IOBuffer() io = IOBuffer()
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("") println("")
@warn "Error occurred: $errorMsg\n$st" @warn "Error occurred: $errorMsg\n$st"
println("") println("")
end end
if attempt > 5 else
error("virtualWineCustomerChatbox failed to get a response") error("virtualWineCustomerChatbox failed to get a response")
end end
end end