This commit is contained in:
narawat lamaiin
2025-05-04 13:30:08 +07:00
parent 5112701dc2
commit c8f5983620
2 changed files with 44 additions and 51 deletions
+21 -28
View File
@@ -160,7 +160,6 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function, llmFo
- Text information in the database usually stored in lower case. If your search returns empty, try using lower case to search.
You should then respond to the user with interleaving Comprehension, Plan, Action_name, Action_input:
Comprehension: state your comprehension about the current situation.
Plan: Given the current circumstances, outline a detailed, step-by-step plan to accomplish the task. Be specific.
Action_name: (Typically corresponds to the execution of the first step in your plan)
Can be one of the following function names:
@@ -170,7 +169,6 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function, llmFo
4) Action_input: Input to the action
You should only respond in format as described below:
Comprehension: ...
Plan: ...
Action_name: ...
Action_input: ...
@@ -195,16 +193,15 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function, llmFo
similarSQL_ = sql !== nothing ? sql : "None"
end
header = ["Comprehension:", "Plan:", "Action_name:", "Action_input:"]
dictkey = ["comprehension", "plan", "action_name", "action_input"]
header = ["Plan:", "Action_name:", "Action_input:"]
dictkey = ["plan", "action_name", "action_input"]
llmkwargs=Dict(
:num_ctx => 32768,
:temperature => 0.1,
:temperature => 0.5,
)
for attempt in 1:maxattempt
attempt > 1 ? llmkwargs[:temperature] += 0.1 : nothing
QandA = generatequestion(state, context, text2textInstructLLM, llmFormatName; similarSQL=similarSQL_)
@@ -230,6 +227,7 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function, llmFo
prompt = GeneralUtils.formatLLMtext(_prompt, llmFormatName)
response = text2textInstructLLM(prompt; llmkwargs=llmkwargs)
response = GeneralUtils.deFormatLLMtext(response, llmFormatName)
think, response = GeneralUtils.extractthink(response)
# LLM tends to generate observation given that it is in the input
response =
@@ -376,16 +374,14 @@ function evaluator(state::T1, text2textInstructLLM::Function, llmFormatName::Str
"action_input" is the input to the action
"observation" is result of the preceding immediate action
<At each round of conversation, the user will give you>
At each round of conversation, the user will give you:
Trajectory: ...
Error_note: error note from your previous attempt
</At each round of conversation, the user will give you>
<You must follow the following guidelines>
You must follow the following guidelines:
- When the search returns no result, validate whether the SQL query makes sense before accepting it as a valid answer.
</You must follow the following guidelines>
<You should then respond to the user with>
You should then respond to the user with:
1) Trajectory_evaluation: Analyze the trajectory of a solution to answer the user's original question.
- Evaluate the correctness of each section and the overall trajectory based on the given question.
- Provide detailed reasoning and analysis, focusing on the latest thought, action, and observation.
@@ -408,16 +404,14 @@ function evaluator(state::T1, text2textInstructLLM::Function, llmFormatName::Str
- 6 indicates that the trajectory are correct, but the observation's content doesn't directly answer the question
- 8 indicates that both the trajectory are correct, and the observation's content directly answers the question.
- 9 indicates a perfect perfomance. Both the trajectory are correct, and the observation's content directly answers the question, surpassing your expectations.
5) Suggestion: if accepted_as_answer is "No", provide suggestion.
</You should then respond to the user with>
5) Suggestion: what are the possible reason of this outcome, what can you learn from it and what suggestion can made?
<You should only respond in format as described below>
You should only respond in format as described below:
Trajectory_evaluation: ...
Answer_evaluation: ...
Accepted_as_answer: ...
Score: ...
Suggestion: ...
</You should only respond in format as described below>
Let's begin!
"""
@@ -427,7 +421,7 @@ function evaluator(state::T1, text2textInstructLLM::Function, llmFormatName::Str
thoughthistory *= "$k: $v\n"
end
errornote = ""
errornote = "N/A"
for attempt in 1:maxattempt
usermsg =
"""
@@ -449,6 +443,7 @@ function evaluator(state::T1, text2textInstructLLM::Function, llmFormatName::Str
response = text2textInstructLLM(prompt, modelsize="medium")
response = GeneralUtils.deFormatLLMtext(response, llmFormatName)
think, response = GeneralUtils.extractthink(response)
# sometime LLM output something like **Comprehension**: which is not expected
response = replace(response, "**"=>"")
@@ -1004,9 +999,9 @@ function query(query::T, executeSQL::Function, text2textInstructLLM::Function;
root, _, resultState, highValueState =
LLMMCTS.runMCTS(initialstate, transition, transitionargs;
horizontalSampleExpansionPhase=3,
horizontalSampleSimulationPhase=3,
maxSimulationDepth=5,
horizontalSampleExpansionPhase=2,
horizontalSampleSimulationPhase=2,
maxSimulationDepth=3,
maxiterations=1,
explorationweight=1.0,
earlystop=earlystop,
@@ -1060,7 +1055,7 @@ function makeNewState(currentstate::T1, thoughtDict::T4, rawresponse, response::
reward::T3, isterminal::Bool
)::NamedTuple{(:newNodeKey, :newstate), Tuple{String, Dict{Symbol, <:Any}}} where {T1<:AbstractDict, T2<:AbstractString, T3<:Number, T4<:AbstractDict}
keys = [:comprehension, :action_name, :action_input, :observation]
keys = [:action_name, :action_input, :observation]
# latestKeys = []
currentstate_latestKey, currentstate_latestIndice =
@@ -1127,14 +1122,11 @@ function generatequestion(state::T1, context, text2textInstructLLM::Function,
- When querying data in the database, start with broad search terms and refine your query later for more precise results.
You should then respond to the user with:
1) Understanding:
- State your understanding about the current situation.
2) Q: Given the situation, "ask yourself" about the situation at least five, but no more than ten, questions.
3) A: Given the situation, "answer to yourself" the best you can.
1) Q: Given the situation, "ask yourself" about the situation at least three, but no more than five, questions.
2) A: Given the situation, "answer to yourself" the best you can.
- Do not generate any text after the last answer.
You must only respond in format as described below:
Understanding: ...
Q1: ...
A1: ...
Q2: ...
@@ -1154,8 +1146,8 @@ function generatequestion(state::T1, context, text2textInstructLLM::Function,
Let's begin!
"""
header = ["Understanding:", "Q1:"]
dictkey = ["understanding", "q1"]
header = ["Q1:"]
dictkey = ["q1"]
workprogress = ""
for (k, v) in state[:thoughtHistory]
@@ -1165,7 +1157,7 @@ function generatequestion(state::T1, context, text2textInstructLLM::Function,
end
response = nothing # store for show when error msg show up
errornote = ""
errornote = "N/A"
for attempt in 1:maxattempt
usermsg =
@@ -1188,6 +1180,7 @@ function generatequestion(state::T1, context, text2textInstructLLM::Function,
response = text2textInstructLLM(prompt, modelsize="medium")
response = GeneralUtils.deFormatLLMtext(response, llmFormatName)
think, response = GeneralUtils.extractthink(response)
# check if response is valid
q_number = count("Q", response)