update
This commit is contained in:
97
src/utils.jl
97
src/utils.jl
@@ -363,40 +363,83 @@ end
|
||||
# return thinkingmode
|
||||
# end
|
||||
|
||||
# function isUseTools(a::agentReflex, usermsg::String)
|
||||
# prompt =
|
||||
# """
|
||||
# <|im_start|>system
|
||||
# {systemMsg}
|
||||
|
||||
# Your earlier conversation with the user:
|
||||
# None
|
||||
|
||||
# User's message:
|
||||
# $usermsg
|
||||
|
||||
# From the user's message, Are there any explicit request from the user? Answer: {Yes/No/Not sure}. What do you need to do?
|
||||
# <|im_end|>
|
||||
# <|im_start|>assistant
|
||||
# Answer:
|
||||
# """
|
||||
# toollines = ""
|
||||
# for (toolname, v) in a.tools
|
||||
# if toolname ∉ [:chatbox]
|
||||
# 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)
|
||||
|
||||
# result = sendReceivePrompt(a, prompt, temperature=0.2)
|
||||
|
||||
# if occursin("Yes", result)
|
||||
# isUseTool = result
|
||||
# @show isUseTool
|
||||
# return true
|
||||
# else
|
||||
# return false
|
||||
# end
|
||||
# end
|
||||
|
||||
function isUseTools(a::agentReflex, usermsg::String)
|
||||
prompt =
|
||||
"""
|
||||
<|im_start|>system
|
||||
{systemMsg}
|
||||
You have access to the following tools:
|
||||
{tools}
|
||||
|
||||
User's message:
|
||||
{input}
|
||||
|
||||
From the user's message, Do you need to any tools before responseing? 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]
|
||||
if toolname ∉ ["chatbox"]
|
||||
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, temperature=0.2)
|
||||
|
||||
if occursin("Yes", result)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
prompt =
|
||||
"""
|
||||
<|im_start|>system
|
||||
$(a.roles[a.role])
|
||||
You have access to the following tools:
|
||||
$toollines
|
||||
|
||||
Your earlier conversation with the user:
|
||||
None
|
||||
|
||||
User's message:
|
||||
$usermsg
|
||||
|
||||
From the user's message, what to do?
|
||||
<|im_end|>
|
||||
<|im_start|>assistant
|
||||
|
||||
"""
|
||||
|
||||
# if LLM mentions any tools, use Plan/Thought/Act loop
|
||||
isusetool = false
|
||||
result = sendReceivePrompt(a, prompt, temperature=0.2)
|
||||
for (toolname, v) in a.tools
|
||||
if occursin(toolname, result)
|
||||
isusetool = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return isusetool
|
||||
end
|
||||
|
||||
|
||||
@@ -441,7 +484,7 @@ function conversationSummary(a::T) where {T<:agent}
|
||||
|
||||
"""
|
||||
conversation = ""
|
||||
summary = "nothing"
|
||||
summary = ""
|
||||
if length(a.messages)!= 0
|
||||
for msg in a.messages[1:end-1]
|
||||
role = msg[:role]
|
||||
@@ -458,7 +501,7 @@ function conversationSummary(a::T) where {T<:agent}
|
||||
|
||||
prompt = replace(prompt, "{conversation}" => conversation)
|
||||
result = sendReceivePrompt(a, prompt)
|
||||
summary = result === nothing ? "nothing" : result
|
||||
summary = result === nothing ? "" : result
|
||||
summary = split(summary, "<|im_end|>")[1]
|
||||
if summary[1:1] == "\n"
|
||||
summary = summary[2:end]
|
||||
|
||||
Reference in New Issue
Block a user