From 3316ec4ecf357151041ca44af4f62b3527001226 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Mon, 29 Apr 2024 20:55:02 +0700 Subject: [PATCH] update --- src/interface.jl | 8 ++--- src/llmfunction.jl | 79 ++++++++++++++++++++++++++++++++++++++++++++-- src/mcts.jl | 6 ++-- test/runtest.jl | 2 +- 4 files changed, 84 insertions(+), 11 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index e2b648a..47173bf 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -47,13 +47,13 @@ end """ Think and choose action # Arguments - `a::T1` + - `a::T1` one of Yiem's agent - `state::T2` + - `state::T2` a game state # Return - `thought::Dict` + - `thought::Dict` # Example ```jldoctest @@ -145,7 +145,7 @@ function decisionMaker(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractD prompt = formatLLMtext_llama3instruct("system", _prompt) msgMeta = GeneralUtils.generate_msgMeta( - a.config[:externalService][:text2textinstruct][:mqtttopic], + a.config[:externalservice][:text2textinstruct][:mqtttopic], senderName= "decisionMaker", senderId= a.id, receiverName= "text2textinstruct", diff --git a/src/llmfunction.jl b/src/llmfunction.jl index 03baaa6..2ba2954 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -21,17 +21,90 @@ julia> # TODO - [] update docstring - - [WORKING] implement the function + - [PENDING] implement the function # Signature """ function chatbox(a::T1, input::T2) where {T1<:agent, T2<:AbstractString} error("--> chatbox") + # put in model format - if a.config[:externalService][] - GeneralUtils.formatLLMtext_llama3instruct + virtualWineCustomer = a.config[:externalservice][:virtualWineCustomer_1] + llminfo = virtualWineCustomer[:llminfo] + formattedinput = + if llminfo[:name] == "llama3instruct" + formatLLMtext_llama3instruct("assistant", input) + else + error("llm model name is not defied yet $(@__LINE__)") + end + + # send formatted input to user using GeneralUtils.sendReceiveMqttMsg + + + # return response + end + + +""" Chatbox for chatting with virtual wine customer. + +# Arguments + - `a::T1` + one of Yiem's agent + - `input::T2` + text to be send to virtual wine customer + +# Return + - `response::String` + response of virtual wine customer +# Example +```jldoctest +julia> +``` + +# TODO + - [x] update docstring + - [TESTING] implement the function + +# Signature +""" +function virtualWineCustomerChatbox(a::T1, input::T2)::String where {T1<:agent, T2<:AbstractString} + + # put in model format + virtualWineCustomer = a.config[:externalservice][:virtualWineCustomer_1] + llminfo = virtualWineCustomer[:llminfo] + prompt = + if llminfo[:name] == "llama3instruct" + formatLLMtext_llama3instruct("assistant", input) + else + error("llm model name is not defied yet $(@__LINE__)") + end + + # send formatted input to user using GeneralUtils.sendReceiveMqttMsg + msgMeta = GeneralUtils.generate_msgMeta( + virtualWineCustomer[:mqtttopic], + senderName= "virtualWineCustomerChatbox", + senderId= a.id, + receiverName= "virtualWineCustomer", + mqttBroker= a.config[:mqttServerInfo][:broker], + mqttBrokerPort= a.config[:mqttServerInfo][:port], + ) + + outgoingMsg = Dict( + :msgMeta=> msgMeta, + :payload=> Dict( + :text=> prompt, + ) + ) + + result = GeneralUtils.sendReceiveMqttMsg(outgoingMsg) + response = result[:response][:text] + + return response +end + + """ Search wine in stock. Arguments\n diff --git a/src/mcts.jl b/src/mcts.jl index 013de73..a4a82e1 100644 --- a/src/mcts.jl +++ b/src/mcts.jl @@ -136,7 +136,7 @@ function expand(a::T1, node::MCTSNode, state::T2, decisionMaker::Function, state action = _action[:action] actioninput = _action[:input] - newState = transition(a, node.state, action, actioninput) #[] Implement your transition function + newState = MCTStransition(a, node.state, action, actioninput) #[] Implement your transition function if newState ∉ keys(node.children) node.children[newState] = MCTSNode(newState, 0, 0.0, Dict{T, MCTSNode}()) @@ -230,14 +230,14 @@ julia> # Signature """ -function transition(a::T1, state::T2, action::T3, +function MCTStransition(a::T1, state::T2, action::T3, actioninput::T3) where {T1<:agent, T2<:AbstractDict, T3<:AbstractString} # map action and input() to llm function result = if action == "chatbox" - chatbox(a, input) + virtualWineCustomerChatbox(a, input) # user virtu elseif action == "winestock" elseif action == "finish" diff --git a/test/runtest.jl b/test/runtest.jl index 9928e9e..7f05ab4 100644 --- a/test/runtest.jl +++ b/test/runtest.jl @@ -25,7 +25,7 @@ agentConfig = Dict( :prompt=> config[:servicetopic][:mqtttopic], # topic to receive prompt i.e. frontend send msg to this topic :internal=> instanceInternalTopic, ), - :externalService=> config[:externalService], + :externalservice=> config[:externalservice], ) # Instantiate an agent