update
This commit is contained in:
167
src/interface.jl
167
src/interface.jl
@@ -138,15 +138,17 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function,
|
|||||||
|
|
||||||
At each round of conversation, the user will give you the current situation:
|
At each round of conversation, the user will give you the current situation:
|
||||||
User Query: ...
|
User Query: ...
|
||||||
Hints: ...
|
Example: ...
|
||||||
Your Q&A: ...
|
Your Q&A: ...
|
||||||
Your work progress: ...
|
Your work progress: ...
|
||||||
Evaluation: Evaluation of the latest action and observation
|
Evaluation: Evaluation of the latest action and observation
|
||||||
Suggestion: ...
|
Suggestion: ...
|
||||||
|
|
||||||
You should consider the following guidelines:
|
You must follow the following guidelines:
|
||||||
|
- Keep SQL queries focused only on the provided information.
|
||||||
|
|
||||||
|
You should follow the following guidelines:
|
||||||
- Do not create any table in the database
|
- Do not create any table in the database
|
||||||
- Start only with the infomation the the query.
|
|
||||||
- Column name can be the same in different tables. Refer to column comments to get more details by using TABLEINFO function
|
- Column name can be the same in different tables. Refer to column comments to get more details by using TABLEINFO function
|
||||||
- A junction table can be used to link tables together. Another use case is for filtering data.
|
- A junction table can be used to link tables together. Another use case is for filtering data.
|
||||||
- If you can't find a single table that can be used to answer the user's query, try joining multiple tables to see if you can obtain the answer.
|
- If you can't find a single table that can be used to answer the user's query, try joining multiple tables to see if you can obtain the answer.
|
||||||
@@ -161,7 +163,7 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function,
|
|||||||
3) Plan: Given the current circumstances, outline a detailed, step-by-step plan to accomplish the task. Be specific.
|
3) Plan: Given the current circumstances, outline a detailed, step-by-step plan to accomplish the task. Be specific.
|
||||||
4) Action_name (Must be aligned with your plan): Can be one of the following functions:
|
4) Action_name (Must be aligned with your plan): Can be one of the following functions:
|
||||||
- TABLEINFO[list_of_table_name], which you can use to get the data type of a table column. "list_of_table_name" is a list of table name you want to get info. e.g. TABLEINFO["table name 1", "table name 2"]
|
- TABLEINFO[list_of_table_name], which you can use to get the data type of a table column. "list_of_table_name" is a list of table name you want to get info. e.g. TABLEINFO["table name 1", "table name 2"]
|
||||||
- GETDATA[SQL], which you can use to get the data from the database. "SQL" is the single SQL command to be executed against the database.
|
- GETDATA[SQL], which you can use to get the data from the database. "SQL" is a single SQL command to be executed against the database.
|
||||||
For more effective text search, it's necessary to use case-insensitivity and the ILIKE operator.
|
For more effective text search, it's necessary to use case-insensitivity and the ILIKE operator.
|
||||||
Do not wrap the SQL as it will be executed against the database directly and SQL must be ended with ';'.
|
Do not wrap the SQL as it will be executed against the database directly and SQL must be ended with ';'.
|
||||||
5) Action_input: Input to the action
|
5) Action_input: Input to the action
|
||||||
@@ -173,7 +175,6 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function,
|
|||||||
Plan: ...
|
Plan: ...
|
||||||
Action_name: ...
|
Action_name: ...
|
||||||
Action_input: ...
|
Action_input: ...
|
||||||
Observation: ...
|
|
||||||
|
|
||||||
Let's begin!
|
Let's begin!
|
||||||
"""
|
"""
|
||||||
@@ -203,7 +204,7 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function,
|
|||||||
"""
|
"""
|
||||||
$(context[:tablelist])
|
$(context[:tablelist])
|
||||||
User query: $(state[:thoughtHistory][:question])
|
User query: $(state[:thoughtHistory][:question])
|
||||||
Hints: $similarSQL_
|
Example: $similarSQL_
|
||||||
Your Q&A: $QandA
|
Your Q&A: $QandA
|
||||||
Your work progress: $workprogress
|
Your work progress: $workprogress
|
||||||
Evaluation: $(state[:evaluation])
|
Evaluation: $(state[:evaluation])
|
||||||
@@ -224,104 +225,74 @@ function decisionMaker(state::T1, context, text2textInstructLLM::Function,
|
|||||||
<|start_header_id|>assistant<|end_header_id|>
|
<|start_header_id|>assistant<|end_header_id|>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# try
|
try
|
||||||
# response = text2textInstructLLM(prompt)
|
response = text2textInstructLLM(prompt)
|
||||||
|
println("\nSQL decisionMaker() rawresponse: ", response)
|
||||||
|
|
||||||
# # textToDict() search for action_input
|
header = ["Understanding", "Reasoning", "Plan", "Action_name", "Action_input", "Observation"]
|
||||||
# responsedict = GeneralUtils.textToDict(response,
|
|
||||||
# ["Understanding", "Reasoning", "Plan", "Action_name", "Action_input", "Observation"],
|
|
||||||
# rightmarker=":", symbolkey=true, lowercasekey=true)
|
|
||||||
|
|
||||||
# delete!(responsedict, :observation)
|
# detect if there are more than 1 key per categories
|
||||||
|
count = GeneralUtils.countGivenWords(response, header)
|
||||||
# # [WORKING] remove backticks Error occurred: MethodError: no method matching occursin(::String, ::Vector{String})
|
if sum(count) > length(header)
|
||||||
# if occursin("```", responsedict[:action_input])
|
error("duplicated words", @__FILE__, " ", @__LINE__)
|
||||||
# responsedict[:action_input] =
|
|
||||||
# GeneralUtils.extract_triple_backtick_text(responsedict[:action_input])
|
|
||||||
# end
|
|
||||||
|
|
||||||
# toollist = ["TABLEINFO", "GETDATA"]
|
|
||||||
# if responsedict[:action_name] ∉ toollist
|
|
||||||
# error("SQL decisionMaker() didn't use the given functions ", @__FILE__, " ", @__LINE__)
|
|
||||||
# end
|
|
||||||
|
|
||||||
# for i in toollist
|
|
||||||
# if occursin(i, responsedict[:action_input])
|
|
||||||
# error("Action_name is in action_input which is not allowed.")
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# for i ∈ [:understanding, :reasoning, :plan, :action_name, :action_input]
|
|
||||||
# if length(JSON3.write(responsedict[i])) == 0
|
|
||||||
# error("$i is empty ", @__FILE__, " ", @__LINE__)
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # check if there are more than 1 key per categories
|
|
||||||
# for i ∈ [:understanding, :reasoning, :plan, :action_name, :action_input]
|
|
||||||
# matchkeys = GeneralUtils.findMatchingDictKey(responsedict, i)
|
|
||||||
# if length(matchkeys) > 1
|
|
||||||
# error("DecisionMaker has more than one key per categories")
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# state[:decisionMaker] = responsedict
|
|
||||||
|
|
||||||
# return responsedict
|
|
||||||
# catch e
|
|
||||||
# io = IOBuffer()
|
|
||||||
# showerror(io, e)
|
|
||||||
# errorMsg = String(take!(io))
|
|
||||||
# st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
|
||||||
# println("")
|
|
||||||
# println("\n~~~ SQLLLM decisionMaker() Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
|
|
||||||
# println("")
|
|
||||||
# end
|
|
||||||
|
|
||||||
response = text2textInstructLLM(prompt)
|
|
||||||
println("SQL decisionMaker() rawresponse: ", response)
|
|
||||||
|
|
||||||
# textToDict() search for action_input
|
|
||||||
responsedict = GeneralUtils.textToDict(response,
|
|
||||||
["Understanding", "Reasoning", "Plan", "Action_name", "Action_input", "Observation"],
|
|
||||||
rightmarker=":", symbolkey=true, lowercasekey=true)
|
|
||||||
|
|
||||||
delete!(responsedict, :observation)
|
|
||||||
|
|
||||||
# [WORKING] remove backticks Error occurred: MethodError: no method matching occursin(::String, ::Vector{String})
|
|
||||||
if occursin("```", responsedict[:action_input])
|
|
||||||
responsedict[:action_input] =
|
|
||||||
GeneralUtils.extract_triple_backtick_text(responsedict[:action_input])
|
|
||||||
end
|
|
||||||
|
|
||||||
toollist = ["TABLEINFO", "GETDATA"]
|
|
||||||
if responsedict[:action_name] ∉ toollist
|
|
||||||
error("SQL decisionMaker() didn't use the given functions ", @__FILE__, " ", @__LINE__)
|
|
||||||
end
|
|
||||||
|
|
||||||
for i in toollist
|
|
||||||
if occursin(i, responsedict[:action_input])
|
|
||||||
error("Action_name is in action_input which is not allowed.")
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for i ∈ [:understanding, :reasoning, :plan, :action_name, :action_input]
|
# textToDict() search for action_input
|
||||||
if length(JSON3.write(responsedict[i])) == 0
|
responsedict = GeneralUtils.textToDict(response, header,
|
||||||
error("$i is empty ", @__FILE__, " ", @__LINE__)
|
rightmarker=":", symbolkey=true, lowercasekey=true)
|
||||||
|
|
||||||
|
delete!(responsedict, :observation)
|
||||||
|
|
||||||
|
# remove backticks Error occurred: MethodError: no method matching occursin(::String, ::Vector{String})
|
||||||
|
if occursin("```", responsedict[:action_input])
|
||||||
|
sql = GeneralUtils.extract_triple_backtick_text(responsedict[:action_input])[1]
|
||||||
|
if sql[1:4] == "sql\n"
|
||||||
|
sql = sql[5:end]
|
||||||
|
end
|
||||||
|
sql = split(sql, ';') # some time there are comments in the sql
|
||||||
|
sql = sql[1] * ';'
|
||||||
|
|
||||||
|
responsedict[:action_input] = sql
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# check if there are more than 1 key per categories
|
toollist = ["TABLEINFO", "GETDATA"]
|
||||||
for i ∈ [:understanding, :reasoning, :plan, :action_name, :action_input]
|
if responsedict[:action_name] ∉ toollist
|
||||||
matchkeys = GeneralUtils.findMatchingDictKey(responsedict, i)
|
error("SQL decisionMaker() didn't use the given functions ", @__FILE__, " ", @__LINE__)
|
||||||
if length(matchkeys) > 1
|
|
||||||
error("DecisionMaker has more than one key per categories")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for i in toollist
|
||||||
|
if occursin(i, responsedict[:action_input])
|
||||||
|
error("Action_name is in action_input which is not allowed.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for i ∈ [:understanding, :reasoning, :plan, :action_name, :action_input]
|
||||||
|
if length(JSON3.write(responsedict[i])) == 0
|
||||||
|
error("$i is empty ", @__FILE__, " ", @__LINE__)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# check if there are more than 1 key per categories
|
||||||
|
for i ∈ [:understanding, :reasoning, :plan, :action_name, :action_input]
|
||||||
|
matchkeys = GeneralUtils.findMatchingDictKey(responsedict, i)
|
||||||
|
if length(matchkeys) > 1
|
||||||
|
error("DecisionMaker has more than one key per categories")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
state[:decisionMaker] = responsedict
|
||||||
|
|
||||||
|
return responsedict
|
||||||
|
catch e
|
||||||
|
io = IOBuffer()
|
||||||
|
showerror(io, e)
|
||||||
|
errorMsg = String(take!(io))
|
||||||
|
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
|
||||||
|
println("")
|
||||||
|
println("\n~~~ SQLLLM decisionMaker() Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
|
||||||
|
println("")
|
||||||
end
|
end
|
||||||
|
|
||||||
state[:decisionMaker] = responsedict
|
|
||||||
|
|
||||||
return responsedict
|
|
||||||
end
|
end
|
||||||
error("DecisionMaker failed to generate a thought ", response)
|
error("DecisionMaker failed to generate a thought ", response)
|
||||||
end
|
end
|
||||||
@@ -1068,7 +1039,7 @@ function generatequestion(state::T1, context, text2textInstructLLM::Function;
|
|||||||
|
|
||||||
At each round of conversation, the user will give you the current situation:
|
At each round of conversation, the user will give you the current situation:
|
||||||
User query: ...
|
User query: ...
|
||||||
Hints: ...
|
Example: ...
|
||||||
Your work progress: ...
|
Your work progress: ...
|
||||||
|
|
||||||
About the tables in the database:
|
About the tables in the database:
|
||||||
@@ -1082,7 +1053,7 @@ function generatequestion(state::T1, context, text2textInstructLLM::Function;
|
|||||||
3) Some information can be accessed by joining multiple tables.
|
3) Some information can be accessed by joining multiple tables.
|
||||||
4) Do not generate any question or comments at the end.
|
4) Do not generate any question or comments at the end.
|
||||||
|
|
||||||
You should consider the following guidelines:
|
You should follow the following guidelines:
|
||||||
- When querying data in the database, start with broad search terms and refine your query later for more precise results.
|
- 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:
|
You should then respond to the user with:
|
||||||
@@ -1128,7 +1099,7 @@ function generatequestion(state::T1, context, text2textInstructLLM::Function;
|
|||||||
"""
|
"""
|
||||||
$(context[:tablelist])
|
$(context[:tablelist])
|
||||||
User query: $(state[:thoughtHistory][:question])
|
User query: $(state[:thoughtHistory][:question])
|
||||||
Hints: $similarSQL
|
Example: $similarSQL
|
||||||
Your work progress: $workprogress
|
Your work progress: $workprogress
|
||||||
$errornote
|
$errornote
|
||||||
$noise
|
$noise
|
||||||
|
|||||||
Reference in New Issue
Block a user