From 4d7998da6d58086a2793aac3e10346fc81aa4cab Mon Sep 17 00:00:00 2001 From: tonaerospace Date: Thu, 23 Nov 2023 13:42:45 +0000 Subject: [PATCH] update --- src/interface.jl | 16 +++++++++++----- src/type.jl | 9 ++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index f51c771..ecb5dff 100755 --- a/src/interface.jl +++ b/src/interface.jl @@ -215,7 +215,6 @@ function chat_mistral_openorca(a::agentReflex, usermsg::String) """ <|im_start|>system {role} - {tools} {thinkingFormat} <|im_end|> {context} @@ -297,6 +296,7 @@ function planner_mistral_openorca(a::agentReflex, usermsg::String) toollines *= toolline toolnames *= "$toolname," end + prompt = replace(prompt, "{toolnames}" => toolnames) prompt = replace(prompt, "{tools}" => "You have access to the following tools:\n$toollines") @@ -607,18 +607,21 @@ function work(a::agentReflex, usermsg::String) a.earlierConversation = conversationSummary(a) _ = addNewMessage(a, "user", usermsg) elseif a.thinkingmode == :continue_thinking + error("continue_thinking") _ = addNewMessage(a, "user", usermsg) a.thought *= "Obs $(a.attempt): $usermsg\n" else error("undefined condition thinkingmode = $thinkingmode") end - + while true # plan a.attempt += 1 @show a.attempt @show usermsg - a.thoughtlog *= "$usermsg\n" + logmsg = "<|im_start|>user:\nStimulus: $usermsg\n<|im_end|>\n" + a.memory[:shortterm] *= logmsg + toolname = nothing toolinput = nothing prompt = planner_mistral_openorca(a, usermsg) @@ -626,7 +629,9 @@ function work(a::agentReflex, usermsg::String) respond = sendReceivePrompt(a, prompt) plan = split(respond, "<|im_end|>")[1] @show plan - a.thoughtlog *= plan + logmsg = "<|im_start|>assistant:\n$plan\n" + a.memory[:shortterm] *= logmsg + a.step = 0 while true # execute step by step a.step += 1 @@ -806,13 +811,14 @@ end function chooseThinkingMode(a::agentReflex, usermsg::String) thinkingmode = nothing - if a.thoughtlog != "nothing" + if length(a.thoughtlog) != 0 thinkingmode = :continue_thinking else prompt = """ <|im_start|>system {systemMsg} + You always use tools if there is a chance to impove your respond. You have access to the following tools: {tools} Your job is to determine whether you will use tools or actions to respond. diff --git a/src/type.jl b/src/type.jl index ff06335..0770dd7 100644 --- a/src/type.jl +++ b/src/type.jl @@ -34,7 +34,7 @@ abstract type agent end # messages= [Dict(:role=>"system", :content=> "", :timestamp=> Dates.now()),] messages = Vector{Dict{Symbol, Any}}() tools::Union{Dict, Nothing} = nothing - thoughtlog::String = "nothing" # logs unfinished thoughts + thoughtlog::String = "" # logs unfinished thoughts attempt::Int = 0 # attempted number step::Int = 0 # step number thinkingroundlimit::Int = 5 # thinking round limit @@ -42,7 +42,7 @@ abstract type agent end thinkingFormat::Union{Dict, Nothing} = nothing memory::Dict = Dict( :shortterm=> "", - :longterm=>"" + :longterm=> Dict{Symbol, Any}(), ) end @@ -54,7 +54,6 @@ function agentReflex( :assistant => """ You are a helpful assistant who respond to a stimulus as best you can. - You always use tools if there is a chance to impove your respond. """, :sommelier => """ @@ -87,12 +86,12 @@ function agentReflex( Begin!""", :planner=> """Use the following format: - Stimulus: the input given to you and you must respond + Stimulus: the input user gives to you and you must respond Plan: first you should always think about the stimulus and the info you have thoroughly then extract and devise a step by step plan to respond (pay attention to correct numeral calculation and commonsense). """, :actor=> """Use the following format: - Stimulus: the input given to you and you must respond + Stimulus: the input user gives to you and you must respond Thought: your should always think about what to do (pay attention to correct numeral calculation and commonsense). Act: the action to take that match your thought, should be one of {toolnames} ActInput: the input to the action (pay attention to the tool's input)