This commit is contained in:
narawat lamaiin
2024-04-28 15:58:02 +07:00
parent b33ddca2a1
commit 0c39c507f5
2 changed files with 41 additions and 12 deletions

View File

@@ -107,17 +107,23 @@ function decisionMaker(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractD
"Thought_2": "reasoning", "Thought_2": "reasoning",
... ...
"Thought_n": "reasoning", "Thought_n": "reasoning",
"Action_1": "action to take", "Action_1": {"action": "action to take", "input": "Action input"},
"Observation_1": "result of the action" "Observation_1": "result of the action"
} }
Here are some examples: Here are some examples:
{ {
"Question": "I would like to buy a sedan", "Question": "I would like to buy a sedan.",
"Thought_1": "I have many car in my inventory suitable for several usage scenarios", "Thought_1": "I have many cars in my inventory suitable for several usage scenarios.",
"Thought_2": "It would be better if I know what the user intend to do with his car", "Thought_2": "It would be better if I knew what the user intends to do with his car."1,
"Thought_3": "I will ask the user what is the intended usecase", "Thought_3": "I will ask the user what is the intended usecase",
"Action_1": "Chatbox[What will you use it for?]" "Action_1": {"action": "Chatbox", "input": "What will you use it for?"}
}
{
"Question": "I'm looking for a sedan.",
"Thought_1": "I have many types of sedans in my inventory, each with diverse features.",
"Thought_2": "It would be easier to make a recommendation if I knew what feature the user is looking for. I should ask the user.",
"Action_1": {"action": "Chatbox", "input": "Do you have any specific feature in mind?"}
} }
$reflect $reflect
@@ -307,7 +313,7 @@ function conversation(a::T, userinput::Dict) where {T<:agent}
else #[WORKING] new thinking else #[PENDING] new thinking
initialState = Dict( initialState = Dict(
# deepcopy the info to prevent modifying the info unintentionally during MCTS planning # deepcopy the info to prevent modifying the info unintentionally during MCTS planning

View File

@@ -121,15 +121,28 @@ function expand(a::T1, node::MCTSNode, state::T2, decisionMaker::Function, state
for sample in 1:n for sample in 1:n
thoughtJstr = decisionMaker(a, state) thoughtJstr = decisionMaker(a, state)
thoughtDict = copy(JSON3.read(thoughtJstr)) thoughtDict = copy(JSON3.read(thoughtJstr))
latestActionKey = GeneralUtils.findHighestIndexKey(thoughtDict, "Action")
error("--> expand") """ Example of thoughtDict
newState = transition(node.state, action) #[] Implement your transition function 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 => ""
"""
latestActionKey = GeneralUtils.findHighestIndexKey(thoughtDict, "Action")
_action = thoughtDict[latestActionKey]
action = _action[:action]
actioninput = _action[:input]
newState = transition(a, node.state, action, actioninput) #[] Implement your transition function
if newState keys(node.children) if newState keys(node.children)
node.children[newState] = MCTSNode(newState, 0, 0.0, Dict{T, MCTSNode}()) node.children[newState] = MCTSNode(newState, 0, 0.0, Dict{T, MCTSNode}())
end end
end end
error("--> expand")
end end
""" """
@@ -192,9 +205,17 @@ function backpropagate(node::MCTSNode, reward::Float64)
end end
end end
""" """ Get a new state
# Arguments # Arguments
- `a::T1`
one of YiemAgent's agent
- `state::T2`
current game state
- `action::String`
name of LLM's function to be used
- `actioninput::String`
input to LLM function
# Return # Return
@@ -205,12 +226,14 @@ julia>
# TODO # TODO
- [] update docstring - [] update docstring
- [] implement the function - [WORKING] implement the function
# Signature # Signature
""" """
function transition(state, action) function transition(a::T1, state::T2, action::T3,
actioninput::T3) where {T1<:agent, T2<:AbstractDict, T3<:AbstractString}
error("--> transition")
end end
""" """