use string key for dict
This commit is contained in:
+49
-49
@@ -287,17 +287,17 @@ function getdata_transition(state::T, args::NamedTuple
|
||||
# decisionMaker::Function = args[:decisionMaker]
|
||||
# evaluator::Function = args[:evaluator]
|
||||
# reflector::Function = args[:reflector]
|
||||
context = args[:context]
|
||||
executeSQL::Function = args[:executeSQL]
|
||||
text2textInstructLLM::Function = args[:text2textInstructLLM]
|
||||
context = args["context"]
|
||||
executeSQL::Function = args["executeSQL"]
|
||||
text2textInstructLLM::Function = args["text2textInstructLLM"]
|
||||
|
||||
thought, sql =
|
||||
if state[:code] !== nothing
|
||||
result = getdata_decisionMaker(state, context, text2textInstructLLM)
|
||||
result[:thought], result[:code]
|
||||
else
|
||||
nothing, state[:question]
|
||||
end
|
||||
thought, sql =
|
||||
if state["code"] !== nothing
|
||||
result = getdata_decisionMaker(state, context, text2textInstructLLM)
|
||||
result["thought"], result["code"]
|
||||
else
|
||||
nothing, state["question"]
|
||||
end
|
||||
|
||||
# make new state
|
||||
newNodeKey = GeneralUtils.uuid4snakecase()
|
||||
@@ -314,15 +314,15 @@ function getdata_transition(state::T, args::NamedTuple
|
||||
isterminal=false)
|
||||
end
|
||||
println("getdata_transition() 1 ", @__FILE__, " ", @__LINE__)
|
||||
newstate[:code] = sql
|
||||
newstate[:response] = response
|
||||
newstate[:errorexplain] = thought
|
||||
newstate[:errormsg] = errormsg
|
||||
newstate[:reward] = reward
|
||||
newstate[:isterminal] = isterminal
|
||||
newstate["code"] = sql
|
||||
newstate["response"] = response
|
||||
newstate["errorexplain"] = thought
|
||||
newstate["errormsg"] = errormsg
|
||||
newstate["reward"] = reward
|
||||
newstate["isterminal"] = isterminal
|
||||
if response !== nothing
|
||||
extracted = extractContent_dataframe(response, context, text2textInstructLLM)
|
||||
newstate[:response] = extracted
|
||||
newstate["response"] = extracted
|
||||
end
|
||||
println("getdata_transition() 2 ", @__FILE__, " ", @__LINE__)
|
||||
stateevaluation = "None"
|
||||
@@ -389,10 +389,10 @@ function getdata_decisionMaker(state::Dict, context::Dict, text2textInstructLLM:
|
||||
for attempt in 1:10
|
||||
usermsg = """
|
||||
Context:
|
||||
$(context[:mentionedTableInfo])
|
||||
User intention: $(context[:userintention])
|
||||
Code executed from the last round: $(state[:code])
|
||||
Execution error: $(state[:errormsg])
|
||||
$(context["mentionedTableInfo"])
|
||||
User intention: $(context["userintention"])
|
||||
Code executed from the last round: $(state["code"])
|
||||
Execution error: $(state["errormsg"])
|
||||
$noise
|
||||
$note_flag
|
||||
"""
|
||||
@@ -414,13 +414,13 @@ function getdata_decisionMaker(state::Dict, context::Dict, text2textInstructLLM:
|
||||
dictkey = ["plan", "code"]
|
||||
|
||||
responsedict = GeneralUtils.textToDict(response, header;
|
||||
dictKey=dictkey, symbolkey=true)
|
||||
_code = responsedict[:code]
|
||||
dictKey=dictkey, symbolkey=false)
|
||||
_code = responsedict["code"]
|
||||
code = strip(_code)
|
||||
|
||||
if length(code) < 2
|
||||
error("No code available.")
|
||||
elseif code == state[:code]
|
||||
elseif code == state["code"]
|
||||
error("generated code is the same as earlier.")
|
||||
else
|
||||
end
|
||||
@@ -440,7 +440,7 @@ function getdata_decisionMaker(state::Dict, context::Dict, text2textInstructLLM:
|
||||
|
||||
println("\n~~~ getdata_decisionMaker() ", @__FILE__, " ", @__LINE__)
|
||||
pprintln(Dict(responsedict))
|
||||
return (thought=responsedict[:comprehension], code=code, success=true, errormsg=nothing)
|
||||
return (thought=responsedict["comprehension"], code=code, success=true, errormsg=nothing)
|
||||
catch e
|
||||
io = IOBuffer()
|
||||
showerror(io, e)
|
||||
@@ -651,12 +651,12 @@ function extractContent_dataframe(df::DataFrame, text2textInstructLLM::Function,
|
||||
end
|
||||
|
||||
responsedict = GeneralUtils.textToDict(response, header;
|
||||
dictKey=dictkey, symbolkey=true)
|
||||
dictKey=dictkey, symbolkey=false)
|
||||
|
||||
# result = dfstr
|
||||
result =
|
||||
"""
|
||||
Summary: $(responsedict[:search_summary])
|
||||
Summary: $(responsedict["search_summary"])
|
||||
More details: $dfstr
|
||||
"""
|
||||
|
||||
@@ -778,8 +778,8 @@ function getTableNameFromSQL(sql::T, text2textInstructLLM::Function,
|
||||
response = text2textInstructLLM(prompt, modelsize="medium")
|
||||
response = GeneralUtils.deFormatLLMtext(response, llmFormatName)
|
||||
responsedict = GeneralUtils.textToDict(response, header;
|
||||
dictKey=dictkey, symbolkey=true)
|
||||
response = copy(JSON3.read(responsedict[:table_name]))
|
||||
dictKey=dictkey, symbolkey=false)
|
||||
response = copy(JSON3.read(responsedict["table_name"]))
|
||||
|
||||
return response
|
||||
catch e
|
||||
@@ -862,21 +862,21 @@ function compareState(question::String, highValueStateList::Vector{T},
|
||||
Let's begin!
|
||||
"""
|
||||
|
||||
potentialSolution = []
|
||||
keys = [:action_input, :observation]
|
||||
# extract the last action_name, action_input, observation of each state in highValueStateList and store them in a dictionary then push into potentialSolution
|
||||
for state in highValueStateList
|
||||
thoughtHistory = state[:thoughtHistory]
|
||||
_, currentstate_latestIndice =
|
||||
GeneralUtils.findHighestIndexKey(thoughtHistory, keys[1])
|
||||
latestKeys = makekey.(keys, currentstate_latestIndice)
|
||||
d = Dict()
|
||||
# get the last action_name, action_input, observation of currentstate
|
||||
for (i,v) in enumerate(keys)
|
||||
d[v] = thoughtHistory[latestKeys[i]]
|
||||
end
|
||||
push!(potentialSolution, d)
|
||||
end
|
||||
potentialSolution = []
|
||||
keys = ["action_input", "observation"]
|
||||
# extract the last action_name, action_input, observation of each state in highValueStateList and store them in a dictionary then push into potentialSolution
|
||||
for state in highValueStateList
|
||||
thoughtHistory = state["thoughtHistory"]
|
||||
_, currentstate_latestIndice =
|
||||
GeneralUtils.findHighestIndexKey(thoughtHistory, keys[1])
|
||||
latestKeys = makekey.(keys, currentstate_latestIndice)
|
||||
d = Dict()
|
||||
# get the last action_name, action_input, observation of currentstate
|
||||
for (i,v) in enumerate(keys)
|
||||
d[v] = thoughtHistory[latestKeys[i]]
|
||||
end
|
||||
push!(potentialSolution, d)
|
||||
end
|
||||
|
||||
"""
|
||||
# put potential solutions from potentialSolution into the following form
|
||||
@@ -944,11 +944,11 @@ function compareState(question::String, highValueStateList::Vector{T},
|
||||
continue
|
||||
end
|
||||
|
||||
responsedict = GeneralUtils.textToDict(response, header; dictKey=dictkey, symbolkey=true)
|
||||
responsedict = GeneralUtils.textToDict(response, header; dictKey=dictkey, symbolkey=false)
|
||||
|
||||
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
|
||||
responsedict[:selected_response_number] = parse(Int, responsedict[:selected_response_number]) # convert string "5" into integer 5
|
||||
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
|
||||
responsedict["selected_response_number"] = parse(Int, responsedict["selected_response_number"]) # convert string "5" into integer 5
|
||||
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())")
|
||||
@@ -958,7 +958,7 @@ function compareState(question::String, highValueStateList::Vector{T},
|
||||
println("\n~~~ compareState() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||
pprintln(Dict(responsedict))
|
||||
|
||||
return responsedict[:selected_response_number]
|
||||
return responsedict["selected_response_number"]
|
||||
end
|
||||
error("compareState() failed to generate an evaluation, Response: \n$response\n<|End of error|>", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user