From c2e3d1bae552df3a4959c863a86e41fbd9ea4d8b Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Tue, 23 Apr 2024 23:24:51 +0700 Subject: [PATCH] update --- src/interface.jl | 14 ++------ src/type.jl | 2 +- src/utils.jl | 93 ++++++++++++++++++++++++------------------------ 3 files changed, 51 insertions(+), 58 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 8e93404..af761ee 100755 --- a/src/interface.jl +++ b/src/interface.jl @@ -48,6 +48,7 @@ julia> addNewMessage(agent1, "user", "Where should I go to buy snacks") ``` """ function addNewMessage(a::T1, name::String, content::T2) where {T1<:agent, T2<:AbstractString} + if name ∉ a.availableRole # guard against typo error("name is not in agent.availableRole $(@__LINE__)") end @@ -181,18 +182,14 @@ function chat_mistral_openorca(a::agentReflex, prompttemplate="llama3") {longterm memory} " """ - conversation = formatLLMtext(a.messages, "llama3instruct") - prompt = """ $conversation """ - - response = sendReceivePrompt(a, prompt, a.config[:text2textchat][:mqtttopic], + _response = sendReceivePrompt(a, prompt, a.config[:text2textchat][:mqtttopic], timeout=180, stopword=["<|", " "system",:text=> "You are a helpful, respectful and honest assistant.",) + systemChatMsg = Dict(:name=> "system", :text=> "You are a helpful, respectful and honest assistant.",) push!(newAgent.messages, systemChatMsg) diff --git a/src/utils.jl b/src/utils.jl index d122cd4..aecd372 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -53,7 +53,6 @@ function sendReceivePrompt(a::T1, prompt::String, sendtopic::String; max_tokens::Integer=256, timeout::Integer=120, temperature::AbstractFloat=0.2, stopword::T2=["nostopwordyet"], seed=nothing) where {T1<:agent, T2<:Vector{<:AbstractString}} - println("---> 4") # copy a.msgMeta instead of using GeneralUtils.generate_msgMeta because if I want to custom # msgMeta for some communication I can do it during that agent instantiation and the custom # msgMeta will effect all of the communication in that agent without effecting all agent @@ -379,50 +378,6 @@ end 2. objective # what LLM going to do """ function isUsePlans(a::agentReflex) - toollines = "" - for (toolname, v) in a.tools - if toolname ∉ ["chatbox"] # LLM will always use chatbox - toolline = "$toolname is $(v[:description])\n" - toollines *= toolline - end - end - - conversation = messagesToString(a.messages) - - aboutYourself = - """ - Your name is $(a.name) - $(a.roles[a.role]) - """ - - prompt = - """ - <|system|> - - $aboutYourself - - - $toollines - - - $conversation - - - Your job is to decide whether you need think thoroughly or use tools in order to respond to the user. - Use the following format: - Thought: Do you need to think thoroughly or use tools before responding to the user? - - - user: Hello!. How are you? - assistant: The user is greeting me, I don't need to think about it. - - - user: "What's tomorrow weather like?" - assistant: I will need to use weather tools to check for tomorrow's temperature. - - - <|assistant|> - """ isuseplan = false @show a.role if length(a.memory[:shortterm]) != 0 @@ -432,6 +387,51 @@ function isUsePlans(a::agentReflex) elseif a.role == :sommelier isuseplan = true else + toollines = "" + for (toolname, v) in a.tools + if toolname ∉ ["chatbox"] # LLM will always use chatbox + toolline = "$toolname is $(v[:description])\n" + toollines *= toolline + end + end + + conversation = messagesToString(a.messages) + + aboutYourself = + """ + Your name is $(a.name) + $(a.roles[a.role]) + """ + + prompt = + """ + <|system|> + + $aboutYourself + + + $toollines + + + $conversation + + + Your job is to decide whether you need think thoroughly or use tools in order to respond to the user. + Use the following format: + Thought: Do you need to think thoroughly or use tools before responding to the user? + + + user: Hello!. How are you? + assistant: The user is greeting me, I don't need to think about it. + + + user: "What's tomorrow weather like?" + assistant: I will need to use weather tools to check for tomorrow's temperature. + + + <|assistant|> + """ + # if LLM mentions any tools, use Plan/Thought/Act loop response = sendReceivePrompt(a, prompt, a.config[:text2textchat][:mqtttopic], max_tokens=64, timeout=180, stopword=["<|", "