mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Fix: Table parse method issue. (#11627)
### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -706,6 +706,7 @@ async def set_meta():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return server_error_response(e)
|
return server_error_response(e)
|
||||||
|
|
||||||
|
|
||||||
@manager.route("/upload_info", methods=["POST"]) # noqa: F821
|
@manager.route("/upload_info", methods=["POST"]) # noqa: F821
|
||||||
async def upload_info():
|
async def upload_info():
|
||||||
files = await request.files
|
files = await request.files
|
||||||
|
|||||||
@ -676,7 +676,11 @@ Please write the SQL, only SQL, without any other explanations or text.
|
|||||||
if kb_ids:
|
if kb_ids:
|
||||||
kb_filter = "(" + " OR ".join([f"kb_id = '{kb_id}'" for kb_id in kb_ids]) + ")"
|
kb_filter = "(" + " OR ".join([f"kb_id = '{kb_id}'" for kb_id in kb_ids]) + ")"
|
||||||
if "where" not in sql.lower():
|
if "where" not in sql.lower():
|
||||||
sql += f" WHERE {kb_filter}"
|
o = sql.lower().split("order by")
|
||||||
|
if len(o) > 1:
|
||||||
|
sql = o[0] + f" WHERE {kb_filter} order by " + o[1]
|
||||||
|
else:
|
||||||
|
sql += f" WHERE {kb_filter}"
|
||||||
else:
|
else:
|
||||||
sql += f" AND {kb_filter}"
|
sql += f" AND {kb_filter}"
|
||||||
|
|
||||||
@ -684,10 +688,9 @@ Please write the SQL, only SQL, without any other explanations or text.
|
|||||||
tried_times += 1
|
tried_times += 1
|
||||||
return settings.retriever.sql_retrieval(sql, format="json"), sql
|
return settings.retriever.sql_retrieval(sql, format="json"), sql
|
||||||
|
|
||||||
tbl, sql = get_table()
|
try:
|
||||||
if tbl is None:
|
tbl, sql = get_table()
|
||||||
return None
|
except Exception as e:
|
||||||
if tbl.get("error") and tried_times <= 2:
|
|
||||||
user_prompt = """
|
user_prompt = """
|
||||||
Table name: {};
|
Table name: {};
|
||||||
Table of database fields are as follows:
|
Table of database fields are as follows:
|
||||||
@ -701,16 +704,14 @@ Please write the SQL, only SQL, without any other explanations or text.
|
|||||||
The SQL error you provided last time is as follows:
|
The SQL error you provided last time is as follows:
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Error issued by database as follows:
|
|
||||||
{}
|
|
||||||
|
|
||||||
Please correct the error and write SQL again, only SQL, without any other explanations or text.
|
Please correct the error and write SQL again, only SQL, without any other explanations or text.
|
||||||
""".format(index_name(tenant_id), "\n".join([f"{k}: {v}" for k, v in field_map.items()]), question, sql, tbl["error"])
|
""".format(index_name(tenant_id), "\n".join([f"{k}: {v}" for k, v in field_map.items()]), question, e)
|
||||||
tbl, sql = get_table()
|
try:
|
||||||
logging.debug("TRY it again: {}".format(sql))
|
tbl, sql = get_table()
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
|
||||||
logging.debug("GET table: {}".format(tbl))
|
if len(tbl["rows"]) == 0:
|
||||||
if tbl.get("error") or len(tbl["rows"]) == 0:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
docid_idx = set([ii for ii, c in enumerate(tbl["columns"]) if c["name"] == "doc_id"])
|
docid_idx = set([ii for ii, c in enumerate(tbl["columns"]) if c["name"] == "doc_id"])
|
||||||
|
|||||||
@ -575,9 +575,9 @@ class ESConnection(DocStoreConnection):
|
|||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
self._connect()
|
self._connect()
|
||||||
continue
|
continue
|
||||||
except Exception:
|
except Exception as e:
|
||||||
logger.exception("ESConnection.sql got exception")
|
logger.exception(f"ESConnection.sql got exception. SQL:\n{sql}")
|
||||||
break
|
raise Exception(f"SQL error: {e}\n\nSQL: {sql}")
|
||||||
logger.error(f"ESConnection.sql timeout for {ATTEMPT_TIME} times!")
|
logger.error(f"ESConnection.sql timeout for {ATTEMPT_TIME} times!")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user