This commit is contained in:
narawat lamaiin
2024-05-05 12:06:32 +07:00
parent 1ac2ad1801
commit 77b590c6ad
4 changed files with 78 additions and 128 deletions

View File

@@ -381,7 +381,7 @@ julia>
# TODO
- [] update docstring
- [TESTING] implement the function
- [x] implement the function
# Signature
"""

View File

@@ -7,7 +7,7 @@ module mcts
export MCTSNode, runMCTS, isleaf
using Dates, UUIDs, DataStructures, JSON3, Random
using Dates, UUIDs, DataStructures, JSON3, Random, PrettyPrinting
using GeneralUtils
using ..type, ..llmfunction
@@ -211,13 +211,11 @@ end
current game state
- `thoughtDict::T3`
contain Thought, Action, Observation
- `isterminal::Function`
a function to determine terminal state
# Return
- (newNodeKey, )
- `newNodeKey::String`
key for newstate
- `newstate::Dict{Symbol, Any}`
next game state
- `(newNodeKey, newstate, isterminalstate, reward)::Tuple{String, Dict{Symbol, <:Any}, Bool, <:Number}`
# Example
```jldoctest
@@ -238,16 +236,14 @@ julia> thoughtDict = Dict(
```
# TODO
- [WORKING] update docstring
- [PENDING] add other actions
- [] add embedding of newstate and store in newstate[:embedding]
- [x] check for terminal state and assign reward
# Signature
"""
function MCTStransition(a::T1, state::T2, thoughtDict::T3, isterminal::Function
)::Tuple{String, Dict{Symbol, <:Any}, Bool, <:Number} where {T1<:agent, T2<:AbstractDict, T3<:AbstractDict}
pprint(thoughtDict)
actionname = thoughtDict[:Action][:name]
actioninput = thoughtDict[:Action][:input]
@@ -279,7 +275,7 @@ function MCTStransition(a::T1, state::T2, thoughtDict::T3, isterminal::Function
newNodeKey = GeneralUtils.uuid4snakecase()
isterminalstate, reward = isterminal(newstate)
return newNodeKey, newstate, isterminalstate, reward
return (newNodeKey, newstate, isterminalstate, reward)
end
@@ -317,21 +313,21 @@ isleaf(node::MCTSNode)::Bool = isempty(node.children)
""" Select child node based on the highest progressValue
# Arguments
- `node::MCTSNode`
node of a search tree
# Return
- `childNode::MCTSNode`
the highest value child node
# Example
```jldoctest
julia>
```
# TODO
- [WORKING] update docstring
- [x] implement the function
# Signature
"""
function selectChildNode(node::MCTSNode)
function selectChildNode(node::MCTSNode)::MCTSNode
highestProgressValue = 0
nodekey = nothing

View File

@@ -12,79 +12,75 @@ abstract type agent end
""" A sommelier agent.
Arguments\n
-----
mqttClient::Client
MQTTClient's client
msgMeta::Dict{Symbol, Any}
A dict contain info about a message.
config::Dict{Symbol, Any}
Config info for an agent. Contain mqtt topic for internal use and other info.
# Arguments
- `mqttClient::Client`
MQTTClient's client
- `msgMeta::Dict{Symbol, Any}`
A dict contain info about a message.
- `config::Dict{Symbol, Any}`
Config info for an agent. Contain mqtt topic for internal use and other info.
Keyword Arguments\n
-----
name::String
Agent's name
id::String
Agent's ID
tools::Dict{Symbol, Any}
Agent's tools
maxHistoryMsg::Integer
max history message
# Keyword Arguments
- `name::String`
Agent's name
- `id::String`
Agent's ID
- `tools::Dict{Symbol, Any}`
Agent's tools
- `maxHistoryMsg::Integer`
max history message
Return\n
-----
nothing
# Return
- `nothing`
Example:
```jldoctest
julia> using YiemAgent, MQTTClient, GeneralUtils
julia> msgMeta = GeneralUtils.generate_msgMeta(
"N/A",
replyTopic = "/testtopic/prompt"
)
julia> tools= Dict(
:chatbox=>Dict(
:name => "chatbox",
:description => "Useful only for when you need to ask the user for more info or context. Do not ask the user their own question.",
:input => "Input should be a text.",
:output => "" ,
:func => nothing,
),
)
julia> agentConfig = Dict(
:receiveprompt=>Dict(
:mqtttopic=> "/testtopic/prompt", # topic to receive prompt i.e. frontend send msg to this topic
),
:receiveinternal=>Dict(
:mqtttopic=> "/testtopic/internal", # receive topic for model's internal
),
:text2text=>Dict(
:mqtttopic=> "/text2text/receive",
),
)
julia> client, connection = MakeConnection("test.mosquitto.org", 1883)
julia> agent = YiemAgent.bsommelier(
client,
msgMeta,
agentConfig,
name= "assistant",
id= "555", # agent instance id
tools=tools,
)
```
# Example
```jldoctest
julia> using YiemAgent, MQTTClient, GeneralUtils
julia> msgMeta = GeneralUtils.generate_msgMeta(
"N/A",
replyTopic = "/testtopic/prompt"
)
julia> tools= Dict(
:chatbox=>Dict(
:name => "chatbox",
:description => "Useful only for when you need to ask the user for more info or context. Do not ask the user their own question.",
:input => "Input should be a text.",
:output => "" ,
:func => nothing,
),
)
julia> agentConfig = Dict(
:receiveprompt=>Dict(
:mqtttopic=> "/testtopic/prompt", # topic to receive prompt i.e. frontend send msg to this topic
),
:receiveinternal=>Dict(
:mqtttopic=> "/testtopic/internal", # receive topic for model's internal
),
:text2text=>Dict(
:mqtttopic=> "/text2text/receive",
),
)
julia> client, connection = MakeConnection("test.mosquitto.org", 1883)
julia> agent = YiemAgent.bsommelier(
client,
msgMeta,
agentConfig,
name= "assistant",
id= "555", # agent instance id
tools=tools,
)
```
# TODO
- [WORKING] update docstring
- [x] implement the function
# TODO
- [] update docstring
- [x] implement the function
Signature\n
-----
# Signature
"""
@kwdef mutable struct sommelier <: agent
name::String
id::String
config::Dict
name::String # agent name
id::String # agent id
config::Dict # agent config
tools::Dict
thinkinglimit::Integer # thinking round limit
thinkingcount::Integer # used to count attempted round of a task

View File

@@ -1,6 +1,6 @@
module util
export clearhistory, addNewMessage, formatLLMtext, syntaxcheck_json, iterativeprompting,
export clearhistory, addNewMessage, formatLLMtext, iterativeprompting,
formatLLMtext_llama3instruct, formatLLMtext_phi3instruct
using UUIDs, Dates, DataStructures, HTTP, MQTTClient, JSON3
@@ -269,48 +269,6 @@ function formatLLMtext(messages::Vector{Dict{Symbol, T}},
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