update
This commit is contained in:
@@ -109,8 +109,8 @@ function conversation(a::T, userinput::Dict) where {T<:agent}
|
||||
|
||||
else #[WORKING] new thinking
|
||||
initialState = Dict(
|
||||
:info=> Dict(), # keyword info
|
||||
:thoughtHistory=> Dict( # contain question, thought_1, action_1, observation_1, thought_2, ...
|
||||
:info=> Dict{Symbol, Any}(), # keyword info
|
||||
:thoughtHistory=> Dict{Symbol, Any}( # contain question, thought_1, action_1, observation_1, thought_2, ...
|
||||
:question=> userinput[:text],
|
||||
)
|
||||
)
|
||||
@@ -125,71 +125,6 @@ end
|
||||
|
||||
|
||||
|
||||
# function conversation(a::T) where {T<:agent}
|
||||
# """
|
||||
# [] update document
|
||||
# [x] MCTS() for planning
|
||||
# """
|
||||
# while true
|
||||
# # check for incoming user message
|
||||
# if isready(a.receiveUserMsgChannel)
|
||||
# incomingMsg = take!(a.receiveUserMsgChannel)
|
||||
# incomingPayload = incomingMsg[:payload]
|
||||
# @show incomingMsg
|
||||
|
||||
# # "newtopic" command to delete chat history
|
||||
# if incomingPayload[:text] == "newtopic"
|
||||
# clearhistory(a)
|
||||
# msgMeta = deepcopy(a.msgMeta)
|
||||
# msgMeta[:sendTopic] = incomingMsg[:msgMeta][:replyTopic]
|
||||
# msgMeta[:senderName] = "agent-backend"
|
||||
# msgMeta[:senderId] = a.id
|
||||
# msgMeta[:receiverName] = "agent-frontend"
|
||||
# msgMeta[:receiverId] = incomingMsg[:msgMeta][:senderId]
|
||||
# msgMeta[:replyTopic] = a.config[:receivemsg][:prompt]
|
||||
# msgMeta[:msgId] = string(uuid4())
|
||||
# msgMeta[:replyToMsgId] = incomingMsg[:msgMeta][:msgId]
|
||||
|
||||
# outgoingMsg = Dict(
|
||||
# :msgMeta=> msgMeta,
|
||||
# :payload=> Dict(
|
||||
# :name=> a.name, # will be shown in frontend as agent name
|
||||
# :text => "Okay. What shall we talk about?",
|
||||
# )
|
||||
# )
|
||||
# # _ = GeneralUtils.sendMqttMsg(outgoingMsg)
|
||||
|
||||
# else
|
||||
# @show a = 55555
|
||||
# # add usermsg to a.chathistory
|
||||
# addNewMessage(a, "user", usermsg)
|
||||
|
||||
# #[] if the last used tool is a chatbox
|
||||
# if a.plan[:currenttrajectory][end][:action] == "chatbox"
|
||||
# #usermsg -> observation and continue actor loop as planned
|
||||
|
||||
|
||||
|
||||
# else #[WORKING] new thinking
|
||||
|
||||
|
||||
# initialState = 0
|
||||
# bestplan = runMCTS(initialState, decisionMaker, stateValueEstimator, reflector,
|
||||
# 3, 10, 1000, 1.0)
|
||||
|
||||
# # actor loop(best plan)
|
||||
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# sleep(1)
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
10
src/mcts.jl
10
src/mcts.jl
@@ -52,7 +52,7 @@ using GeneralUtils
|
||||
Signature\n
|
||||
-----
|
||||
"""
|
||||
struct MCTSNode{T}
|
||||
struct MCTSNode{T<:AbstractDict}
|
||||
state::T
|
||||
visits::Integer
|
||||
stateValue::AbstractFloat
|
||||
@@ -129,7 +129,7 @@ end
|
||||
-----
|
||||
"""
|
||||
function expand(node::MCTSNode, state::T, decisionMaker::Function, stateValueEstimator::Function;
|
||||
n::Integer=3) where {T<:Any}
|
||||
n::Integer=3) where {T<:AbstractDict}
|
||||
|
||||
# sampling action from decisionMaker
|
||||
for sample in 1:n
|
||||
@@ -164,7 +164,7 @@ end
|
||||
Signature\n
|
||||
-----
|
||||
"""
|
||||
function simulate(state::T, max_depth::Int) where {T<:Any}
|
||||
function simulate(state::T, max_depth::Int) where {T<:AbstractDict}
|
||||
total_reward = 0.0
|
||||
for _ in 1:max_depth
|
||||
#[] Implement your action selection function based on highest stateValue
|
||||
@@ -264,7 +264,7 @@ end
|
||||
"""
|
||||
isLeaf(node::MCTSNode)::Bool = isempty(node.children)
|
||||
|
||||
"""
|
||||
""" Think and choose action
|
||||
|
||||
Arguments\n
|
||||
-----
|
||||
@@ -287,7 +287,7 @@ isLeaf(node::MCTSNode)::Bool = isempty(node.children)
|
||||
Signature\n
|
||||
-----
|
||||
"""
|
||||
function decisionMaker()
|
||||
function decisionMaker(state::T) where {T<:AbstractDict}
|
||||
|
||||
end
|
||||
|
||||
|
||||
24
src/util.jl
24
src/util.jl
@@ -117,7 +117,20 @@ function addNewMessage(a::T1, name::String, text::T2;
|
||||
end
|
||||
|
||||
|
||||
""" Convert a chat dictionary into LLM model instruct format.
|
||||
""" Convert a single chat dictionary into LLM model instruct format.
|
||||
|
||||
Llama 3 instruct format example\n
|
||||
-----
|
||||
<|begin_of_text|>
|
||||
<|start_header_id|>system<|end_header_id|>
|
||||
You are a helpful assistant.
|
||||
<|eot_id|>
|
||||
<|start_header_id|>user<|end_header_id|>
|
||||
Get me an icecream.
|
||||
<|eot_id|>
|
||||
<|start_header_id|>assistant<|end_header_id|>
|
||||
Go buy it yourself at 7-11.
|
||||
<|eot_id|>
|
||||
|
||||
Arguments\n
|
||||
-----
|
||||
@@ -134,8 +147,10 @@ end
|
||||
-----
|
||||
```jldoctest
|
||||
julia> using Revise
|
||||
julia> using YiemAgent
|
||||
julia> d = Dict(:name=> "system",:text=> "You are a helpful, respectful and honest assistant.",)
|
||||
julia> formattedtext = formatLLMtext_llama3instruct(d[:name], d[:text])
|
||||
julia> formattedtext = YiemAgent.formatLLMtext_llama3instruct(d[:name], d[:text])
|
||||
"<|begin_of_text|>\n <|start_header_id|>system<|end_header_id|>\n You are a helpful, respectful and honest assistant.\n <|eot_id|>\n"
|
||||
```
|
||||
|
||||
Signature\n
|
||||
@@ -180,11 +195,14 @@ end
|
||||
-----
|
||||
```jldoctest
|
||||
julia> using Revise
|
||||
julia> using YiemAgent
|
||||
julia> chatmessage = [
|
||||
Dict(:name=> "system",:text=> "You are a helpful, respectful and honest assistant.",),
|
||||
Dict(:name=> "user",:text=> "list me all planets in our solar system.",),
|
||||
Dict(:name=> "assistant",:text=> "I'm sorry. I don't know. You tell me.",),
|
||||
]
|
||||
julia> formattedtext = formatLLMtext(chatmessage, "llama3instruct")
|
||||
julia> formattedtext = YiemAgent.formatLLMtext(chatmessage, "llama3instruct")
|
||||
"<|begin_of_text|>\n <|start_header_id|>system<|end_header_id|>\n You are a helpful, respectful and honest assistant.\n <|eot_id|>\n <|start_header_id|>user<|end_header_id|>\n list me all planets in our solar system.\n <|eot_id|>\n <|start_header_id|>assistant<|end_header_id|>\n I'm sorry. I don't know. You tell me.\n <|eot_id|>\n"
|
||||
```
|
||||
|
||||
Signature\n
|
||||
|
||||
Reference in New Issue
Block a user