Compare commits
10 Commits
e0b3ffa8e3
...
v0.2.6
| Author | SHA1 | Date | |
|---|---|---|---|
| 2efb016646 | |||
| 216a8bdabb | |||
| cbaa480e84 | |||
| 6cb4073e29 | |||
| 42b8f5bdb1 | |||
| 35f1482228 | |||
| b4cac4f383 | |||
| 685ee7a48f | |||
| b55ae31e5b | |||
| e8e1764bb4 |
+2
-2
@@ -759,10 +759,10 @@ uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
|
|||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
|
||||||
[[deps.SQLLLM]]
|
[[deps.SQLLLM]]
|
||||||
deps = ["CSV", "DataFrames", "DataStructures", "Dates", "FileIO", "GeneralUtils", "HTTP", "JSON", "LLMMCTS", "LibPQ", "PrettyPrinting", "Random", "Revise", "StatsBase", "Tables", "URIs", "UUIDs"]
|
deps = ["CSV", "DataFrames", "DataStructures", "Dates", "FileIO", "GeneralUtils", "HTTP", "JSON", "LibPQ", "PrettyPrinting", "Random", "Revise", "StatsBase", "Tables", "URIs", "UUIDs"]
|
||||||
path = "."
|
path = "."
|
||||||
uuid = "2ebc79c7-cc10-4a3a-9665-d2e1d61e63d3"
|
uuid = "2ebc79c7-cc10-4a3a-9665-d2e1d61e63d3"
|
||||||
version = "0.2.4"
|
version = "0.2.5"
|
||||||
|
|
||||||
[[deps.SQLStrings]]
|
[[deps.SQLStrings]]
|
||||||
git-tree-sha1 = "55de0530689832b1d3d43491ee6b67bd54d3323c"
|
git-tree-sha1 = "55de0530689832b1d3d43491ee6b67bd54d3323c"
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
name = "SQLLLM"
|
name = "SQLLLM"
|
||||||
uuid = "2ebc79c7-cc10-4a3a-9665-d2e1d61e63d3"
|
uuid = "2ebc79c7-cc10-4a3a-9665-d2e1d61e63d3"
|
||||||
version = "0.2.5"
|
version = "0.2.6"
|
||||||
authors = ["narawat lamaiin <narawat@outlook.com>"]
|
authors = ["narawat lamaiin <narawat@outlook.com>"]
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
@@ -26,4 +26,4 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
|
|||||||
Dates = "1.11.0"
|
Dates = "1.11.0"
|
||||||
GeneralUtils = "0.4.0 - 0.9.0"
|
GeneralUtils = "0.4.0 - 0.9.0"
|
||||||
JSON = "1.6.1"
|
JSON = "1.6.1"
|
||||||
LLMMCTS = "0.1.5"
|
LLMMCTS = "0.1.5 - 0.9.0"
|
||||||
|
|||||||
+51
-50
@@ -118,9 +118,9 @@ function decisionMaker(state::T1, text2textInstructLLM::Function, llmFormatName:
|
|||||||
<possible SQL for this question>
|
<possible SQL for this question>
|
||||||
$similarSQL_
|
$similarSQL_
|
||||||
</possible SQL for this question>
|
</possible SQL for this question>
|
||||||
<your earlier actions>
|
<assistant_action_history>
|
||||||
$(GeneralUtils.dict_to_string_html(state["action_history"]))
|
$(GeneralUtils.dict_to_string_html(state["action_history"]))
|
||||||
</your earlier actions>
|
</assistant_action_history>
|
||||||
<error_note>
|
<error_note>
|
||||||
$errornote
|
$errornote
|
||||||
<error_note>
|
<error_note>
|
||||||
@@ -284,14 +284,16 @@ function evaluator(state::T1, text2textInstructLLM::Function, llmFormatName::Str
|
|||||||
usermsg =
|
usermsg =
|
||||||
"""
|
"""
|
||||||
<internal_context_for_assistant>
|
<internal_context_for_assistant>
|
||||||
$(state["context"]["table_schema"])
|
<table_schema>
|
||||||
|
$(state["context"]["table_schema"])
|
||||||
|
</table_schema>
|
||||||
|
<customer question>
|
||||||
|
$(state["chathistory"][2]["content"][1]["text"])
|
||||||
|
</customer question>
|
||||||
|
<assistant_action_history>
|
||||||
|
$(GeneralUtils.dict_to_string_html(state["action_history"]))
|
||||||
|
</assistant_action_history>
|
||||||
</internal_context_for_assistant>
|
</internal_context_for_assistant>
|
||||||
<customer question>
|
|
||||||
$(state["chathistory"][2]["content"][1]["text"])
|
|
||||||
</customer question>
|
|
||||||
<trajectories>
|
|
||||||
$(GeneralUtils.dict_to_string_html(state["action_history"]))
|
|
||||||
</trajectories>
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
msg = Dict(
|
msg = Dict(
|
||||||
@@ -371,10 +373,10 @@ function evaluator(state::T1, text2textInstructLLM::Function, llmFormatName::Str
|
|||||||
state["reward"] = responsedict["score"]
|
state["reward"] = responsedict["score"]
|
||||||
end
|
end
|
||||||
|
|
||||||
println("\n--- SQLLLM evaluator() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
# println("\n--- SQLLLM evaluator() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
pprintln(responsedict)
|
# pprintln(responsedict)
|
||||||
println("---\n")
|
# println("---\n")
|
||||||
|
# error(7777)
|
||||||
return responsedict["score"]
|
return responsedict["score"]
|
||||||
end
|
end
|
||||||
error("Evaluator failed to generate an evaluation, Response: \n$response\n<|End of error|>")
|
error("Evaluator failed to generate an evaluation, Response: \n$response\n<|End of error|>")
|
||||||
@@ -596,16 +598,16 @@ function transition(state::T, args::NamedTuple
|
|||||||
end
|
end
|
||||||
|
|
||||||
newNodeKey, newstate = makeNewState(state, thoughtDict, response)
|
newNodeKey, newstate = makeNewState(state, thoughtDict, response)
|
||||||
progressvalue::Integer =
|
progressvalue::Integer = evaluatorF(newstate, text2textInstructLLM, llmFormatName)
|
||||||
if response[:success]
|
# if response[:success]
|
||||||
8 # for faster agent response. if success just skip evaluation
|
# 8 # for faster agent response. if success just skip evaluation
|
||||||
else
|
# else
|
||||||
evaluatorF(newstate, text2textInstructLLM, llmFormatName)
|
# evaluatorF(newstate, text2textInstructLLM, llmFormatName)
|
||||||
end
|
# end
|
||||||
|
|
||||||
println("\n--- SQLLLM transition() thoughtDict ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
# println("\n--- SQLLLM transition() thoughtDict ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
pprintln(thoughtDict)
|
# pprintln(thoughtDict)
|
||||||
println("---")
|
# println("---")
|
||||||
# error("SQLLLM transition() end")
|
# error("SQLLLM transition() end")
|
||||||
return (newNodeKey=newNodeKey, newstate=newstate, progressvalue=progressvalue)
|
return (newNodeKey=newNodeKey, newstate=newstate, progressvalue=progressvalue)
|
||||||
end
|
end
|
||||||
@@ -727,42 +729,41 @@ function query(query::T, executeSQL::Function, text2textInstructLLM::Function;
|
|||||||
|
|
||||||
systemmsg =
|
systemmsg =
|
||||||
"""
|
"""
|
||||||
<available_actions>
|
# database search guidelines
|
||||||
- RUNSQL, which you can use to execute SQL against the database.
|
|
||||||
action_input for this function must be a single SQL query to be executed against the database.
|
|
||||||
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 ';'.
|
|
||||||
</available_actions>
|
|
||||||
<situation>
|
|
||||||
At each round of conversation, you will be given the following:
|
|
||||||
- user question
|
|
||||||
You are working under your mentor supervision and you are also eager to improve your helpfulness.
|
|
||||||
</situation>
|
|
||||||
<objective>
|
|
||||||
Consult the database search guidelines. Then find the data from a database to satisfy the user's question.
|
|
||||||
</objective>
|
|
||||||
<your responsibility includes>
|
|
||||||
Fulfill the objective.
|
|
||||||
</your responsibility includes>
|
|
||||||
<database search guidelines>
|
|
||||||
- Keep SQL queries focused only on the provided information.
|
- Keep SQL queries focused only on the provided information.
|
||||||
- Do not create any table in the database
|
- Do not create any table in the database
|
||||||
- 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.
|
||||||
- Text information in the database usually stored in lower case. If your search returns empty, try using lower case to search.
|
- Text information in the database usually stored in lower case. If your search returns empty, try using lower case to search.
|
||||||
- If there is no search result from the database, remove the restrictive criteria until a search result is available, and proceed from there.
|
- If there is no search result from the database, remove the restrictive criteria until a search result is available, and proceed from there.
|
||||||
</database search guidelines>
|
|
||||||
<you should then respond to the user with interleaving plan, action_name, action_input>
|
# situation
|
||||||
1) plan: Based on the current situation, state a complete action plan to complete the task. Be specific.
|
At each round of conversation, you will be given the following:
|
||||||
2) action_name: (Typically corresponds to the execution of the first step in your plan) Can be one of the available_actions name
|
- user question
|
||||||
3) action_input: The input to the action you are about to perform according to your plan.
|
You are working under your mentor supervision and you are also eager to improve your helpfulness.
|
||||||
|
|
||||||
|
# objective
|
||||||
|
Consult the database search guidelines. Then find the data from a database to satisfy the user's question.
|
||||||
|
|
||||||
|
# your responsibility includes
|
||||||
|
Fulfill the objective.
|
||||||
|
|
||||||
|
# you should then respond to the user with interleaving plan, action_name, action_input
|
||||||
|
1) **plan**, Based on the current situation, state a complete action plan to complete the task and rationale. Be specific.
|
||||||
|
2) **action_name**, (Typically corresponds to the execution of the first step in your plan) Can be one of the available_actions name
|
||||||
|
3) **action_input**, The input to the action you are about to perform according to your plan.
|
||||||
After the action is executed you gets "action_result". It is the output from the action you selected.
|
After the action is executed you gets "action_result". It is the output from the action you selected.
|
||||||
</you should then respond to the user with interleaving plan, action_name, action_input>
|
|
||||||
<you should only respond in JSON format as described below>
|
# you should only respond in JSON format as described below
|
||||||
"plan": "...",
|
"plan": "...",
|
||||||
"action_name": "...",
|
"action_name": "...",
|
||||||
"action_input": "..."
|
"action_input": "..."
|
||||||
</you should only respond in JSON format as described below>
|
|
||||||
|
# available_actions
|
||||||
|
**RUNSQL**, which you can use to execute SQL against the database.
|
||||||
|
The input must be a single SQL query to be executed against the database.
|
||||||
|
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 ';'.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@@ -975,7 +976,7 @@ function query(query::T, executeSQL::Function, text2textInstructLLM::Function;
|
|||||||
end
|
end
|
||||||
|
|
||||||
println("\n--- SQLLLM query() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
println("\n--- SQLLLM query() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
|
||||||
println(resultState["result_raw"])
|
# pprintln(resultState)
|
||||||
println("---\n")
|
println("---\n")
|
||||||
|
|
||||||
return (result_str=latest_action["action_result"], result_raw=resultState["result_raw"])
|
return (result_str=latest_action["action_result"], result_raw=resultState["result_raw"])
|
||||||
@@ -1001,7 +1002,7 @@ function makeNewState(currentstate::T1, thoughtDict::T2, response::NamedTuple,
|
|||||||
if response[:success]
|
if response[:success]
|
||||||
thoughtDict["action_result"] = response[:result_str]
|
thoughtDict["action_result"] = response[:result_str]
|
||||||
else
|
else
|
||||||
error(response[:errormsg])
|
thoughtDict["action_result"] = response[:errormsg]
|
||||||
end
|
end
|
||||||
|
|
||||||
newstate = deepcopy(currentstate)
|
newstate = deepcopy(currentstate)
|
||||||
|
|||||||
Reference in New Issue
Block a user