diff --git a/src/llmfunction.jl b/src/llmfunction.jl index 4227073..0cfbe34 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -381,7 +381,7 @@ julia> # TODO - [] update docstring - - [TESTING] implement the function + - [x] implement the function # Signature """ diff --git a/src/mcts.jl b/src/mcts.jl index ae027a3..a559700 100644 --- a/src/mcts.jl +++ b/src/mcts.jl @@ -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 diff --git a/src/type.jl b/src/type.jl index be0a9d3..a86130f 100644 --- a/src/type.jl +++ b/src/type.jl @@ -12,80 +12,76 @@ 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. - - 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 +# 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 + - `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 - tools::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 diff --git a/src/util.jl b/src/util.jl index 0c2aebf..80138c8 100644 --- a/src/util.jl +++ b/src/util.jl @@ -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