This commit is contained in:
narawat lamaiin
2024-05-04 21:17:02 +07:00
parent dea3f0260e
commit 8907156522
3 changed files with 28 additions and 24 deletions

View File

@@ -186,7 +186,7 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
_response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
_thoughtJsonStr = _response[:response][:text]
thoughtJsonStr = jsoncorrection(a, _thoughtJsonStr, "")
thoughtJsonStr = jsoncorrection(a, _thoughtJsonStr, responseformat)
thoughtDict = copy(JSON3.read(thoughtJsonStr))
pprint(thoughtDict)
return thoughtDict
@@ -324,11 +324,14 @@ function reflector()
end
"""
""" Determine whether the state is a terminal state
# Arguments
- `state::T`
a game state
# Return
- `(isterminal, reward)::Tuple{Bool, Number}`
# Example
```jldoctest
@@ -336,13 +339,19 @@ julia>
```
# TODO
- [] update docstring
- [] implement the function
- [x] update docstring
- [TESTING] implement the function
# Signature
"""
function isterminal()
function isterminal(state::T)::Tuple{Bool, Number} where {T<:AbstractDict}
latestObservationKey, _ = GeneralUtils.findHighestIndexKey(state[:thoughtHistory], "Observation")
latestObservation = state[:thoughtHistory][latestObservationKey]
# terminal condition is when the user select wine by putting <<winename>> in latest observation
if occursin("<<", latestObservation) && occursin(">>", latestObservation)
return true, 1
end
end
@@ -423,7 +432,6 @@ function conversation(a::T, userinput::Dict) where {T<:agent}
# deepcopy the info to prevent modifying the info unintentionally during MCTS planning
:customerinfo=> deepcopy(a.keywordinfo[:customerinfo]),
:storeinfo=> deepcopy(a.keywordinfo[:storeinfo]),
:thoughtHistory=> OrderedDict{Symbol, Any}( # contain question, thought_1, action_1, observation_1, thought_2, ...
:Question=> userinput[:text],
)