This commit is contained in:
narawat lamaiin
2024-07-29 15:28:47 +07:00
parent 7e0f8fa6f0
commit 689bca3805
3 changed files with 30 additions and 31 deletions

View File

@@ -197,7 +197,7 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
# - plan: Based on the current situation, what would you do to complete the task? Be specific. # - plan: Based on the current situation, what would you do to complete the task? Be specific.
# - action (Must be aligned with your plan): Can be one of the following functions: # - action (Must be aligned with your plan): Can be one of the following functions:
# 1) CHATBOX[text], which you can use to talk with the user. "text" is in verbal English. # 1) CHATBOX[text], which you can use to talk with the user. "text" is in verbal English.
# 2) WINESTOCK[query], which you can use to find info about wine in your inventory. "query" is a search term in verbal English. # 2) CHECKINVENTORY[query], which you can use to find info about wine in your inventory. "query" is a search term in verbal English.
# - observation: result of the action. # - observation: result of the action.
# You should only respond in format as described below: # You should only respond in format as described below:
@@ -222,15 +222,12 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
You must follow the following DO guidelines: You must follow the following DO guidelines:
- If the user interrupts, prioritize the user then get back to the guidelines. - If the user interrupts, prioritize the user then get back to the guidelines.
- Check your inventory before mentioning any specific wine.
- Get to know how much the user willing to spend - Get to know how much the user willing to spend
- Get to know type of wine the user is looking for e.g. red, white, sparkling, rose, dessert, fortified - Get to know type of wine the user is looking for e.g. red, white, sparkling, rose, dessert, fortified
- Get to know what occasion the user is buying wine for - Get to know what occasion the user is buying wine for
- Get to know what characteristics of wine the user is looking for e.g. tannin, sweetness, intensity, acidity - Get to know what characteristics of wine the user is looking for e.g. tannin, sweetness, intensity, acidity
- Get to know what food will be served with wine - Get to know what food will be served with wine
You must follow the following DON'T guidelines:
- Don't mention any specific wine until you've checked your inventory.
- Check your inventory before recommending any specific wine.
You should then respond to the user with interleaving Thought, Plan, Action and Observation: You should then respond to the user with interleaving Thought, Plan, Action and Observation:
- thought: - thought:
@@ -238,7 +235,7 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
- plan: Based on the current situation, state a complete plan to complete the task. Be specific. - plan: Based on the current situation, state a complete plan to complete the task. Be specific.
- action_name (Must be aligned with your plan): Can be one of the following functions: - action_name (Must be aligned with your plan): Can be one of the following functions:
1) CHATBOX[text], which you can use to talk with the user. "text" is in verbal English. 1) CHATBOX[text], which you can use to talk with the user. "text" is in verbal English.
2) WINESTOCK[query], which you can use to find info about wine in your inventory. "query" is a search term in verbal English. 2) CHECKINVENTORY[query], which you can use to find info about wine in your inventory. "query" is a search term in verbal English.
Good query example: black car with a stereo, 200 mile range and an electric motor. Good query example: black car with a stereo, 200 mile range and an electric motor.
Good query example: How many car brand are from Asia? Good query example: How many car brand are from Asia?
- action_input: input to the action - action_input: input to the action
@@ -280,7 +277,7 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
["thought", "plan", "action_name", "action_input", "observation"], ["thought", "plan", "action_name", "action_input", "observation"],
rightmarker=":", symbolkey=true) rightmarker=":", symbolkey=true)
if responsedict[:action_name] ["CHATBOX", "WINESTOCK"] if responsedict[:action_name] ["CHATBOX", "CHECKINVENTORY"]
error("decisionMaker didn't use the given functions ", @__LINE__) error("decisionMaker didn't use the given functions ", @__LINE__)
end end
@@ -493,9 +490,8 @@ function evaluator(config::T1, state::T2
Analyze the trajectories of a solution to a question answering task. The trajectories are Analyze the trajectories of a solution to a question answering task. The trajectories are
labeled by environmental observations about the situation, thoughts that can reason about labeled by environmental observations about the situation, thoughts that can reason about
the current situation and actions that can be three types: the current situation and actions that can be three types:
1) winestock[query], which you can use to find wine in your inventory. 1) CHECKINVENTORY[query], which you can use to find wine in your inventory.
2) chatbox[text], which you can use to interact with the user. 2) CHATBOX[text], which you can use to interact with the user.
3) recommendbox[answer], which returns your wine recommendation to the user.
Given a question and a trajectory, evaluate its correctness and provide your reasoning and Given a question and a trajectory, evaluate its correctness and provide your reasoning and
analysis in detail. Focus on the latest thought, action, and observation. Incomplete trajectories analysis in detail. Focus on the latest thought, action, and observation. Incomplete trajectories
@@ -1056,8 +1052,8 @@ function think(a::T) where {T<:agent}
response = response =
if actionname == "CHATBOX" if actionname == "CHATBOX"
(result=actioninput, errormsg=nothing, success=true) (result=actioninput, errormsg=nothing, success=true)
elseif actionname == "WINESTOCK" elseif actionname == "CHECKINVENTORY"
winestock(a, actioninput) checkinventory(a, actioninput)
else else
error("undefined LLM function. Requesting $actionname") error("undefined LLM function. Requesting $actionname")
end end

View File

@@ -1,7 +1,7 @@
module llmfunction module llmfunction
export virtualWineUserChatbox, jsoncorrection, winestock, export virtualWineUserChatbox, jsoncorrection, checkinventory,
virtualWineUserRecommendbox, userChatbox, userRecommendbox virtualWineUserRecommendbox, userChatbox, userRecommendbox, extractWineAttributes
using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs
using GeneralUtils, SQLLLM using GeneralUtils, SQLLLM
@@ -352,7 +352,7 @@ end
julia> using ChatAgent julia> using ChatAgent
julia> agent = ChatAgent.agentReflex("Jene") julia> agent = ChatAgent.agentReflex("Jene")
julia> input = "{\"food\": \"pizza\", \"occasion\": \"anniversary\"}" julia> input = "{\"food\": \"pizza\", \"occasion\": \"anniversary\"}"
julia> result = winestock(agent, input) julia> result = checkinventory(agent, input)
"{"wine 1": {\"Winery\": \"Pichon Baron\", \"wine name\": \"Pauillac (Grand Cru Classé)\", \"grape variety\": \"Cabernet Sauvignon\", \"year\": 2010, \"price\": \"125 USD\", \"stock ID\": \"ar-17\"}, }" "{"wine 1": {\"Winery\": \"Pichon Baron\", \"wine name\": \"Pauillac (Grand Cru Classé)\", \"grape variety\": \"Cabernet Sauvignon\", \"year\": 2010, \"price\": \"125 USD\", \"stock ID\": \"ar-17\"}, }"
``` ```
@@ -362,7 +362,7 @@ julia> result = winestock(agent, input)
# Signature # Signature
""" """
function winestock(a::T1, input::T2 function checkinventory(a::T1, input::T2
)::Union{Tuple{String, Number, Number, Bool}, Tuple{String, Nothing, Number, Bool}} where {T1<:agent, T2<:AbstractString} )::Union{Tuple{String, Number, Number, Bool}, Tuple{String, Nothing, Number, Bool}} where {T1<:agent, T2<:AbstractString}
wineattributes = extractWineAttributes(a, input) wineattributes = extractWineAttributes(a, input)

View File

@@ -62,6 +62,9 @@ function text2textInstructLLM(prompt::String)
return response return response
end end
# Instantiate an agent # Instantiate an agent
a = YiemAgent.sommelier( a = YiemAgent.sommelier(
text2textInstructLLM, text2textInstructLLM,
@@ -70,22 +73,22 @@ end
id="testingSessionID", # agent instance id id="testingSessionID", # agent instance id
) )
function main() # function main()
userinput = "Hello, I would like a get a bottle of wine." # userinput = "Hello, I would like a get a bottle of wine."
for i in 1:10 # for i in 1:10
response = YiemAgent.conversation(a, Dict(:text=> userinput)) # response = YiemAgent.conversation(a, Dict(:text=> userinput))
println("") # println("")
println("--> assistant response: \n", response) # println("--> assistant response: \n", response)
println("") # println("")
println("--> user input:") # println("--> user input:")
userinput = readline() # userinput = readline()
end # end
end # end
main() # main()
# """ # """
# I'm having a graduation party this evening. So I think a bottle of wine would be nice. # I'm having a graduation party this evening. I have no budget limit.
# I have no idea. The party will be formal. What type of wine people usually get for this occasion? # I have no idea. The party will be formal. What type of wine people usually get for this occasion?
# What about sparkling Rose? # What about sparkling Rose?
@@ -116,7 +119,7 @@ main()
input = "query=\"medium-bodied dry white wine\""
result = YiemAgent.extractWineAttributes(a, input)