update
This commit is contained in:
92
src/utils.jl
92
src/utils.jl
@@ -2,7 +2,7 @@ module utils
|
||||
|
||||
export makeSummary, sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalStepInPlan,
|
||||
detectCharacters, findDetectedCharacter, extract_number, toolNameBeingCalled,
|
||||
chooseThinkingMode, conversationSummary, checkReasonableness, replaceHeaders,
|
||||
isUseTools, conversationSummary, checkReasonableness, replaceHeaders,
|
||||
addShortMem!, splittext, dictToString, removeHeaders, keepOnlyKeys, experience
|
||||
|
||||
using UUIDs, Dates, DataStructures
|
||||
@@ -89,12 +89,14 @@ end
|
||||
)
|
||||
```
|
||||
"""
|
||||
function sendReceivePrompt(a::T, prompt::String; max_tokens=256, timeout::Int=120) where {T<:agent}
|
||||
function sendReceivePrompt(a::T, prompt::String; max_tokens=256, timeout::Int=120,
|
||||
temperature::AbstractFloat=0.2) where {T<:agent}
|
||||
a.msgMeta[:msgId] = "$(uuid4())" # new msg id for each msg
|
||||
msg = Dict(
|
||||
:msgMeta=> a.msgMeta,
|
||||
:txt=> prompt,
|
||||
:max_tokens=>max_tokens
|
||||
:max_tokens=> max_tokens,
|
||||
:temperature=> temperature,
|
||||
)
|
||||
payloadChannel = Channel(1)
|
||||
|
||||
@@ -340,52 +342,6 @@ function toolNameBeingCalled(text::T, tools::Dict) where {T<:AbstractString}
|
||||
return toolNameBeingCalled
|
||||
end
|
||||
|
||||
|
||||
|
||||
function chooseThinkingMode(a::agentReflex, usermsg::String)
|
||||
thinkingmode = nothing
|
||||
if length(a.memory[:log]) != 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.
|
||||
|
||||
Choose one of the following choices:
|
||||
Choice 1: If the user want to get wine say, "{yes}".
|
||||
Choice 2: If you don't need to use tools or actions to respond to the stimulus say, "{no}".
|
||||
<|im_end|>
|
||||
|
||||
<|im_start|>user
|
||||
{input}
|
||||
<|im_end|>
|
||||
<|im_start|>assistant
|
||||
|
||||
"""
|
||||
toollines = ""
|
||||
for (toolname, v) in a.tools
|
||||
if toolname ∉ ["chatbox", "nothing"]
|
||||
toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
|
||||
toollines *= toolline
|
||||
end
|
||||
end
|
||||
prompt = replace(prompt, "{systemMsg}" => a.roles[a.role])
|
||||
prompt = replace(prompt, "{tools}" => toollines)
|
||||
prompt = replace(prompt, "{input}" => usermsg)
|
||||
result = sendReceivePrompt(a, prompt)
|
||||
willusetools = GeneralUtils.getStringBetweenCharacters(result, "{", "}")
|
||||
thinkingmode = willusetools == "yes" ? :new_thinking : :no_thinking
|
||||
end
|
||||
|
||||
return thinkingmode
|
||||
end
|
||||
|
||||
|
||||
# function chooseThinkingMode(a::agentReflex, usermsg::String)
|
||||
# thinkingmode = nothing
|
||||
# if length(a.memory[:log]) != 0
|
||||
@@ -429,32 +385,26 @@ end
|
||||
# return thinkingmode
|
||||
# end
|
||||
|
||||
function chooseThinkingMode(a::agentReflex, usermsg::String)
|
||||
thinkingmode = nothing
|
||||
if length(a.memory[:log]) != 0
|
||||
thinkingmode = :continue_thinking
|
||||
else
|
||||
prompt =
|
||||
function isUseTools(a::agentReflex, usermsg::String)
|
||||
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}
|
||||
|
||||
User message:
|
||||
{input}
|
||||
|
||||
Your job is to determine the following topics:
|
||||
Topic 1: Is the user message show that they would like to get some wine? {Yes/No}
|
||||
Topic 2: Is the user message show that they would like to get some cloth? {Yes/No}
|
||||
Your job is to answer the following questions:
|
||||
Question 1: From the user's message, Do you need to any tools before responding? Answer: {Yes/No/Not sure}. What will the you do?
|
||||
<|im_end|>
|
||||
<|im_start|>assistant
|
||||
|
||||
Answer:
|
||||
"""
|
||||
toollines = ""
|
||||
for (toolname, v) in a.tools
|
||||
if toolname ∉ ["chatbox", "nothing"]
|
||||
if toolname ∉ [:chatbox]
|
||||
toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
|
||||
toollines *= toolline
|
||||
end
|
||||
@@ -462,19 +412,17 @@ function chooseThinkingMode(a::agentReflex, usermsg::String)
|
||||
prompt = replace(prompt, "{systemMsg}" => a.roles[a.role])
|
||||
prompt = replace(prompt, "{tools}" => toollines)
|
||||
prompt = replace(prompt, "{input}" => usermsg)
|
||||
result = sendReceivePrompt(a, prompt)
|
||||
headers = detectCharacters(lessonwithcontext, ["Topic 1:", "Topic 2:"])
|
||||
chunkedtext = chunktext(result, headers)
|
||||
@show chunkedtext
|
||||
error(11)
|
||||
willusetools = GeneralUtils.getStringBetweenCharacters(result, "{", "}")
|
||||
thinkingmode = willusetools == "Yes" ? :new_thinking : :no_thinking
|
||||
end
|
||||
|
||||
result = sendReceivePrompt(a, prompt, temperature=0.2)
|
||||
|
||||
@show result
|
||||
error(11)
|
||||
# headers = detectCharacters(result, ["Question 1:", "Question 2:"])
|
||||
# chunkedtext = chunktext(result, headers)
|
||||
|
||||
return thinkingmode
|
||||
if occursin("Yes", result)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user