feat(ChatDB): ChatDB Use fintune model

1.Compatible with community pure sql output model
This commit is contained in:
yhjun1026 2023-11-14 20:12:27 +08:00
parent 18883ec56a
commit aaddde87fd
59 changed files with 262 additions and 248 deletions

View File

@ -206,6 +206,10 @@ class BaseOutputParser(ABC):
if not cleaned_output.startswith("{") or not cleaned_output.endswith("}"):
logger.info("illegal json processing:\n" + cleaned_output)
cleaned_output = self.__extract_json(cleaned_output)
if not cleaned_output or len(cleaned_output) <=0:
return model_out_text
cleaned_output = (
cleaned_output.strip()
.replace("\\n", " ")

View File

@ -72,7 +72,7 @@ class ChatWithDbAutoExecute(BaseChat):
)
input_values = {
# "input": self.current_user_input,
"user_input": self.current_user_input,
"top_k": str(self.top_k),
"dialect": self.database.dialect,
"table_info": table_infos,

View File

@ -27,7 +27,7 @@ class DbChatOutputParser(BaseOutputParser):
def __init__(self, sep: str, is_stream_out: bool):
super().__init__(sep=sep, is_stream_out=is_stream_out)
def is_sql_statement(statement):
def is_sql_statement(self, statement):
parsed = sqlparse.parse(statement)
if not parsed:
return False
@ -43,13 +43,17 @@ class DbChatOutputParser(BaseOutputParser):
if self.is_sql_statement(clean_str):
return SqlAction(clean_str, "")
else:
response = json.loads(clean_str)
for key in sorted(response):
if key.strip() == "sql":
sql = response[key]
if key.strip() == "thoughts":
thoughts = response[key]
return SqlAction(sql, thoughts)
try:
response = json.loads(clean_str)
for key in sorted(response):
if key.strip() == "sql":
sql = response[key]
if key.strip() == "thoughts":
thoughts = response[key]
return SqlAction(sql, thoughts)
except Exception as e:
logging.error("json load faild")
return SqlAction("", clean_str)
def parse_view_response(self, speak, data, prompt_response) -> str:
@ -57,6 +61,9 @@ class DbChatOutputParser(BaseOutputParser):
api_call_element = ET.Element("chart-view")
err_msg = None
try:
if not prompt_response.sql or len(prompt_response.sql) <=0:
return f""" <span style=\"color:red\">[Unresolvable return]</span>\n{speak}"""
df = data(prompt_response.sql)
param["type"] = "response_table"
param["sql"] = prompt_response.sql

View File

@ -22,6 +22,8 @@ Constraint:
3.Use as few tables as possible when querying.
4.Please check the correctness of the SQL and ensure that the query performance is optimized under correct conditions.
User Question:
{user_input}
Please think step by step and respond according to the following JSON format:
{response}
Ensure the response is correct json and can be parsed by Python json.loads.
@ -37,7 +39,8 @@ _DEFAULT_TEMPLATE_ZH = """
2. 只能使用表结构信息中提供的表来生成 sql如果无法根据提供的表结构中生成 sql 请说提供的表结构信息不足以生成 sql 查询 禁止随意捏造信息
3. 请注意生成SQL时不要弄错表和列的关系
4. 请检查SQL的正确性并保证正确的情况下优化查询性能
用户问题:
{user_input}
请一步步思考并按照以下JSON格式回复
{response}
确保返回正确的json并且可以被Python json.loads方法解析.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 21 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
.model-tab:before{content:"";position:absolute;left:.4rem;width:45%;height:80%;background-color:#ffc800;border-radius:2rem;transition:all .4s}.editor-tab:before{left:calc(50%)}

View File

@ -1 +0,0 @@
.model-tab:before{content:"";position:absolute;left:.4rem;width:45%;height:80%;background-color:#ffc800;border-radius:2rem;transition:all .4s}.editor-tab:before{left:calc(50%)}.auto-chart-header{padding:12px 0;&-title{font-weight:500;font-size:16px}&-toolbar{display:flex;align-items:center;&>*{margin-left:8px}}}

View File

@ -1 +0,0 @@
.auto-chart-header{padding:12px 0;&-title{font-weight:500;font-size:16px}&-toolbar{display:flex;align-items:center;&>*{margin-left:8px}}}.model-tab:before{content:"";position:absolute;left:.4rem;width:45%;height:80%;background-color:#ffc800;border-radius:2rem;transition:all .4s}.editor-tab:before{left:calc(50%)}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
self.__BUILD_MANIFEST=function(s,c,a,e,t,d,n,b,k,h,i,f){return{__rewrites:{beforeFiles:[],afterFiles:[],fallback:[]},"/":["static/chunks/29107295-90b90cb30c825230.js",s,c,a,d,n,b,"static/chunks/539-dcd22f1f6b99ebee.js","static/chunks/pages/index-e5fd29b9e2d6bb59.js"],"/_error":["static/chunks/pages/_error-dee72aff9b2e2c12.js"],"/agent":[s,c,e,k,t,d,"static/chunks/pages/agent-762425b419303d9d.js"],"/chat":["static/chunks/pages/chat-12498cfa4a376095.js"],"/chat/[scene]/[id]":["static/chunks/pages/chat/[scene]/[id]-39a3901132926636.js"],"/database":[s,c,a,e,t,n,h,"static/chunks/643-d8f53f40dd3c5b40.js","static/chunks/pages/database-b4f32916b9d484a7.js"],"/knowledge":[i,s,c,e,k,t,d,n,"static/chunks/109-0dace28dd2667396.js","static/chunks/pages/knowledge-fbe0df9d6a60a0b5.js"],"/knowledge/chunk":[e,t,"static/chunks/pages/knowledge/chunk-765a4b202d79ac28.js"],"/models":[i,s,c,a,f,h,"static/chunks/pages/models-cb9ab490969e70dd.js"],"/prompt":[s,c,a,f,"static/chunks/837-e6d4d1eb9e057050.js",b,"static/chunks/607-b224c640f6907e4b.js","static/chunks/pages/prompt-7f839dfd56bc4c20.js"],sortedPages:["/","/_app","/_error","/agent","/chat","/chat/[scene]/[id]","/database","/knowledge","/knowledge/chunk","/models","/prompt"]}}("static/chunks/64-91b49d45b9846775.js","static/chunks/479-b20198841f9a6a1e.js","static/chunks/9-bb2c54d5c06ba4bf.js","static/chunks/442-197e6cbc1e54109a.js","static/chunks/813-cce9482e33f2430c.js","static/chunks/924-ba8e16df4d61ff5c.js","static/chunks/411-d9eba2657c72f766.js","static/chunks/270-2f094a936d056513.js","static/chunks/365-a224ec0807392b35.js","static/chunks/928-74244889bd7f2699.js","static/chunks/75fc9c18-a784766a129ec5fb.js","static/chunks/947-5980a3ff49069ddd.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();

View File

@ -1 +0,0 @@
self.__BUILD_MANIFEST=function(s,c,e,a,t,n,b,d,k,h,i,u){return{__rewrites:{beforeFiles:[],afterFiles:[],fallback:[]},"/":[b,s,c,e,n,d,"static/chunks/539-dcd22f1f6b99ebee.js","static/chunks/pages/index-5ee4d5bede88e6ef.js"],"/_error":["static/chunks/pages/_error-dee72aff9b2e2c12.js"],"/agent":[s,c,a,k,t,"static/chunks/pages/agent-ff3852522fea07c6.js"],"/chat":["static/chunks/pages/chat-be738dbebc61501d.js"],"/chat/[scene]/[id]":["static/chunks/pages/chat/[scene]/[id]-868f396254bd78ec.js"],"/database":[s,c,e,a,t,n,h,"static/chunks/643-d8f53f40dd3c5b40.js","static/chunks/pages/database-51b362b90c1b0be9.js"],"/knowledge":[i,s,c,a,k,t,n,"static/chunks/63-d9f1013be8e4599a.js","static/chunks/pages/knowledge-7a8d4a6321e572be.js"],"/knowledge/chunk":[a,t,"static/chunks/pages/knowledge/chunk-e27c2e349b868b28.js"],"/models":[i,s,c,e,u,h,"static/chunks/pages/models-97ac98a0a4bed459.js"],"/prompt":[b,s,c,e,u,"static/chunks/837-e6d4d1eb9e057050.js",d,"static/chunks/607-b224c640f6907e4b.js","static/chunks/pages/prompt-cbdeda486835f410.js"],sortedPages:["/","/_app","/_error","/agent","/chat","/chat/[scene]/[id]","/database","/knowledge","/knowledge/chunk","/models","/prompt"]}}("static/chunks/64-91b49d45b9846775.js","static/chunks/479-b20198841f9a6a1e.js","static/chunks/9-bb2c54d5c06ba4bf.js","static/chunks/442-197e6cbc1e54109a.js","static/chunks/813-cce9482e33f2430c.js","static/chunks/411-d9eba2657c72f766.js","static/chunks/29107295-90b90cb30c825230.js","static/chunks/719-5a18c3c696beda6f.js","static/chunks/365-2cad3676ccbb1b1a.js","static/chunks/928-74244889bd7f2699.js","static/chunks/75fc9c18-a784766a129ec5fb.js","static/chunks/947-5980a3ff49069ddd.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long