This commit is contained in:
narawat lamaiin
2024-05-05 22:51:53 +07:00
parent e43caf4919
commit 9e3ab1333b
5 changed files with 310 additions and 287 deletions

View File

@@ -127,7 +127,7 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
Thought can reason about the current situation, and Action can be three types:
1) winestock[query], which you can use to find wine in your inventory. The more input data the better.
2) chatbox[text], which you can use to interact with the user.
3) recommendation[answer], which returns your wine reccommendation to the user.
3) reccommendbox[answer], which returns your wine reccommendation to the user.
$responseformat
@@ -186,9 +186,18 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
_response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
_thoughtJsonStr = _response[:response][:text]
thoughtJsonStr = jsoncorrection(a, _thoughtJsonStr, responseformat)
expectedJsonExample =
"""
Here is an expected JSON format:
{
"Thought": "...",
"Action": {"name": "...", "input": "..."},
"Observation": "..."
}
"""
thoughtJsonStr = jsoncorrection(a, _thoughtJsonStr, expectedJsonExample)
thoughtDict = copy(JSON3.read(thoughtJsonStr))
pprint(thoughtDict)
return thoughtDict
end
@@ -219,10 +228,7 @@ function progressValueEstimator(a::T1, state::T2)::Tuple{String, Integer} where
"""
You should only respond in JSON format as describe below:
{
"Thought_1": "reasoning 1",
"Action_1": {"name": "action to take", "input": "Action input"},
"Observation_1": "result of the action",
"Evaluation_1": {"evaluation": "your evaluation", "score": your evaluation score}
"Evaluation": {"evaluation": "your evaluation", "score": your evaluation score}
}
"""
@@ -233,7 +239,7 @@ function progressValueEstimator(a::T1, state::T2)::Tuple{String, Integer} where
the current situation and actions that can be three types:
1) winestock[query], which you can use to find wine in your inventory.
2) chatbox[text], which you can use to interact with the user.
3) finish[answer], which returns your wine reccommendation to the user.
3) reccommendbox[answer], which returns your wine reccommendation to the user.
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
@@ -250,14 +256,17 @@ function progressValueEstimator(a::T1, state::T2)::Tuple{String, Integer} where
"Thought_2": "But there is only 1 model that has the feature customer wanted.",
"Thought_3": "I should check our inventory first to see if we have it.",
"Action_1": {"name": "inventory", "input": "Yiem model A"},
"Observation_1": "Yiem model A is in stock.",
"Evaluation_1": {"evaluation": "This trajectory is correct as it is reasonable to check an inventory for info provided in the question.
"Observation_1": "Yiem model A is in stock."
}
{
"Evaluation": {"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}
}
Let's begin!:
$(JSON3.write(state[:thoughtHistory]))
{Evaluation
"""
# apply LLM specific instruct format
@@ -292,11 +301,16 @@ function progressValueEstimator(a::T1, state::T2)::Tuple{String, Integer} where
_response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
_thoughtJsonStr = _response[:response][:text]
thoughtJsonStr = jsoncorrection(a, _thoughtJsonStr, responseformat)
expectedJsonExample =
"""
Here is an expected JSON format:
{
"Evaluation": {"evaluation": "...", "score": ...}
}
"""
thoughtJsonStr = jsoncorrection(a, _thoughtJsonStr, expectedJsonExample)
thoughtDict = copy(JSON3.read(thoughtJsonStr))
latestEvaluationKey, _ =
GeneralUtils.findHighestIndexKey(thoughtDict, "Evaluation")
evaluation = thoughtDict[latestEvaluationKey]
evaluation = thoughtDict[:Evaluation]
return evaluation[:evaluation], evaluation[:score]
end