add identifyUserIntention()

This commit is contained in:
2023-11-16 07:25:57 +00:00
parent 2c3891223e
commit 102be442ca

View File

@@ -74,7 +74,7 @@ function agentReact(
QTS: the input question your user is asking and you must answer
Plan: first you should always think about the question and the info you have thoroughly then extract and devise a complete plan to find the answer (pay attention to variables and their corresponding numerals).
Thought: you should always think about the info you need and what to do (pay attention to correct numeral calculation and commonsense).
Act: the action tool related to what you intend to do, should be one of [Chatbox, Internet, WineStock]
Act: the action tool related to what you intend to do, should be one of {toolnames}
ActInput: the input to the action (pay attention to the tool's input)
Obs: the result of the action
... (this Plan/Thought/Act/ActInput/Obs loop can repeat N times.)
@@ -91,7 +91,7 @@ function agentReact(
QTS: the input question your user is asking and you must answer
Plan: first you should always think about the question and the info you have thoroughly then extract and devise a complete plan to find the answer (pay attention to variables and their corresponding numerals).
Thought: ask yourself do you have all the info you need? And what to do (pay attention to correct numeral calculation and commonsense).
Act: the tool that match your thought, should be one of [Chatbox, Internet, WineStock]
Act: the tool that match your thought, should be one of {toolnames}
ActInput: the input to the action (pay attention to the tool's input)
Obs: the result of the action
... (this Plan/Thought/Act/ActInput/Obs loop can repeat N times until you know the answer.)
@@ -260,7 +260,7 @@ function generatePrompt_react_mistral_openorca(messages::Dict, systemMsg::String
Begin!
<|im_end|>
Here are the context for the question:
{context}
{context}
"""
for msg in messages
role = msg[:role]
@@ -273,6 +273,9 @@ function generatePrompt_react_mistral_openorca(messages::Dict, systemMsg::String
toolline = "$(tool[:name]): $(tool[:description]) $(tool[:input]) $(tool[:output])\n"
toollines *= toolline
end
prompt = replace(promptTemplate, "{tools}" => toollines)
prompt = replace(promptTemplate, "{context}" => context)
elseif role == "user"
@@ -301,11 +304,14 @@ function generatePrompt_react_mistral_openorca(a::T, usermsg::String) where {T<:
"""
prompt = replace(prompt, "{systemMsg}" => a.roles[a.role])
toolnames = ""
toollines = ""
for (toolname, v) in a.tools
toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
toollines *= toolline
toolnames *= "$toolname,"
end
prompt = replace(prompt, "{toolnames}" => toolnames)
prompt = replace(prompt, "{tools}" => toollines)
prompt = replace(prompt, "{context}" => a.context)
@@ -318,12 +324,22 @@ end
#WORKING
function conversation(a::T, usermsg::String) where {T<:agent}
userintend = identifyUserIntention(a, usermsg)
@show userintend
error("conversation done")
if a.thought == "nothing"
a.context = conversationSummary(a)
addNewMessage(a, "user", usermsg)
prompt = generatePrompt_react_mistral_openorca(a, usermsg)
@show prompt
error("conversation done")
else
@@ -344,11 +360,6 @@ function work(a::T, usermsg::String) where {T<:agent}
end
function workContinueThought(a::T, usermsg::String) where {T<:agent}
end
#WORKING
"""
make a conversation summary.
```julia
@@ -492,80 +503,113 @@ function workContinue(a::agent)
end
#TESTING
function identifyUserIntention(a::agent, usermsg::String)
# function identifyUserIntention(a::T, usermsg::String) where {T<:agent}
# prompt =
# """
# <|im_start|>system
# You are a helpful assistant. Your job is to determine intention of the question.
# Your choices are:
# chat: normal conversation that you don't need to do something.
# task: a request for you to do something.
# Here are examples of how to determine intention of the question:
# Question: How are you?
# Answer: {chat}, this question intention is about chat.
# Question: Ummm.
# Answer: {chat}, this question is about chat.
# Question: Search for the stock prices of 'BJC' and 'IOU'on June 10th.
# Answer: {task}, this question is about asking you to do something.
# Question: Hello
# Answer: {chat}, this question is about chat.
# Question: 'BJC' and 'IOU'on June 10th.
# Answer: {task}, this question is about asking you to do something.
# Question: What time is it?
# Answer: {task}, this question is about asking you to do something.
# Question: What is the price of 'ABC'
# Answer: {task}, this question is about asking you to do something.
# Question: Do you like coconut?
# Answer: {task}, this question is about asking you to do something.
# Question: What is the weather tomorrow?
# Answer: {task}, this question is about asking you to do something.
# Question: I'm fine.
# Answer: {chat}, this question is about chat.
# Question: How to make a cake?
# Answer: {task}, this question is about asking you to do something.
# Question: Did you turn off the light?
# Answer: {task}, this question is about asking you to do something.
# Question: What is stock price of Tesla on June 6th?
# Answer: {task}, this question is about asking you to do something.
# Question: Tell me some jokes.
# Answer: {chat}, this question is about chat.
# Begin!
# Here are the context for the question:
# {context}
# <|im_end|>
# <|im_start|>user
# Question: {input}
# <|im_end|>
# <|im_start|>assistant
# """
# prompt = replace(prompt, "{input}" => usermsg)
# result = sendReceivePrompt(a, prompt)
# answer = result === nothing ? nothing : GeneralUtils.getStringBetweenCharacters(result, "{", "}")
# return answer
# end
function identifyUserIntention(a::T, usermsg::String) where {T<:agent}
prompt =
"""
<|im_start|>system
You are a helpful assistant. Your job is to determine intention of the question.
Your choices are:
chat: normal conversation that you don't need to do something.
task: a request for you to do something.
Here are examples of how to determine intention of the question:
Question: How are you?
Answer: {chat}, this question intention is about chat.
Question: Ummm.
Answer: {chat}, this question is about chat.
Question: Search for the stock prices of 'BJC' and 'IOU'on June 10th.
Answer: {task}, this question is about asking you to do something.
Question: Hello
Answer: {chat}, this question is about chat.
Question: 'BJC' and 'IOU'on June 10th.
Answer: {task}, this question is about asking you to do something.
Question: What time is it?
Answer: {task}, this question is about asking you to do something.
Question: What is the price of 'ABC'
Answer: {task}, this question is about asking you to do something.
Question: Do you like coconut?
Answer: {task}, this question is about asking you to do something.
Question: What is the weather tomorrow?
Answer: {task}, this question is about asking you to do something.
Question: I'm fine.
Answer: {chat}, this question is about chat.
Question: How to make a cake?
Answer: {task}, this question is about asking you to do something.
Question: Did you turn off the light?
Answer: {task}, this question is about asking you to do something.
Question: What is stock price of Tesla on June 6th?
Answer: {task}, this question is about asking you to do something.
Question: Tell me some jokes.
Answer: {chat}, this question is about chat.
Begin!
If the user question is about general conversation say, "{chat}".
If the user question is related to wine say, "{wine}".
If the user question is related to your earlier thought say, "{thought}".
Your earlier thought:
{earlier thought}
Here are the context for the question:
{context}
<|im_end|>
<|im_start|>user
Question: {input}
{input}
<|im_end|>
<|im_start|>assistant
"""
prompt = replace(prompt, "{input}" => usermsg)
prompt = replace(prompt, "{earlier thought}" => a.thought)
prompt = replace(prompt, "{context}" => "")
@show prompt
result = sendReceivePrompt(a, prompt)
answer = result === nothing ? nothing : GeneralUtils.getStringBetweenCharacters(result, "{", "}")
@show answer
error("indentifyUserIntention done")
return answer
end
function sendReceivePrompt(a::agent, prompt::String; timeout::Int=30)
a.msgMeta[:msgId] = "$(uuid4())" # new msg id for each msg
msg = Dict(
@@ -691,7 +735,7 @@ end
(char = "i", startInd = 35, endInd = 35)
```
"""
function detectCharacters(text::T, characters::Vector{T}) where {T<:AbstractString}
function detectCharacters(text::T1, characters::Vector{T2}) where {T1<:AbstractString, T2<:AbstractString}
result = []
for i in eachindex(text)
for char in characters