mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-14 11:45:58 +08:00
Refactor (#4303)
### What problem does this PR solve? ### Type of change - [x] Refactoring
This commit is contained in:
parent
b52b0f68fc
commit
4ba4f622a5
@ -457,7 +457,7 @@ class ComponentBase(ABC):
|
|||||||
|
|
||||||
def get_input(self):
|
def get_input(self):
|
||||||
if self._param.debug_inputs:
|
if self._param.debug_inputs:
|
||||||
return pd.DataFrame([{"content": v["value"]} for v in self._param.debug_inputs])
|
return pd.DataFrame([{"content": v["value"]} for v in self._param.debug_inputs if v.get("value")])
|
||||||
|
|
||||||
reversed_cpnts = []
|
reversed_cpnts = []
|
||||||
if len(self._canvas.path) > 1:
|
if len(self._canvas.path) > 1:
|
||||||
|
@ -152,8 +152,8 @@ def load_user(web_request):
|
|||||||
return user[0]
|
return user[0]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
except Exception:
|
except Exception as e:
|
||||||
logging.exception("load_user got exception")
|
logging.warning(f"load_user got exception {e}")
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
@ -65,10 +65,6 @@ def set_conversation():
|
|||||||
"message": [{"role": "assistant", "content": dia.prompt_config["prologue"]}]
|
"message": [{"role": "assistant", "content": dia.prompt_config["prologue"]}]
|
||||||
}
|
}
|
||||||
ConversationService.save(**conv)
|
ConversationService.save(**conv)
|
||||||
e, conv = ConversationService.get_by_id(conv["id"])
|
|
||||||
if not e:
|
|
||||||
return get_data_error_result(message="Fail to new a conversation!")
|
|
||||||
conv = conv.to_dict()
|
|
||||||
return get_json_result(data=conv)
|
return get_json_result(data=conv)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return server_error_response(e)
|
return server_error_response(e)
|
||||||
|
@ -96,14 +96,11 @@ class DocumentService(CommonService):
|
|||||||
def insert(cls, doc):
|
def insert(cls, doc):
|
||||||
if not cls.save(**doc):
|
if not cls.save(**doc):
|
||||||
raise RuntimeError("Database error (Document)!")
|
raise RuntimeError("Database error (Document)!")
|
||||||
e, doc = cls.get_by_id(doc["id"])
|
e, kb = KnowledgebaseService.get_by_id(doc["kb_id"])
|
||||||
if not e:
|
|
||||||
raise RuntimeError("Database error (Document retrieval)!")
|
|
||||||
e, kb = KnowledgebaseService.get_by_id(doc.kb_id)
|
|
||||||
if not KnowledgebaseService.update_by_id(
|
if not KnowledgebaseService.update_by_id(
|
||||||
kb.id, {"doc_num": kb.doc_num + 1}):
|
kb.id, {"doc_num": kb.doc_num + 1}):
|
||||||
raise RuntimeError("Database error (Knowledgebase)!")
|
raise RuntimeError("Database error (Knowledgebase)!")
|
||||||
return doc
|
return Document(**doc)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@DB.connection_context()
|
@DB.connection_context()
|
||||||
|
@ -98,6 +98,7 @@ def get_exponential_backoff_interval(retries, full_jitter=False):
|
|||||||
|
|
||||||
def get_data_error_result(code=settings.RetCode.DATA_ERROR,
|
def get_data_error_result(code=settings.RetCode.DATA_ERROR,
|
||||||
message='Sorry! Data missing!'):
|
message='Sorry! Data missing!'):
|
||||||
|
logging.exception(Exception(message))
|
||||||
result_dict = {
|
result_dict = {
|
||||||
"code": code,
|
"code": code,
|
||||||
"message": message}
|
"message": message}
|
||||||
|
@ -92,10 +92,12 @@ DONE_TASKS = 0
|
|||||||
FAILED_TASKS = 0
|
FAILED_TASKS = 0
|
||||||
CURRENT_TASK = None
|
CURRENT_TASK = None
|
||||||
|
|
||||||
|
|
||||||
class TaskCanceledException(Exception):
|
class TaskCanceledException(Exception):
|
||||||
def __init__(self, msg):
|
def __init__(self, msg):
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
|
|
||||||
|
|
||||||
def set_progress(task_id, from_page=0, to_page=-1, prog=None, msg="Processing..."):
|
def set_progress(task_id, from_page=0, to_page=-1, prog=None, msg="Processing..."):
|
||||||
global PAYLOAD
|
global PAYLOAD
|
||||||
if prog is not None and prog < 0:
|
if prog is not None and prog < 0:
|
||||||
@ -250,7 +252,7 @@ def build_chunks(task, progress_callback):
|
|||||||
STORAGE_IMPL.put(task["kb_id"], d["id"], output_buffer.getvalue())
|
STORAGE_IMPL.put(task["kb_id"], d["id"], output_buffer.getvalue())
|
||||||
el += timer() - st
|
el += timer() - st
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("Saving image of chunk {}/{}/{} got exception".format(task["location"], task["name"], d["_id"]))
|
logging.exception("Saving image of chunk {}/{}/{} got exception".format(task["location"], task["name"], d["id"]))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
d["img_id"] = "{}-{}".format(task["kb_id"], d["id"])
|
d["img_id"] = "{}-{}".format(task["kb_id"], d["id"])
|
||||||
@ -312,6 +314,8 @@ def embedding(docs, mdl, parser_config=None, callback=None):
|
|||||||
if not c:
|
if not c:
|
||||||
c = d["content_with_weight"]
|
c = d["content_with_weight"]
|
||||||
c = re.sub(r"</?(table|td|caption|tr|th)( [^<>]{0,12})?>", " ", c)
|
c = re.sub(r"</?(table|td|caption|tr|th)( [^<>]{0,12})?>", " ", c)
|
||||||
|
if not c:
|
||||||
|
c = "None"
|
||||||
cnts.append(c)
|
cnts.append(c)
|
||||||
|
|
||||||
tk_count = 0
|
tk_count = 0
|
||||||
@ -394,8 +398,6 @@ def run_raptor(row, chat_mdl, embd_mdl, callback=None):
|
|||||||
return res, tk_count, vector_size
|
return res, tk_count, vector_size
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def do_handle_task(task):
|
def do_handle_task(task):
|
||||||
task_id = task["id"]
|
task_id = task["id"]
|
||||||
task_from_page = task["from_page"]
|
task_from_page = task["from_page"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user