update
This commit is contained in:
@@ -118,7 +118,7 @@ function decisionMaker(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractD
|
||||
"Thought_2": "reasoning",
|
||||
...
|
||||
"Thought_n": "reasoning",
|
||||
"Action_1": {"action": "action to take", "input": "Action input"},
|
||||
"Action_1": {"name": "action to take", "input": "Action input"},
|
||||
"Observation_1": "result of the action"
|
||||
}
|
||||
|
||||
@@ -128,13 +128,13 @@ function decisionMaker(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractD
|
||||
"Thought_1": "I have many cars in my inventory suitable for several usage scenarios.",
|
||||
"Thought_2": "It would be better if I knew what the user intends to do with his car.",
|
||||
"Thought_3": "I will ask the user what is the intended usecase",
|
||||
"Action_1": {"action": "chatbox", "input": "What will you use it for?"}
|
||||
"Action_1": {"name": "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?"}
|
||||
"Action_1": {"name": "chatbox", "input": "Do you have any specific feature in mind?"}
|
||||
}
|
||||
|
||||
$reflect
|
||||
@@ -311,7 +311,7 @@ function conversation(a::T, userinput::Dict) where {T<:agent}
|
||||
:storeinfo=> deepcopy(a.keywordinfo[:storeinfo]),
|
||||
|
||||
:thoughtHistory=> Dict{Symbol, Any}( # contain question, thought_1, action_1, observation_1, thought_2, ...
|
||||
:question=> userinput[:text],
|
||||
:Question=> userinput[:text],
|
||||
)
|
||||
)
|
||||
bestplan = runMCTS(a, initialState, decisionMaker, stateValueEstimator, reflector,
|
||||
|
||||
62
src/mcts.jl
62
src/mcts.jl
@@ -131,15 +131,11 @@ function expand(a::T1, node::MCTSNode, state::T2, decisionMaker::Function, state
|
||||
)
|
||||
:Observation_1 => ""
|
||||
"""
|
||||
latestActionKey = GeneralUtils.findHighestIndexKey(thoughtDict, "Action")
|
||||
_action = thoughtDict[latestActionKey]
|
||||
action = _action[:action]
|
||||
actioninput = _action[:input]
|
||||
|
||||
newState = MCTStransition(a, node.state, action, actioninput) #[] Implement your transition function
|
||||
newstate = MCTStransition(a, node.state, thoughtDict) #[] Implement your transition function
|
||||
|
||||
if newState ∉ keys(node.children)
|
||||
node.children[newState] = MCTSNode(newState, 0, 0.0, Dict{T, MCTSNode}())
|
||||
if newstate ∉ keys(node.children)
|
||||
node.children[newstate] = MCTSNode(newstate, 0, 0.0, Dict{T, MCTSNode}())
|
||||
end
|
||||
end
|
||||
error("--> expand")
|
||||
@@ -212,41 +208,61 @@ end
|
||||
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
|
||||
- `thoughtDict::T2`
|
||||
contain Thought, Action, Observation
|
||||
|
||||
# Return
|
||||
- `newstate::AbstractDict`
|
||||
next game state
|
||||
|
||||
# Example
|
||||
```jldoctest
|
||||
julia>
|
||||
julia> thoughtDict = Dict(
|
||||
:Question=> "I want to buy a bottle of wine."
|
||||
:Thought_1=> "The customer wants to buy a bottle of wine. This is a good start!",
|
||||
:Action_1=> Dict{Symbol, Any}(
|
||||
:name=>"Chatbox",
|
||||
:input=>"What occasion are you buying the wine for?"
|
||||
),
|
||||
:Observation_1 => ""
|
||||
)
|
||||
```
|
||||
|
||||
# TODO
|
||||
- [] update docstring
|
||||
- [WORKING] implement the function
|
||||
- [x] update docstring
|
||||
- [TESTING] implement the function
|
||||
|
||||
# Signature
|
||||
"""
|
||||
function MCTStransition(a::T1, state::T2, action::T3,
|
||||
actioninput::T3) where {T1<:agent, T2<:AbstractDict, T3<:AbstractString}
|
||||
|
||||
function MCTStransition(a::T1, state::T2, thoughtDict::T2)::AbstractDict where {T1<:agent, T2<:AbstractDict}
|
||||
latestThoughtKey, latestindice = GeneralUtils.findHighestIndexKey(thoughtDict, "Thought")
|
||||
latestActionKey = GeneralUtils.findHighestIndexKey(thoughtDict, "Action")
|
||||
_action = thoughtDict[latestActionKey]
|
||||
actionname = _action[:name]
|
||||
actioninput = _action[:input]
|
||||
|
||||
# map action and input() to llm function
|
||||
result =
|
||||
if action == "chatbox"
|
||||
virtualWineCustomerChatbox(a, input) # user virtu
|
||||
elseif action == "winestock"
|
||||
response =
|
||||
if actionname == "chatbox"
|
||||
virtualWineCustomerChatbox(a, actioninput) # user virtu
|
||||
elseif actionname == "winestock"
|
||||
|
||||
elseif action == "finish"
|
||||
elseif actionname == "finish"
|
||||
|
||||
else
|
||||
|
||||
end
|
||||
error("--> transition")
|
||||
|
||||
# add Thought, action, observation to thoughtHistory
|
||||
newstate = deepcopy(state)
|
||||
newstate[:thoughtHistory][latestThoughtKey] = thoughtDict[latestThoughtKey]
|
||||
newstate[:thoughtHistory][latestActionKey] = thoughtDict[latestActionKey]
|
||||
latestObservationKey = Symbol("Observation_$(latestindice)")
|
||||
newstate[:thoughtHistory][latestObservationKey] = response
|
||||
|
||||
|
||||
error("--> transition")
|
||||
return newstate
|
||||
end
|
||||
|
||||
"""
|
||||
|
||||
16
src/util.jl
16
src/util.jl
@@ -11,17 +11,14 @@ using ..type
|
||||
|
||||
""" Clear agent chat history.
|
||||
|
||||
Arguments\n
|
||||
-----
|
||||
a::agent
|
||||
# Arguments
|
||||
- `a::agent`
|
||||
an agent
|
||||
|
||||
Return\n
|
||||
-----
|
||||
nothing
|
||||
# Return
|
||||
- nothing
|
||||
|
||||
Example\n
|
||||
-----
|
||||
# Example
|
||||
```jldoctest
|
||||
julia> using YiemAgent, MQTTClient, GeneralUtils
|
||||
julia> client, connection = MakeConnection("test.mosquitto.org", 1883)
|
||||
@@ -47,8 +44,7 @@ using ..type
|
||||
julia> YiemAgent.clearhistory(a)
|
||||
```
|
||||
|
||||
Signature\n
|
||||
-----
|
||||
# Signature
|
||||
"""
|
||||
function clearhistory(a::T) where {T<:agent}
|
||||
empty!(a.chathistory)
|
||||
|
||||
Reference in New Issue
Block a user