update
This commit is contained in:
108
src/interface.jl
108
src/interface.jl
@@ -176,8 +176,12 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
_response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
attempt = 0
|
||||||
_thoughtJsonStr = _response[:response][:text]
|
while attempt <= 5
|
||||||
|
attempt += 1
|
||||||
|
try
|
||||||
|
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
||||||
|
_responseJsonStr = response[:response][:text]
|
||||||
expectedJsonExample =
|
expectedJsonExample =
|
||||||
"""
|
"""
|
||||||
Here is an expected JSON format:
|
Here is an expected JSON format:
|
||||||
@@ -187,10 +191,29 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
|
|||||||
"observation": "..."
|
"observation": "..."
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
thoughtJsonStr = jsoncorrection(a, _thoughtJsonStr, expectedJsonExample)
|
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
|
||||||
thoughtDict = copy(JSON3.read(thoughtJsonStr))
|
thoughtDict = copy(JSON3.read(responseJsonStr))
|
||||||
|
|
||||||
|
# check if dict has all required value
|
||||||
|
dummya::AbstractString = thoughtDict[:thought]
|
||||||
|
dummyb::AbstractString = thoughtDict[:action][:name]
|
||||||
|
dummyc::AbstractString = thoughtDict[:action][:input]
|
||||||
|
|
||||||
return thoughtDict
|
return thoughtDict
|
||||||
|
catch e
|
||||||
|
io = IOBuffer()
|
||||||
|
showerror(io, e)
|
||||||
|
errorMsg = String(take!(io))
|
||||||
|
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||||
|
println("")
|
||||||
|
@warn "Error occurred: $errorMsg\n$st"
|
||||||
|
println("")
|
||||||
|
end
|
||||||
|
|
||||||
|
if attempt > 5
|
||||||
|
error("DecisionMaker failed to generate a thought")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -286,17 +309,39 @@ function progressValueEstimator(a::T1, state::T2)::Tuple{String, Integer} where
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
_response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
attempt = 0
|
||||||
_thoughtJsonStr = _response[:response][:text]
|
while attempt <= 5
|
||||||
|
attempt += 1
|
||||||
|
try
|
||||||
|
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
||||||
|
_responseJsonStr = response[:response][:text]
|
||||||
expectedJsonExample =
|
expectedJsonExample =
|
||||||
"""
|
"""
|
||||||
Here is an expected JSON format:
|
Here is an expected JSON format:
|
||||||
{"evaluation": "...", "score": "..."}
|
{"evaluation": "...", "score": "..."}
|
||||||
"""
|
"""
|
||||||
resultJsonStr = jsoncorrection(a, _thoughtJsonStr, expectedJsonExample)
|
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
|
||||||
resultDict = copy(JSON3.read(resultJsonStr))
|
evaluationDict = copy(JSON3.read(responseJsonStr))
|
||||||
|
|
||||||
return resultDict[:evaluation], resultDict[:score]
|
# check if dict has all required value
|
||||||
|
dummya::AbstractString = evaluationDict[:evaluation]
|
||||||
|
dummyb::AbstractString = evaluationDict[:score]
|
||||||
|
|
||||||
|
return (evaluationDict[:evaluation], evaluationDict[:score])
|
||||||
|
catch e
|
||||||
|
io = IOBuffer()
|
||||||
|
showerror(io, e)
|
||||||
|
errorMsg = String(take!(io))
|
||||||
|
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||||
|
println("")
|
||||||
|
@warn "Error occurred: $errorMsg\n$st"
|
||||||
|
println("")
|
||||||
|
end
|
||||||
|
|
||||||
|
if attempt > 5
|
||||||
|
error("progressValueEstimator failed to generate a thought")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -313,8 +358,8 @@ julia>
|
|||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- [] update docstring
|
- [] update docstring
|
||||||
- [WORKING] implement the function
|
- [x] implement the function
|
||||||
- [PENDING] add try block. check result that it is expected before returning
|
- [x] add try block. check result that it is expected before returning
|
||||||
|
|
||||||
# Signature
|
# Signature
|
||||||
"""
|
"""
|
||||||
@@ -400,21 +445,38 @@ function reflector(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractDict}
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
_response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
attempt = 0
|
||||||
_thoughtJsonStr = _response[:response][:text]
|
while attempt <= 5
|
||||||
|
attempt += 1
|
||||||
|
try
|
||||||
|
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
||||||
|
_responseJsonStr = response[:response][:text]
|
||||||
|
expectedJsonExample =
|
||||||
|
"""
|
||||||
|
Here is an expected JSON format:
|
||||||
|
{"reflection": "..."}
|
||||||
|
"""
|
||||||
|
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
|
||||||
|
reflectionDict = copy(JSON3.read(responseJsonStr))
|
||||||
|
|
||||||
# expectedJsonExample =
|
# check if dict has all required value
|
||||||
# """
|
dummya::AbstractString = reflectionDict[:reflection]
|
||||||
# Here is an expected JSON format:
|
|
||||||
# {"evaluation": "...", "score": "..."}
|
|
||||||
# """
|
|
||||||
# resultJsonStr = jsoncorrection(a, _thoughtJsonStr, expectedJsonExample)
|
|
||||||
# resultDict = copy(JSON3.read(resultJsonStr))
|
|
||||||
|
|
||||||
# return resultDict[:evaluation], resultDict[:score]
|
return reflectionDict[:reflection]
|
||||||
|
catch e
|
||||||
|
io = IOBuffer()
|
||||||
|
showerror(io, e)
|
||||||
|
errorMsg = String(take!(io))
|
||||||
|
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||||
|
println("")
|
||||||
|
@warn "Error occurred: $errorMsg\n$st"
|
||||||
|
println("")
|
||||||
|
end
|
||||||
|
|
||||||
|
if attempt > 5
|
||||||
return _thoughtJsonStr
|
error("reflector failed to generate a thought")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user