update
This commit is contained in:
65
src/utils.jl
65
src/utils.jl
@@ -26,13 +26,14 @@ using ..type
|
||||
```
|
||||
"""
|
||||
function sendReceivePrompt(a::T, prompt::String; max_tokens=256, timeout::Int=120,
|
||||
temperature::AbstractFloat=0.2) where {T<:agent}
|
||||
temperature::AbstractFloat=0.2, stopword=[]) where {T<:agent}
|
||||
a.msgMeta[:msgId] = "$(uuid4())" # new msg id for each msg
|
||||
msg = Dict(
|
||||
:msgMeta=> a.msgMeta,
|
||||
:txt=> prompt,
|
||||
:max_tokens=> max_tokens,
|
||||
:temperature=> temperature,
|
||||
:stopword=> stopword,
|
||||
)
|
||||
payloadChannel = Channel(1)
|
||||
|
||||
@@ -343,44 +344,52 @@ function isUsePlans(a::agentReflex)
|
||||
|
||||
conversation = messagesToString(a.messages)
|
||||
|
||||
aboutYourself =
|
||||
"""
|
||||
Your name is $(a.agentName)
|
||||
$(a.roles[a.role])
|
||||
"""
|
||||
|
||||
prompt =
|
||||
"""
|
||||
<|system|>
|
||||
You are a helpful assistant.
|
||||
You have access to the following tools:
|
||||
$toollines
|
||||
|
||||
<Your job>
|
||||
Your job is to decide whether you need think thoroughly in order to respond to the user according to your conversation with the user and tools you have.
|
||||
</Your job>
|
||||
<Example 1>
|
||||
user: Hello!. How are you?
|
||||
assistant: {"thought": "the user is greeting me, I don't need to think about it.", "anwer": "no"}
|
||||
</Example 1>
|
||||
<Example 2>
|
||||
user: "I want to get a bottle of wine."
|
||||
assistant: {"thought": "the user show interest to purchase wine from me.", "anwer": "yes"}
|
||||
</Example 2>
|
||||
<About yourself>
|
||||
$aboutYourself
|
||||
</About yourself>
|
||||
<You have access to the following tools>
|
||||
$toollines
|
||||
</You have access to the following tools>
|
||||
<Your job>
|
||||
Your job is to decide whether you need think thoroughly or use tools in order to respond to the user's question.
|
||||
</Your job>
|
||||
<Example 1>
|
||||
user: Hello!. How are you?
|
||||
assistant: {"thought": "the user is greeting me, I don't need to think about it.", "anwer": "no"}
|
||||
</Example 1>
|
||||
<Example 2>
|
||||
user: "What's tomorrow weather like?"
|
||||
assistant: {"thought": "I will need to use weather tools to check for tomorrow's temperature.", "anwer": "yes"}
|
||||
</Example 2>
|
||||
</s>
|
||||
$conversation
|
||||
<|assistant|>
|
||||
"""
|
||||
|
||||
# if LLM mentions any tools, use Plan/Thought/Act loop
|
||||
isuseplan = false
|
||||
response = sendReceivePrompt(a, prompt, temperature=0.2, max_tokens=64)
|
||||
response = split(response, "<|assistant|>")[1]
|
||||
response = split(response, "<|user|>")[1]
|
||||
|
||||
for (toolname, v) in a.tools
|
||||
if occursin("Yes", String(response))
|
||||
isuseplan = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if length(a.memory[:shortterm]) != 0
|
||||
isuseplan = true
|
||||
elseif a.role == :sommelier
|
||||
isuseplan = true
|
||||
else
|
||||
# if LLM mentions any tools, use Plan/Thought/Act loop
|
||||
response = sendReceivePrompt(a, prompt, temperature=0.2, max_tokens=64, stopword=["<|", "</"])
|
||||
for (toolname, v) in a.tools
|
||||
if occursin("Yes", String(response))
|
||||
isuseplan = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return isuseplan
|
||||
|
||||
Reference in New Issue
Block a user