update
This commit is contained in:
@@ -381,7 +381,7 @@ julia>
|
|||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- [] update docstring
|
- [] update docstring
|
||||||
- [TESTING] implement the function
|
- [x] implement the function
|
||||||
|
|
||||||
# Signature
|
# Signature
|
||||||
"""
|
"""
|
||||||
|
|||||||
26
src/mcts.jl
26
src/mcts.jl
@@ -7,7 +7,7 @@ module mcts
|
|||||||
|
|
||||||
export MCTSNode, runMCTS, isleaf
|
export MCTSNode, runMCTS, isleaf
|
||||||
|
|
||||||
using Dates, UUIDs, DataStructures, JSON3, Random
|
using Dates, UUIDs, DataStructures, JSON3, Random, PrettyPrinting
|
||||||
using GeneralUtils
|
using GeneralUtils
|
||||||
using ..type, ..llmfunction
|
using ..type, ..llmfunction
|
||||||
|
|
||||||
@@ -211,13 +211,11 @@ end
|
|||||||
current game state
|
current game state
|
||||||
- `thoughtDict::T3`
|
- `thoughtDict::T3`
|
||||||
contain Thought, Action, Observation
|
contain Thought, Action, Observation
|
||||||
|
- `isterminal::Function`
|
||||||
|
a function to determine terminal state
|
||||||
|
|
||||||
# Return
|
# Return
|
||||||
- (newNodeKey, )
|
- `(newNodeKey, newstate, isterminalstate, reward)::Tuple{String, Dict{Symbol, <:Any}, Bool, <:Number}`
|
||||||
- `newNodeKey::String`
|
|
||||||
key for newstate
|
|
||||||
- `newstate::Dict{Symbol, Any}`
|
|
||||||
next game state
|
|
||||||
|
|
||||||
# Example
|
# Example
|
||||||
```jldoctest
|
```jldoctest
|
||||||
@@ -238,16 +236,14 @@ julia> thoughtDict = Dict(
|
|||||||
```
|
```
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- [WORKING] update docstring
|
|
||||||
- [PENDING] add other actions
|
- [PENDING] add other actions
|
||||||
- [] add embedding of newstate and store in newstate[:embedding]
|
- [] add embedding of newstate and store in newstate[:embedding]
|
||||||
- [x] check for terminal state and assign reward
|
|
||||||
|
|
||||||
# Signature
|
# Signature
|
||||||
"""
|
"""
|
||||||
function MCTStransition(a::T1, state::T2, thoughtDict::T3, isterminal::Function
|
function MCTStransition(a::T1, state::T2, thoughtDict::T3, isterminal::Function
|
||||||
)::Tuple{String, Dict{Symbol, <:Any}, Bool, <:Number} where {T1<:agent, T2<:AbstractDict, T3<:AbstractDict}
|
)::Tuple{String, Dict{Symbol, <:Any}, Bool, <:Number} where {T1<:agent, T2<:AbstractDict, T3<:AbstractDict}
|
||||||
|
pprint(thoughtDict)
|
||||||
actionname = thoughtDict[:Action][:name]
|
actionname = thoughtDict[:Action][:name]
|
||||||
actioninput = thoughtDict[:Action][:input]
|
actioninput = thoughtDict[:Action][:input]
|
||||||
|
|
||||||
@@ -279,7 +275,7 @@ function MCTStransition(a::T1, state::T2, thoughtDict::T3, isterminal::Function
|
|||||||
newNodeKey = GeneralUtils.uuid4snakecase()
|
newNodeKey = GeneralUtils.uuid4snakecase()
|
||||||
isterminalstate, reward = isterminal(newstate)
|
isterminalstate, reward = isterminal(newstate)
|
||||||
|
|
||||||
return newNodeKey, newstate, isterminalstate, reward
|
return (newNodeKey, newstate, isterminalstate, reward)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -317,21 +313,21 @@ isleaf(node::MCTSNode)::Bool = isempty(node.children)
|
|||||||
""" Select child node based on the highest progressValue
|
""" Select child node based on the highest progressValue
|
||||||
|
|
||||||
# Arguments
|
# Arguments
|
||||||
|
- `node::MCTSNode`
|
||||||
|
node of a search tree
|
||||||
|
|
||||||
# Return
|
# Return
|
||||||
|
- `childNode::MCTSNode`
|
||||||
|
the highest value child node
|
||||||
|
|
||||||
# Example
|
# Example
|
||||||
```jldoctest
|
```jldoctest
|
||||||
julia>
|
julia>
|
||||||
```
|
```
|
||||||
|
|
||||||
# TODO
|
|
||||||
- [WORKING] update docstring
|
|
||||||
- [x] implement the function
|
|
||||||
|
|
||||||
# Signature
|
# Signature
|
||||||
"""
|
"""
|
||||||
function selectChildNode(node::MCTSNode)
|
function selectChildNode(node::MCTSNode)::MCTSNode
|
||||||
highestProgressValue = 0
|
highestProgressValue = 0
|
||||||
nodekey = nothing
|
nodekey = nothing
|
||||||
|
|
||||||
|
|||||||
38
src/type.jl
38
src/type.jl
@@ -12,31 +12,28 @@ abstract type agent end
|
|||||||
|
|
||||||
""" A sommelier agent.
|
""" A sommelier agent.
|
||||||
|
|
||||||
Arguments\n
|
# Arguments
|
||||||
-----
|
- `mqttClient::Client`
|
||||||
mqttClient::Client
|
|
||||||
MQTTClient's client
|
MQTTClient's client
|
||||||
msgMeta::Dict{Symbol, Any}
|
- `msgMeta::Dict{Symbol, Any}`
|
||||||
A dict contain info about a message.
|
A dict contain info about a message.
|
||||||
config::Dict{Symbol, Any}
|
- `config::Dict{Symbol, Any}`
|
||||||
Config info for an agent. Contain mqtt topic for internal use and other info.
|
Config info for an agent. Contain mqtt topic for internal use and other info.
|
||||||
|
|
||||||
Keyword Arguments\n
|
# Keyword Arguments
|
||||||
-----
|
- `name::String`
|
||||||
name::String
|
|
||||||
Agent's name
|
Agent's name
|
||||||
id::String
|
- `id::String`
|
||||||
Agent's ID
|
Agent's ID
|
||||||
tools::Dict{Symbol, Any}
|
- `tools::Dict{Symbol, Any}`
|
||||||
Agent's tools
|
Agent's tools
|
||||||
maxHistoryMsg::Integer
|
- `maxHistoryMsg::Integer`
|
||||||
max history message
|
max history message
|
||||||
|
|
||||||
Return\n
|
# Return
|
||||||
-----
|
- `nothing`
|
||||||
nothing
|
|
||||||
|
|
||||||
Example:
|
# Example
|
||||||
```jldoctest
|
```jldoctest
|
||||||
julia> using YiemAgent, MQTTClient, GeneralUtils
|
julia> using YiemAgent, MQTTClient, GeneralUtils
|
||||||
julia> msgMeta = GeneralUtils.generate_msgMeta(
|
julia> msgMeta = GeneralUtils.generate_msgMeta(
|
||||||
@@ -75,16 +72,15 @@ abstract type agent end
|
|||||||
```
|
```
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- [WORKING] update docstring
|
- [] update docstring
|
||||||
- [x] implement the function
|
- [x] implement the function
|
||||||
|
|
||||||
Signature\n
|
# Signature
|
||||||
-----
|
|
||||||
"""
|
"""
|
||||||
@kwdef mutable struct sommelier <: agent
|
@kwdef mutable struct sommelier <: agent
|
||||||
name::String
|
name::String # agent name
|
||||||
id::String
|
id::String # agent id
|
||||||
config::Dict
|
config::Dict # agent config
|
||||||
tools::Dict
|
tools::Dict
|
||||||
thinkinglimit::Integer # thinking round limit
|
thinkinglimit::Integer # thinking round limit
|
||||||
thinkingcount::Integer # used to count attempted round of a task
|
thinkingcount::Integer # used to count attempted round of a task
|
||||||
|
|||||||
44
src/util.jl
44
src/util.jl
@@ -1,6 +1,6 @@
|
|||||||
module util
|
module util
|
||||||
|
|
||||||
export clearhistory, addNewMessage, formatLLMtext, syntaxcheck_json, iterativeprompting,
|
export clearhistory, addNewMessage, formatLLMtext, iterativeprompting,
|
||||||
formatLLMtext_llama3instruct, formatLLMtext_phi3instruct
|
formatLLMtext_llama3instruct, formatLLMtext_phi3instruct
|
||||||
|
|
||||||
using UUIDs, Dates, DataStructures, HTTP, MQTTClient, JSON3
|
using UUIDs, Dates, DataStructures, HTTP, MQTTClient, JSON3
|
||||||
@@ -269,48 +269,6 @@ function formatLLMtext(messages::Vector{Dict{Symbol, T}},
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
""" Check JSON format correctness and provide feedback
|
|
||||||
|
|
||||||
Arguments\n
|
|
||||||
-----
|
|
||||||
jsonstring::T
|
|
||||||
|
|
||||||
Return\n
|
|
||||||
-----
|
|
||||||
(correct, critique)
|
|
||||||
|
|
||||||
Example\n
|
|
||||||
-----
|
|
||||||
```jldoctest
|
|
||||||
julia>
|
|
||||||
```
|
|
||||||
|
|
||||||
TODO\n
|
|
||||||
-----
|
|
||||||
[] update docstring
|
|
||||||
[PENDING] implement the function
|
|
||||||
|
|
||||||
Signature\n
|
|
||||||
-----
|
|
||||||
"""
|
|
||||||
function syntaxcheck_json(jsonstring::T)::NamedTuple where {T<:AbstractString}
|
|
||||||
error("--> syntaxcheck_json")
|
|
||||||
success, result, errormsg, st = GeneralUtils.showstracktrace(JSON3.read, jsonstring)
|
|
||||||
if !success # gives feedback
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
return (success, critique)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Arguments\n
|
Arguments\n
|
||||||
|
|||||||
Reference in New Issue
Block a user