This commit is contained in:
2024-05-01 13:15:48 +07:00
parent 513f159be1
commit fba99ab695
3 changed files with 54 additions and 34 deletions

1
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1 @@
{}

View File

@@ -53,22 +53,30 @@ end
a game state a game state
# Return # Return
- `thought::Dict` - `thoughtDict::Dict`
# Example # Example
```jldoctest ```jldoctest
julia> julia> output_thoughtDict = Dict(
:Thought_1 => "The customer wants to buy a bottle of wine. This is a good start!",
:Action_1 => Dict{Symbol, Any}(
:action=>"Chatbox",
:input=>"What occasion are you buying the wine for?"
),
:Observation_1 => ""
)
``` ```
# TODO # TODO
[] update docstring [x] update docstring
[x] implement the function [x] implement the function
[] implement RAG to pull similar experience [] implement RAG to pull similar experience
[] use iterative prompting to ensure JSON format [] use customerinfo
[] user storeinfo
# Signature # Signature
""" """
function decisionMaker(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractDict} function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2<:AbstractDict}
customerinfo = customerinfo =
""" """
I will give you the following information about customer: I will give you the following information about customer:
@@ -161,8 +169,9 @@ function decisionMaker(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractD
) )
result = GeneralUtils.sendReceiveMqttMsg(outgoingMsg) result = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
thought = result[:response][:text] thoughtJsonStr = result[:response][:text]
return thought thoughtDict = copy(JSON3.read(thoughtJsonStr))
return thoughtDict
end end
@@ -365,12 +374,6 @@ end

View File

@@ -110,33 +110,26 @@ julia>
# Signature # Signature
""" """
function expand(a::T1, node::MCTSNode, state::T2, decisionMaker::Function, stateValueEstimator::Function; function expand(a::T1, node::MCTSNode, state::T2, decisionMaker::Function,
n::Integer=3) where {T1<:agent, T2<:AbstractDict} stateValueEstimator::Function; n::Integer=3) where {T1<:agent, T2<:AbstractDict}
# sampling action from decisionMaker # sampling action from decisionMaker
for sample in 1:n for sample in 1:n
thoughtJstr = decisionMaker(a, state) thoughtDict = decisionMaker(a, state)
thoughtDict = copy(JSON3.read(thoughtJstr))
""" Example of thoughtDict
Dict{Symbol, Any} with 3 entries:
:Thought_1 => "The customer wants to buy a bottle of wine. This is a good start!"
:Action_1 => Dict{Symbol, Any}(
:action=>"Chatbox",
:input=>"What occasion are you buying the wine for?"
)
:Observation_1 => ""
"""
@show state @show state
@show thoughtDict @show thoughtDict
newstate = MCTStransition(a, node.state, thoughtDict) #[] Implement your transition function newStatekey, newstate = MCTStransition(a, node.state, thoughtDict) #[] Implement your transition function
if newstate keys(node.children)# BUG should be "key of the newstate" here not newstate itself if newStatekey keys(node.children)# BUG should be "key of the newstate" here not newstate itself
statetype = typeof(state) statetype = typeof(state)
node.children[newStatekey] = MCTSNode(newstate, 0, 0.0, Dict{statetype, MCTSNode}())
# BUG should be node.children[key of newstate] here not newstate. may be a uuid
node.children[newstate] = MCTSNode(newstate, 0, 0.0, Dict{statetype, MCTSNode}())
end end
# add stateValueEstimator
end end
end end
@@ -235,6 +228,7 @@ julia> thoughtDict = Dict(
# TODO # TODO
- [] update docstring - [] update docstring
- [PENDING] add other actions - [PENDING] add other actions
- [] add embedding newstate then store in newstate[:embedding]
# Signature # Signature
""" """
@@ -265,7 +259,9 @@ function MCTStransition(a::T1, state::T2,
latestObservationKey = Symbol("Observation_$(latestActionIndice)") latestObservationKey = Symbol("Observation_$(latestActionIndice)")
newstate[:thoughtHistory][latestObservationKey] = response newstate[:thoughtHistory][latestObservationKey] = response
return newstate newStatekey = Symbol(GeneralUtils.uuid4snakecase())
return newStatekey, newstate
end end
@@ -402,4 +398,24 @@ end
end
end # module mcts