update
This commit is contained in:
@@ -186,7 +186,7 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function,
|
|||||||
end
|
end
|
||||||
|
|
||||||
response = nothing # store for show when error msg show up
|
response = nothing # store for show when error msg show up
|
||||||
errornote = ""
|
errornote = "N/A"
|
||||||
|
|
||||||
# provide similar sql only for the first attempt
|
# provide similar sql only for the first attempt
|
||||||
similarSQL_ = "None"
|
similarSQL_ = "None"
|
||||||
@@ -220,7 +220,7 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function,
|
|||||||
Your work progress: $workprogress
|
Your work progress: $workprogress
|
||||||
Evaluation: $(state[:evaluation])
|
Evaluation: $(state[:evaluation])
|
||||||
Suggestion: $(state[:suggestion])
|
Suggestion: $(state[:suggestion])
|
||||||
$errornote
|
P.S. $errornote
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_prompt =
|
_prompt =
|
||||||
@@ -361,7 +361,7 @@ julia>
|
|||||||
|
|
||||||
# Signature
|
# Signature
|
||||||
"""
|
"""
|
||||||
function evaluator(state::T1, text2textInstructLLM::Function
|
function evaluator(state::T1, text2textInstructLLM::Function; maxattempt=10
|
||||||
) where {T1<:AbstractDict}
|
) where {T1<:AbstractDict}
|
||||||
|
|
||||||
systemmsg =
|
systemmsg =
|
||||||
@@ -432,14 +432,11 @@ function evaluator(state::T1, text2textInstructLLM::Function
|
|||||||
end
|
end
|
||||||
|
|
||||||
errornote = ""
|
errornote = ""
|
||||||
|
for attempt in 1:maxattempt
|
||||||
for attempt in 1:10
|
|
||||||
errorFlag = false
|
|
||||||
|
|
||||||
usermsg =
|
usermsg =
|
||||||
"""
|
"""
|
||||||
Trajectory: $thoughthistory
|
Trajectory: $thoughthistory
|
||||||
Error_note: $errornote
|
P.S. $errornote
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_prompt =
|
_prompt =
|
||||||
@@ -464,10 +461,12 @@ function evaluator(state::T1, text2textInstructLLM::Function
|
|||||||
# check whether response has all header
|
# check whether response has all header
|
||||||
detected_kw = GeneralUtils.detect_keyword(header, response)
|
detected_kw = GeneralUtils.detect_keyword(header, response)
|
||||||
if 0 ∈ values(detected_kw)
|
if 0 ∈ values(detected_kw)
|
||||||
errornote = "\nSQL evaluator() response does not have all header"
|
errornote = "Your previous attempt does not have all answer points"
|
||||||
|
println("\nERROR SQLLLM evaluator() Attempt $attempt/$maxattempt. $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
continue
|
continue
|
||||||
elseif sum(values(detected_kw)) > length(header)
|
elseif sum(values(detected_kw)) > length(header)
|
||||||
errornote = "\nSQL evaluator() response has duplicated header"
|
errornote = "Your previous attempt has duplicated answer point"
|
||||||
|
println("\nERROR SQLLLM evaluator() Attempt $attempt/$maxattempt. $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -478,13 +477,17 @@ function evaluator(state::T1, text2textInstructLLM::Function
|
|||||||
try
|
try
|
||||||
responsedict[:score] = parse(Int, responsedict[:score]) # convert string "5" into integer 5
|
responsedict[:score] = parse(Int, responsedict[:score]) # convert string "5" into integer 5
|
||||||
catch
|
catch
|
||||||
|
errornote = "Your previous attempt's score has wrong format"
|
||||||
|
println("\nERROR SQLLLM evaluator() Attempt $attempt/$maxattempt. $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
accepted_as_answer::AbstractString = responsedict[:accepted_as_answer]
|
accepted_as_answer::AbstractString = responsedict[:accepted_as_answer]
|
||||||
|
|
||||||
if accepted_as_answer ∉ ["Yes", "No"] # [PENDING] add errornote into the prompt
|
if accepted_as_answer ∉ ["Yes", "No"] # [PENDING] add errornote into the prompt
|
||||||
error("generated accepted_as_answer has wrong format")
|
errornote = "Your previous attempt's accepted_as_answer has wrong format"
|
||||||
|
println("\nERROR SQLLLM evaluator() Attempt $attempt/$maxattempt. $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
# add to state here instead to in transition() because the latter causes julia extension crash (a bug in julia extension)
|
# add to state here instead to in transition() because the latter causes julia extension crash (a bug in julia extension)
|
||||||
@@ -1001,13 +1004,13 @@ function query(query::T, executeSQL::Function, text2textInstructLLM::Function;
|
|||||||
root, _, resultState, highValueState =
|
root, _, resultState, highValueState =
|
||||||
LLMMCTS.runMCTS(initialstate, transition, transitionargs;
|
LLMMCTS.runMCTS(initialstate, transition, transitionargs;
|
||||||
horizontalSampleExpansionPhase=3,
|
horizontalSampleExpansionPhase=3,
|
||||||
horizontalSampleSimulationPhase=2,
|
horizontalSampleSimulationPhase=3,
|
||||||
maxSimulationDepth=5,
|
maxSimulationDepth=5,
|
||||||
maxiterations=1,
|
maxiterations=1,
|
||||||
explorationweight=1.0,
|
explorationweight=1.0,
|
||||||
earlystop=earlystop,
|
earlystop=earlystop,
|
||||||
saveSimulatedNode=true,
|
saveSimulatedNode=true,
|
||||||
multithread=true)
|
multithread=false)
|
||||||
|
|
||||||
# compare all high value state answer then select the best one
|
# compare all high value state answer then select the best one
|
||||||
if length(highValueState) > 0
|
if length(highValueState) > 0
|
||||||
@@ -1088,7 +1091,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function generatequestion(state::T1, context, text2textInstructLLM::Function;
|
function generatequestion(state::T1, context, text2textInstructLLM::Function;
|
||||||
similarSQL::Union{T2, Nothing}=nothing
|
similarSQL::Union{T2, Nothing}=nothing, maxattempt=10
|
||||||
)::String where {T1<:AbstractDict, T2<:AbstractString}
|
)::String where {T1<:AbstractDict, T2<:AbstractString}
|
||||||
|
|
||||||
similarSQL =
|
similarSQL =
|
||||||
@@ -1161,14 +1164,14 @@ function generatequestion(state::T1, context, text2textInstructLLM::Function;
|
|||||||
response = nothing # store for show when error msg show up
|
response = nothing # store for show when error msg show up
|
||||||
errornote = ""
|
errornote = ""
|
||||||
|
|
||||||
for attempt in 1:10
|
for attempt in 1:maxattempt
|
||||||
usermsg =
|
usermsg =
|
||||||
"""
|
"""
|
||||||
$(context[:tablelist])
|
$(context[:tablelist])
|
||||||
User query: $(state[:thoughtHistory][:question])
|
User query: $(state[:thoughtHistory][:question])
|
||||||
Example: $similarSQL
|
Example: $similarSQL
|
||||||
Your work progress: $workprogress
|
Your work progress: $workprogress
|
||||||
$errornote
|
P.S. $errornote
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_prompt =
|
_prompt =
|
||||||
@@ -1180,33 +1183,26 @@ function generatequestion(state::T1, context, text2textInstructLLM::Function;
|
|||||||
# put in model format
|
# put in model format
|
||||||
prompt = GeneralUtils.formatLLMtext(_prompt, "granite3")
|
prompt = GeneralUtils.formatLLMtext(_prompt, "granite3")
|
||||||
|
|
||||||
try
|
response = text2textInstructLLM(prompt, modelsize="medium")
|
||||||
response = text2textInstructLLM(prompt, modelsize="medium")
|
response = GeneralUtils.deFormatLLMtext(response, "granite3")
|
||||||
response = GeneralUtils.deFormatLLMtext(response, "granite3")
|
|
||||||
|
|
||||||
# check if response is valid
|
# check if response is valid
|
||||||
q_number = count("Q", response)
|
q_number = count("Q", response)
|
||||||
if q_number < 1
|
if q_number < 1
|
||||||
errornote = "too few question"
|
errornote = "Your previous attempt has too few question."
|
||||||
error("too few questions only $q_number questions are generated")
|
println("\nERROR YiemAgent generatequestion(). Attempt $attempt/$maxattempt. $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
end
|
continue
|
||||||
if occursin('`', response)
|
|
||||||
response = replace(response, '`'=>"")
|
|
||||||
end
|
|
||||||
|
|
||||||
responsedict = GeneralUtils.textToDict(response, header;
|
|
||||||
dictKey=dictkey, symbolkey=true)
|
|
||||||
response = "Q1: " * responsedict[:q1]
|
|
||||||
# println("\nERROR SQLLLM generatequestion() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
pprintln(Dict(responsedict))
|
|
||||||
return response
|
|
||||||
catch e
|
|
||||||
io = IOBuffer()
|
|
||||||
showerror(io, e)
|
|
||||||
errorMsg = String(take!(io))
|
|
||||||
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
|
||||||
println("\nERROR SQLLLM generatequestion() Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
|
||||||
end
|
end
|
||||||
|
if occursin('`', response)
|
||||||
|
response = replace(response, '`'=>"")
|
||||||
|
end
|
||||||
|
|
||||||
|
responsedict = GeneralUtils.textToDict(response, header;
|
||||||
|
dictKey=dictkey, symbolkey=true)
|
||||||
|
response = "Q1: " * responsedict[:q1]
|
||||||
|
println("\nSQLLLM generatequestion() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
|
pprintln(Dict(responsedict))
|
||||||
|
return response
|
||||||
end
|
end
|
||||||
error("generatequestion failed to generate a thought ", response)
|
error("generatequestion failed to generate a thought ", response)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -856,7 +856,7 @@ function compareState(question::String, highValueStateList::Vector{T},
|
|||||||
Result: 50 red wines
|
Result: 50 red wines
|
||||||
Comparison: The second attempt counts only German red wines while the first attempt includes all German wines.
|
Comparison: The second attempt counts only German red wines while the first attempt includes all German wines.
|
||||||
Rationale: The user is asking for the number of German wines without specifying a type, so the most accurate response is the first attempt because it includes all German wines.
|
Rationale: The user is asking for the number of German wines without specifying a type, so the most accurate response is the first attempt because it includes all German wines.
|
||||||
Selected_response_number: 1
|
Selected_response_number:1
|
||||||
</Here are some examples>
|
</Here are some examples>
|
||||||
|
|
||||||
Let's begin!
|
Let's begin!
|
||||||
@@ -908,6 +908,7 @@ function compareState(question::String, highValueStateList::Vector{T},
|
|||||||
"""
|
"""
|
||||||
Question: $question
|
Question: $question
|
||||||
Attempts: $potentialSolutionStr
|
Attempts: $potentialSolutionStr
|
||||||
|
P.S. $errornote
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_prompt =
|
_prompt =
|
||||||
@@ -933,21 +934,23 @@ function compareState(question::String, highValueStateList::Vector{T},
|
|||||||
for i in header
|
for i in header
|
||||||
detected = GeneralUtils.detect_keyword(i, response)
|
detected = GeneralUtils.detect_keyword(i, response)
|
||||||
if detected === nothing
|
if detected === nothing
|
||||||
errornote = "Your previous response didn't provide $i"
|
errornote = "Your previous attempt didn't provide $i"
|
||||||
errorFlag = true
|
errorFlag = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if errorFlag
|
if errorFlag
|
||||||
|
println("\nERROR SQLLLM compareState() Attempt $attempt $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
continue # skip to the next iteration
|
continue # skip to the next iteration
|
||||||
end
|
end
|
||||||
|
|
||||||
responsedict = GeneralUtils.textToDict(response, header;
|
responsedict = GeneralUtils.textToDict(response, header; dictKey=dictkey, symbolkey=true)
|
||||||
dictKey=dictkey, symbolkey=true)
|
|
||||||
|
|
||||||
responsedict[:selected_response_number] = responsedict[:selected_response_number][1] # some time "6\nThe trajectories are incomplete" is generated but I only need the number.
|
responsedict[:selected_response_number] = responsedict[:selected_response_number][1] # some time "6\nThe trajectories are incomplete" is generated but I only need the number.
|
||||||
try
|
try
|
||||||
responsedict[:selected_response_number] = parse(Int, responsedict[:selected_response_number]) # convert string "5" into integer 5
|
responsedict[:selected_response_number] = parse(Int, responsedict[:selected_response_number]) # convert string "5" into integer 5
|
||||||
catch
|
catch
|
||||||
|
errornote = "In your previous attempt, Selected_response_number was not a number. It must be a number."
|
||||||
|
println("\nERROR SQLLLM compareState() Attempt $attempt. $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user