From 4fa768e7337dc421e654a17d655ba09ab6084362 Mon Sep 17 00:00:00 2001
From: KevinHuSh <kevinhu.sh@gmail.com>
Date: Thu, 11 Apr 2024 16:25:28 +0800
Subject: [PATCH] fix bug #314 (#317)

### What problem does this PR solve?

Issue link:#314

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
---
 api/apps/conversation_app.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/api/apps/conversation_app.py b/api/apps/conversation_app.py
index 2379d30..fd9c266 100644
--- a/api/apps/conversation_app.py
+++ b/api/apps/conversation_app.py
@@ -358,6 +358,8 @@ def use_sql(question, field_map, tenant_id, chat_mdl):
     rows = ["|" +
             "|".join([rmSpace(str(r[i])) for i in clmn_idx]).replace("None", " ") +
             "|" for r in tbl["rows"]]
+    rows = "\n".join([r + f" ##{ii}$$ |" for ii, r in enumerate(rows)])
+    rows = re.sub(r"T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+Z)?\|", "|", rows)
     if not docid_idx or not docnm_idx:
         chat_logger.warning("SQL missing field: " + sql)
         return {
@@ -365,8 +367,6 @@ def use_sql(question, field_map, tenant_id, chat_mdl):
             "reference": {"chunks": [], "doc_aggs": []}
         }
 
-    rows = "\n".join([r + f" ##{ii}$$ |" for ii, r in enumerate(rows)])
-    rows = re.sub(r"T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+Z)?\|", "|", rows)
     docid_idx = list(docid_idx)[0]
     docnm_idx = list(docnm_idx)[0]
     doc_aggs = {}
-- 
GitLab