update
This commit is contained in:
252
src/interface.jl
252
src/interface.jl
@@ -126,7 +126,7 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
|
||||
1) Get to know what occasion the user is buying wine for
|
||||
2) Get to know what food the user will have with wine
|
||||
3) Get to know how much the user willing to spend
|
||||
4) Get to know type of wine the user is looking for e.g. Red, White, Sparkling, Rose, Dessert, Fortified
|
||||
4) Get to know type of wine the user is looking for e.g. red, white, sparkling, rose, dessert, fortified
|
||||
5) Get to know what characteristics of wine the user is looking for
|
||||
e.g. tannin, sweetness, intensity, acidity
|
||||
6) Check your inventory for the best wine that match the user preference
|
||||
@@ -197,51 +197,49 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
|
||||
)
|
||||
)
|
||||
@show outgoingMsg
|
||||
attempt = 0
|
||||
while true
|
||||
attempt += 1
|
||||
if attempt <= 5
|
||||
try
|
||||
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
||||
_responseJsonStr = response[:response][:text]
|
||||
expectedJsonExample =
|
||||
"""
|
||||
Here is an expected JSON format:
|
||||
{
|
||||
"thought": "...",
|
||||
"action": {"name": "...", "input": "..."},
|
||||
"observation": "..."
|
||||
}
|
||||
"""
|
||||
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
|
||||
thoughtDict = copy(JSON3.read(responseJsonStr))
|
||||
|
||||
# check if dict has all required value
|
||||
dummya::AbstractString = thoughtDict[:thought]
|
||||
actionname::AbstractString = thoughtDict[:action][:name]
|
||||
actioninput::AbstractString = thoughtDict[:action][:input]
|
||||
for attempt in 1:5
|
||||
try
|
||||
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
||||
_responseJsonStr = response[:response][:text]
|
||||
expectedJsonExample =
|
||||
"""
|
||||
Here is an expected JSON format:
|
||||
{
|
||||
"thought": "...",
|
||||
"action": {"name": "...", "input": "..."},
|
||||
"observation": "..."
|
||||
}
|
||||
"""
|
||||
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
|
||||
thoughtDict = copy(JSON3.read(responseJsonStr))
|
||||
|
||||
if actionname ∈ ["winestock", "chatbox", "recommendbox"]
|
||||
# LLM use available function
|
||||
else
|
||||
error("DecisionMaker use wrong function")
|
||||
end
|
||||
|
||||
return thoughtDict
|
||||
catch e
|
||||
io = IOBuffer()
|
||||
showerror(io, e)
|
||||
errorMsg = String(take!(io))
|
||||
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||
println("")
|
||||
@warn "Error occurred: $errorMsg\n$st"
|
||||
println("")
|
||||
# check if dict has all required value
|
||||
thought::AbstractString = thoughtDict[:thought]
|
||||
actionname::AbstractString = thoughtDict[:action][:name]
|
||||
actioninput::AbstractString = thoughtDict[:action][:input]
|
||||
if actionname ∈ ["winestock", "chatbox", "recommendbox"]
|
||||
# LLM use available function
|
||||
elseif thought == ""
|
||||
error("DecisionMaker has no thought")
|
||||
elseif length(actioninput) == 0
|
||||
error("DecisionMaker has no actioninput")
|
||||
else
|
||||
error("DecisionMaker use wrong function")
|
||||
end
|
||||
|
||||
else
|
||||
error("DecisionMaker failed to generate a thought")
|
||||
return thoughtDict
|
||||
catch e
|
||||
io = IOBuffer()
|
||||
showerror(io, e)
|
||||
errorMsg = String(take!(io))
|
||||
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||
println("")
|
||||
@warn "Attempt $attempt. Error occurred: $errorMsg\n$st"
|
||||
println("")
|
||||
end
|
||||
end
|
||||
error("DecisionMaker failed to generate a thought")
|
||||
end
|
||||
|
||||
|
||||
@@ -297,7 +295,22 @@ function progressValueEstimator(a::T1, state::T2)::Tuple{String, Integer} where
|
||||
}
|
||||
{"evaluation": "This trajectory is correct as it is reasonable to check an inventory for info provided in the question.
|
||||
It is also better to have simple searches corresponding to a single entity, making this the best action.",
|
||||
"score": 10}
|
||||
"score": 10
|
||||
}
|
||||
|
||||
{
|
||||
"question": "Do you have an all-in-one pen with 4 colors and a pencil for sale?",
|
||||
"thought_1": "Let me check our inventory first to see if I have it.",
|
||||
"action_1": {"name": "inventory", "input": "pen with 4 color and a pencil."},
|
||||
"observation_1": "I found {1: "Pilot Dr. grip 4-in-1 pen", 2: "Rotting pencil"}",
|
||||
"thought_2": "Ok, I have what the user is asking. Let's tell the user.",
|
||||
"action_2": {"name": "chatbox", "input": "Yes, we do have a Pilot Dr. grip 4-in-1 pen and a Rotting pencil"},
|
||||
"observation_1": "This is not what I wanted."
|
||||
}
|
||||
{"evaluation": "This trajectory is incorrect as my search term should be related to a 4-colors pen with a pencil in it,
|
||||
not a pen and a pencil seperately. A better search term should have been a 4-colors pen with a pencil, all-in-one.",
|
||||
"score": 2
|
||||
}
|
||||
|
||||
Let's begin!:
|
||||
$(JSON3.write(state[:thoughtHistory]))
|
||||
@@ -334,40 +347,34 @@ function progressValueEstimator(a::T1, state::T2)::Tuple{String, Integer} where
|
||||
)
|
||||
)
|
||||
|
||||
attempt = 0
|
||||
while true
|
||||
attempt += 1
|
||||
if attempt <= 5
|
||||
try
|
||||
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
||||
_responseJsonStr = response[:response][:text]
|
||||
expectedJsonExample =
|
||||
"""
|
||||
Here is an expected JSON format:
|
||||
{"evaluation": "...", "score": "..."}
|
||||
"""
|
||||
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
|
||||
evaluationDict = copy(JSON3.read(responseJsonStr))
|
||||
for attempt in 1:5
|
||||
try
|
||||
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
||||
_responseJsonStr = response[:response][:text]
|
||||
expectedJsonExample =
|
||||
"""
|
||||
Here is an expected JSON format:
|
||||
{"evaluation": "...", "score": "..."}
|
||||
"""
|
||||
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
|
||||
evaluationDict = copy(JSON3.read(responseJsonStr))
|
||||
|
||||
# check if dict has all required value
|
||||
dummya::AbstractString = evaluationDict[:evaluation]
|
||||
dummyb::Integer = evaluationDict[:score]
|
||||
# check if dict has all required value
|
||||
dummya::AbstractString = evaluationDict[:evaluation]
|
||||
dummyb::Integer = evaluationDict[:score]
|
||||
|
||||
return (evaluationDict[:evaluation], evaluationDict[:score])
|
||||
catch e
|
||||
io = IOBuffer()
|
||||
showerror(io, e)
|
||||
errorMsg = String(take!(io))
|
||||
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||
println("")
|
||||
@warn "Error occurred: $errorMsg\n$st"
|
||||
println("")
|
||||
end
|
||||
|
||||
else
|
||||
error("progressValueEstimator failed to generate an evaluation")
|
||||
return (evaluationDict[:evaluation], evaluationDict[:score])
|
||||
catch e
|
||||
io = IOBuffer()
|
||||
showerror(io, e)
|
||||
errorMsg = String(take!(io))
|
||||
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||
println("")
|
||||
@warn "Attempt $attempt. Error occurred: $errorMsg\n$st"
|
||||
println("")
|
||||
end
|
||||
end
|
||||
error("progressValueEstimator failed to generate an evaluation")
|
||||
end
|
||||
|
||||
|
||||
@@ -392,55 +399,6 @@ julia>
|
||||
function reflector(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractDict}
|
||||
# https://github.com/andyz245/LanguageAgentTreeSearch/blob/main/hotpot/hotpot.py
|
||||
|
||||
# _prompt =
|
||||
# """
|
||||
# You are an advanced reasoning agent that can improve based on self refection.
|
||||
# You will be given the information related to the previous help you've done for a user.
|
||||
# You were unsuccessful in helping the user either because you guessed the wrong answer with Finish[answer], or you used up your set number of reasoning steps.
|
||||
# In a few sentences, Diagnose a possible reason for failure and devise a new, concise, high level plan that aims to mitigate the same failure.
|
||||
# Use complete sentences.
|
||||
|
||||
# You should only respond in JSON format as describe below:
|
||||
# {"reflection": "your relection"}
|
||||
|
||||
# Here are some examples:
|
||||
# Previous Trial:
|
||||
# {
|
||||
# "question": "Hello, I would like a get a bottle of wine",
|
||||
# "thought_1": "A customer wants to buy a bottle of wine. Before making a recommendation, I need to know more about their preferences.",
|
||||
# "action_1": {"name": "chatbox", "input": "What is the occasion for which you're buying this wine?"},
|
||||
# "observation_1": "We are holding a wedding party",
|
||||
|
||||
# "thought_2": "A wedding party, that's a great occasion! The customer might be looking for a celebratory drink. Let me ask some more questions to narrow down the options.",
|
||||
# "action_2": {"name": "chatbox", "input": "What type of food will you be serving at the wedding?"},
|
||||
# "observation_2": "It will be Thai dishes.",
|
||||
|
||||
# "thought_3": "With Thai food, I should recommend a wine that complements its spicy and savory flavors. And since it's a celebratory occasion, the customer might prefer a full-bodied wine.",
|
||||
# "action_3": {"name": "chatbox", "input": "What is your budget for this bottle of wine?"},
|
||||
# "observation_3": "I would spend up to 50 bucks.",
|
||||
|
||||
# "thought_4": "Now that I have some more information, it's time to narrow down the options.",
|
||||
# "action_4": {"name": "winestock", "input": "red wine with full body, pairs well with spicy food, budget \$50"},
|
||||
# "observation_4": "I found the following wines in our stock: \n{\n 1: El Enemigo Cabernet Franc 2019\n2: Tantara Chardonnay 2017\n\n}\n",
|
||||
|
||||
# "thought_5": "Now that I have a list of potential wines, I need to know more about the customer's taste preferences.",
|
||||
# "action_5": {"name": "chatbox", "input": "What type of wine characteristics are you looking for? (e.g. t.e.g. tannin level, sweetness, intensity, acidity)"},
|
||||
# "observation_5": "I like full-bodied Red wine with low tannin.",
|
||||
|
||||
# "thought_6": "Now that I have more information about the customer's preferences, it's time to make a recommendation.",
|
||||
# "action_6": {"name": "recommendbox", "input": "El Enemigo Cabernet Franc 2019"},
|
||||
# "observation_6": "I don't like the one you recommend. I want dry wine."
|
||||
# }
|
||||
|
||||
# {
|
||||
# "reflection": "I asked the user about the occasion, food type, and budget, and then searched for wine in the inventory right away. However, I should have asked the user for the specific wine type and their preferences in order to gather more information before making a recommendation."
|
||||
# }
|
||||
|
||||
# Previous trial:
|
||||
# $(JSON3.write(state[:thoughtHistory]))
|
||||
# {"reflection"
|
||||
# """
|
||||
|
||||
_prompt =
|
||||
"""
|
||||
You are a helpful sommelier working for a wine store.
|
||||
@@ -475,7 +433,7 @@ function reflector(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractDict}
|
||||
|
||||
"thought_5": "Now that I have a list of potential wines, I need to know more about the customer's taste preferences.",
|
||||
"action_5": {"name": "chatbox", "input": "What type of wine characteristics are you looking for? (e.g. t.e.g. tannin level, sweetness, intensity, acidity)"},
|
||||
"observation_5": "I like full-bodied Red wine with low tannin.",
|
||||
"observation_5": "I like full-bodied red wine with low tannin.",
|
||||
|
||||
"thought_6": "Now that I have more information about the customer's preferences, it's time to make a recommendation.",
|
||||
"action_6": {"name": "recommendbox", "input": "El Enemigo Cabernet Franc 2019"},
|
||||
@@ -523,39 +481,33 @@ function reflector(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractDict}
|
||||
)
|
||||
)
|
||||
|
||||
attempt = 0
|
||||
while true
|
||||
attempt += 1
|
||||
if attempt <= 5
|
||||
try
|
||||
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
||||
_responseJsonStr = response[:response][:text]
|
||||
expectedJsonExample =
|
||||
"""
|
||||
Here is an expected JSON format:
|
||||
{"reflection": "..."}
|
||||
"""
|
||||
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
|
||||
reflectionDict = copy(JSON3.read(responseJsonStr))
|
||||
for attempt in 1:5
|
||||
try
|
||||
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
||||
_responseJsonStr = response[:response][:text]
|
||||
expectedJsonExample =
|
||||
"""
|
||||
Here is an expected JSON format:
|
||||
{"reflection": "..."}
|
||||
"""
|
||||
responseJsonStr = jsoncorrection(a, _responseJsonStr, expectedJsonExample)
|
||||
reflectionDict = copy(JSON3.read(responseJsonStr))
|
||||
|
||||
# check if dict has all required value
|
||||
dummya::AbstractString = reflectionDict[:reflection]
|
||||
# check if dict has all required value
|
||||
dummya::AbstractString = reflectionDict[:reflection]
|
||||
|
||||
return reflectionDict[:reflection]
|
||||
catch e
|
||||
io = IOBuffer()
|
||||
showerror(io, e)
|
||||
errorMsg = String(take!(io))
|
||||
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||
println("")
|
||||
@warn "Error occurred: $errorMsg\n$st"
|
||||
println("")
|
||||
end
|
||||
|
||||
else
|
||||
error("reflector failed to generate a thought")
|
||||
return reflectionDict[:reflection]
|
||||
catch e
|
||||
io = IOBuffer()
|
||||
showerror(io, e)
|
||||
errorMsg = String(take!(io))
|
||||
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||
println("")
|
||||
@warn "Attempt $attempt. Error occurred: $errorMsg\n$st"
|
||||
println("")
|
||||
end
|
||||
end
|
||||
error("reflector failed to generate a thought")
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user