Kevin Hu
commited on
Commit
·
2320b60
1
Parent(s):
252d77a
Refactor (#4303)
Browse files### What problem does this PR solve?
### Type of change
- [x] Refactoring
- agent/component/base.py +1 -1
- api/apps/__init__.py +2 -2
- api/apps/conversation_app.py +0 -4
- api/db/services/document_service.py +2 -5
- api/utils/api_utils.py +1 -0
- rag/svr/task_executor.py +5 -3
agent/component/base.py
CHANGED
@@ -457,7 +457,7 @@ class ComponentBase(ABC):
|
|
457 |
|
458 |
def get_input(self):
|
459 |
if self._param.debug_inputs:
|
460 |
-
return pd.DataFrame([{"content": v["value"]} for v in self._param.debug_inputs])
|
461 |
|
462 |
reversed_cpnts = []
|
463 |
if len(self._canvas.path) > 1:
|
|
|
457 |
|
458 |
def get_input(self):
|
459 |
if self._param.debug_inputs:
|
460 |
+
return pd.DataFrame([{"content": v["value"]} for v in self._param.debug_inputs if v.get("value")])
|
461 |
|
462 |
reversed_cpnts = []
|
463 |
if len(self._canvas.path) > 1:
|
api/apps/__init__.py
CHANGED
@@ -152,8 +152,8 @@ def load_user(web_request):
|
|
152 |
return user[0]
|
153 |
else:
|
154 |
return None
|
155 |
-
except Exception:
|
156 |
-
logging.
|
157 |
return None
|
158 |
else:
|
159 |
return None
|
|
|
152 |
return user[0]
|
153 |
else:
|
154 |
return None
|
155 |
+
except Exception as e:
|
156 |
+
logging.warning(f"load_user got exception {e}")
|
157 |
return None
|
158 |
else:
|
159 |
return None
|
api/apps/conversation_app.py
CHANGED
@@ -65,10 +65,6 @@ def set_conversation():
|
|
65 |
"message": [{"role": "assistant", "content": dia.prompt_config["prologue"]}]
|
66 |
}
|
67 |
ConversationService.save(**conv)
|
68 |
-
e, conv = ConversationService.get_by_id(conv["id"])
|
69 |
-
if not e:
|
70 |
-
return get_data_error_result(message="Fail to new a conversation!")
|
71 |
-
conv = conv.to_dict()
|
72 |
return get_json_result(data=conv)
|
73 |
except Exception as e:
|
74 |
return server_error_response(e)
|
|
|
65 |
"message": [{"role": "assistant", "content": dia.prompt_config["prologue"]}]
|
66 |
}
|
67 |
ConversationService.save(**conv)
|
|
|
|
|
|
|
|
|
68 |
return get_json_result(data=conv)
|
69 |
except Exception as e:
|
70 |
return server_error_response(e)
|
api/db/services/document_service.py
CHANGED
@@ -96,14 +96,11 @@ class DocumentService(CommonService):
|
|
96 |
def insert(cls, doc):
|
97 |
if not cls.save(**doc):
|
98 |
raise RuntimeError("Database error (Document)!")
|
99 |
-
e,
|
100 |
-
if not e:
|
101 |
-
raise RuntimeError("Database error (Document retrieval)!")
|
102 |
-
e, kb = KnowledgebaseService.get_by_id(doc.kb_id)
|
103 |
if not KnowledgebaseService.update_by_id(
|
104 |
kb.id, {"doc_num": kb.doc_num + 1}):
|
105 |
raise RuntimeError("Database error (Knowledgebase)!")
|
106 |
-
return doc
|
107 |
|
108 |
@classmethod
|
109 |
@DB.connection_context()
|
|
|
96 |
def insert(cls, doc):
|
97 |
if not cls.save(**doc):
|
98 |
raise RuntimeError("Database error (Document)!")
|
99 |
+
e, kb = KnowledgebaseService.get_by_id(doc["kb_id"])
|
|
|
|
|
|
|
100 |
if not KnowledgebaseService.update_by_id(
|
101 |
kb.id, {"doc_num": kb.doc_num + 1}):
|
102 |
raise RuntimeError("Database error (Knowledgebase)!")
|
103 |
+
return Document(**doc)
|
104 |
|
105 |
@classmethod
|
106 |
@DB.connection_context()
|
api/utils/api_utils.py
CHANGED
@@ -98,6 +98,7 @@ def get_exponential_backoff_interval(retries, full_jitter=False):
|
|
98 |
|
99 |
def get_data_error_result(code=settings.RetCode.DATA_ERROR,
|
100 |
message='Sorry! Data missing!'):
|
|
|
101 |
result_dict = {
|
102 |
"code": code,
|
103 |
"message": message}
|
|
|
98 |
|
99 |
def get_data_error_result(code=settings.RetCode.DATA_ERROR,
|
100 |
message='Sorry! Data missing!'):
|
101 |
+
logging.exception(Exception(message))
|
102 |
result_dict = {
|
103 |
"code": code,
|
104 |
"message": message}
|
rag/svr/task_executor.py
CHANGED
@@ -92,10 +92,12 @@ DONE_TASKS = 0
|
|
92 |
FAILED_TASKS = 0
|
93 |
CURRENT_TASK = None
|
94 |
|
|
|
95 |
class TaskCanceledException(Exception):
|
96 |
def __init__(self, msg):
|
97 |
self.msg = msg
|
98 |
|
|
|
99 |
def set_progress(task_id, from_page=0, to_page=-1, prog=None, msg="Processing..."):
|
100 |
global PAYLOAD
|
101 |
if prog is not None and prog < 0:
|
@@ -250,7 +252,7 @@ def build_chunks(task, progress_callback):
|
|
250 |
STORAGE_IMPL.put(task["kb_id"], d["id"], output_buffer.getvalue())
|
251 |
el += timer() - st
|
252 |
except Exception:
|
253 |
-
logging.exception("Saving image of chunk {}/{}/{} got exception".format(task["location"], task["name"], d["
|
254 |
raise
|
255 |
|
256 |
d["img_id"] = "{}-{}".format(task["kb_id"], d["id"])
|
@@ -312,6 +314,8 @@ def embedding(docs, mdl, parser_config=None, callback=None):
|
|
312 |
if not c:
|
313 |
c = d["content_with_weight"]
|
314 |
c = re.sub(r"</?(table|td|caption|tr|th)( [^<>]{0,12})?>", " ", c)
|
|
|
|
|
315 |
cnts.append(c)
|
316 |
|
317 |
tk_count = 0
|
@@ -394,8 +398,6 @@ def run_raptor(row, chat_mdl, embd_mdl, callback=None):
|
|
394 |
return res, tk_count, vector_size
|
395 |
|
396 |
|
397 |
-
|
398 |
-
|
399 |
def do_handle_task(task):
|
400 |
task_id = task["id"]
|
401 |
task_from_page = task["from_page"]
|
|
|
92 |
FAILED_TASKS = 0
|
93 |
CURRENT_TASK = None
|
94 |
|
95 |
+
|
96 |
class TaskCanceledException(Exception):
|
97 |
def __init__(self, msg):
|
98 |
self.msg = msg
|
99 |
|
100 |
+
|
101 |
def set_progress(task_id, from_page=0, to_page=-1, prog=None, msg="Processing..."):
|
102 |
global PAYLOAD
|
103 |
if prog is not None and prog < 0:
|
|
|
252 |
STORAGE_IMPL.put(task["kb_id"], d["id"], output_buffer.getvalue())
|
253 |
el += timer() - st
|
254 |
except Exception:
|
255 |
+
logging.exception("Saving image of chunk {}/{}/{} got exception".format(task["location"], task["name"], d["id"]))
|
256 |
raise
|
257 |
|
258 |
d["img_id"] = "{}-{}".format(task["kb_id"], d["id"])
|
|
|
314 |
if not c:
|
315 |
c = d["content_with_weight"]
|
316 |
c = re.sub(r"</?(table|td|caption|tr|th)( [^<>]{0,12})?>", " ", c)
|
317 |
+
if not c:
|
318 |
+
c = "None"
|
319 |
cnts.append(c)
|
320 |
|
321 |
tk_count = 0
|
|
|
398 |
return res, tk_count, vector_size
|
399 |
|
400 |
|
|
|
|
|
401 |
def do_handle_task(task):
|
402 |
task_id = task["id"]
|
403 |
task_from_page = task["from_page"]
|