update
This commit is contained in:
+13
-40
@@ -2,7 +2,7 @@ module interface
|
||||
|
||||
export decisionMaker, evaluator, reflector, transition, query
|
||||
|
||||
using LibPQ, DataStructures, JSON3, UUIDs, PrettyPrinting, Dates
|
||||
using LibPQ, DataStructures, JSON, UUIDs, PrettyPrinting, Dates
|
||||
using GeneralUtils, LLMMCTS
|
||||
using ..util, ..llmfunction
|
||||
|
||||
@@ -106,33 +106,6 @@ function decisionMaker(state::T1, additionalinfo, text2textInstructLLM::Function
|
||||
; querySQLVectorDBF::Union{T2, Nothing}=nothing, maxattempt=10
|
||||
)::Dict{String, Any} where {T1<:AbstractDict, T2<:Function}
|
||||
|
||||
# lessonDict =
|
||||
# if isfile("lesson.json")
|
||||
# lessonDict = copy(JSON3.read("lesson.json"))
|
||||
# else
|
||||
# lessonDict = nothing
|
||||
# end
|
||||
|
||||
# lessonDict = nothing
|
||||
|
||||
# lesson =
|
||||
# if lessonDict === nothing
|
||||
# ""
|
||||
# else
|
||||
# """
|
||||
# You have attempted to help the user before and failed, either because your reasoning for the
|
||||
# recommendation was incorrect or your response did not exactly match the user expectation.
|
||||
# The following lesson(s) give a plan to avoid failing to help the user in the same way you
|
||||
# did previously. Use them to improve your strategy to help the user.
|
||||
|
||||
# Here are some lessons in JSON format:
|
||||
# $(JSON3.write(lessonDict))
|
||||
|
||||
# When providing the thought and action for the current trial, that into account these failed
|
||||
# trajectories and make sure not to repeat the same mistakes and incorrect answers.
|
||||
# """
|
||||
# end
|
||||
|
||||
systemmsg =
|
||||
"""
|
||||
You are a helpful assistant that find the data from a database to satisfy the user's question.
|
||||
@@ -188,7 +161,7 @@ similarSQL_ = "None"
|
||||
if length(state["thoughtHistory"]) == 1
|
||||
sql, distance = querySQLVectorDBF(state["thoughtHistory"]["question"])
|
||||
similarSQL_ = sql !== nothing ? sql : "None"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for attempt in 1:maxattempt
|
||||
@@ -211,7 +184,7 @@ similarSQL_ = "None"
|
||||
$workprogress
|
||||
</progress>
|
||||
<suggestion> This is your mentor's suggestion for the immediately preceding action and observation
|
||||
$(state["suggestion"])
|
||||
$(state["suggestion"])
|
||||
</suggestion>
|
||||
P.S. $errornote
|
||||
</context>
|
||||
@@ -239,7 +212,7 @@ $(state["suggestion"])
|
||||
|
||||
responsedict = nothing
|
||||
try
|
||||
responsedict = copy(JSON3.read(response))
|
||||
responsedict = copy(JSON.parse(response))
|
||||
catch
|
||||
println("\nERROR YiemAgent generatechat() failed to parse response: $response", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||
continue
|
||||
@@ -307,10 +280,10 @@ responsedict["thoughthistory"] = state["thoughtHistory"]
|
||||
responsedict["system"] = systemmsg
|
||||
responsedict["prompt"] = prompt
|
||||
responsedict["context"] = context
|
||||
responsedict["think"] = think
|
||||
responsedict["think"] = think
|
||||
|
||||
# # read sessionId
|
||||
# sessionid = JSON3.read("/appfolder/app/sessionid.json")
|
||||
# sessionid = JSON.parse("/appfolder/app/sessionid.json")
|
||||
# # save to filename ./log/decisionlog.txt
|
||||
# println("saving SQLLLM decisionMaker() to disk")
|
||||
# filename = "agent_decision_log_$(sessionid[:id]).json"
|
||||
@@ -324,7 +297,7 @@ responsedict["thoughthistory"] = state["thoughtHistory"]
|
||||
# end
|
||||
# else
|
||||
# # read the file and append new data
|
||||
# decisionlist = copy(JSON3.read(filepath))
|
||||
# decisionlist = copy(JSON.parse(filepath))
|
||||
# push!(decisionlist, responsedict)
|
||||
# println("Appending new data to file $filepath")
|
||||
# open(filepath, "w") do io
|
||||
@@ -343,7 +316,7 @@ end
|
||||
|
||||
# # lessonDict =
|
||||
# # if isfile("lesson.json")
|
||||
# # lessonDict = copy(JSON3.read("lesson.json"))
|
||||
# # lessonDict = copy(JSON.parse("lesson.json"))
|
||||
# # else
|
||||
# # lessonDict = nothing
|
||||
# # end
|
||||
@@ -754,7 +727,7 @@ function evaluator(state::T1, thoughtDict, text2textInstructLLM::Function, llmFo
|
||||
# responsedict[:think] = think
|
||||
|
||||
# # read sessionId
|
||||
# sessionid = JSON3.read("/appfolder/app/sessionid.json")
|
||||
# sessionid = JSON.parse("/appfolder/app/sessionid.json")
|
||||
# # save to filename ./log/decisionlog.txt
|
||||
# println("saving SQLLLM evaluator() to disk")
|
||||
# filename = "agent_evaluator_log_$(sessionid[:id]).json"
|
||||
@@ -768,7 +741,7 @@ function evaluator(state::T1, thoughtDict, text2textInstructLLM::Function, llmFo
|
||||
# end
|
||||
# else
|
||||
# # read the file and append new data
|
||||
# decisionlist = copy(JSON3.read(filepath))
|
||||
# decisionlist = copy(JSON.parse(filepath))
|
||||
# push!(decisionlist, responsedict)
|
||||
# println("Appending new data to file $filepath")
|
||||
# open(filepath, "w") do io
|
||||
@@ -917,7 +890,7 @@ function reflector(config::T1, state::T2)::String where {T1<:AbstractDict, T2<:A
|
||||
error("Not valid JSON")
|
||||
end
|
||||
|
||||
reflectionDict = copy(JSON3.read(responseJsonStr))
|
||||
reflectionDict = copy(JSON.parse(responseJsonStr))
|
||||
|
||||
# check if dict has all required value
|
||||
dummya::AbstractString = reflectionDict[:reflection]
|
||||
@@ -1295,7 +1268,7 @@ function query(query::T, executeSQL::Function, text2textInstructLLM::Function;
|
||||
end
|
||||
latestKey, latestInd = GeneralUtils.findHighestIndexKey(resultState[:thoughtHistory], "observation")
|
||||
action_input = "action_input_$latestInd" # latest sql
|
||||
sql = resultState["thoughtHistory"][action_input]
|
||||
sql = resultState["thoughtHistory"][action_input]
|
||||
extractedTableContent = resultState["thoughtHistory"][latestKey]
|
||||
|
||||
# add to vectorDB only if the answer is achieved and the state is terminal
|
||||
@@ -1355,7 +1328,7 @@ function makeNewState(currentstate::T1, thoughtDict::T4, rawresponse, response::
|
||||
newstate["reward"] = reward
|
||||
newstate["select"] = select
|
||||
newstate["isterminal"] = isterminal
|
||||
newstate["rawresponse"] = rawresponse # whatever return from action
|
||||
newstate["rawresponse"] = rawresponse # whatever return from action
|
||||
|
||||
newNodeKey = GeneralUtils.uuid4snakecase()
|
||||
|
||||
|
||||
+7
-7
@@ -3,7 +3,7 @@ module llmfunction
|
||||
export listAllTable_json, listAllTable_str, tableinfo, getdata, finalAnswerBox,
|
||||
getTableNameFromSQL, extractContent_dataframe, SQLexecution, compareState
|
||||
|
||||
using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs, LibPQ, Tables, DataFrames, CSV,
|
||||
using HTTP, JSON, URIs, Random, PrettyPrinting, UUIDs, LibPQ, Tables, DataFrames, CSV,
|
||||
DataStructures, StatsBase, Dates
|
||||
using GeneralUtils, LLMMCTS
|
||||
using ..util
|
||||
@@ -189,7 +189,7 @@ function tableinfo(executeSQL::Function, tablenames::T
|
||||
end
|
||||
end
|
||||
if !isempty(notExistingTable)
|
||||
result = "Error, the following tables does not exist in the database: $(JSON3.write(notExistingTable))"
|
||||
result = "Error, the following tables does not exist in the database: $(JSON.json(notExistingTable))"
|
||||
return (result=result,)
|
||||
end
|
||||
|
||||
@@ -297,7 +297,7 @@ context = args["context"]
|
||||
result["thought"], result["code"]
|
||||
else
|
||||
nothing, state["question"]
|
||||
end
|
||||
end
|
||||
|
||||
# make new state
|
||||
newNodeKey = GeneralUtils.uuid4snakecase()
|
||||
@@ -319,7 +319,7 @@ newstate["code"] = sql
|
||||
newstate["errorexplain"] = thought
|
||||
newstate["errormsg"] = errormsg
|
||||
newstate["reward"] = reward
|
||||
newstate["isterminal"] = isterminal
|
||||
newstate["isterminal"] = isterminal
|
||||
if response !== nothing
|
||||
extracted = extractContent_dataframe(response, context, text2textInstructLLM)
|
||||
newstate["response"] = extracted
|
||||
@@ -779,7 +779,7 @@ function getTableNameFromSQL(sql::T, text2textInstructLLM::Function,
|
||||
response = GeneralUtils.deFormatLLMtext(response, llmFormatName)
|
||||
responsedict = GeneralUtils.textToDict(response, header;
|
||||
dictKey=dictkey, symbolkey=false)
|
||||
response = copy(JSON3.read(responsedict["table_name"]))
|
||||
response = copy(JSON.parse(responsedict["table_name"]))
|
||||
|
||||
return response
|
||||
catch e
|
||||
@@ -876,7 +876,7 @@ potentialSolution = []
|
||||
d[v] = thoughtHistory[latestKeys[i]]
|
||||
end
|
||||
push!(potentialSolution, d)
|
||||
end
|
||||
end
|
||||
|
||||
"""
|
||||
# put potential solutions from potentialSolution into the following form
|
||||
@@ -948,7 +948,7 @@ potentialSolution = []
|
||||
|
||||
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"] = 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())")
|
||||
|
||||
Reference in New Issue
Block a user