Minor tweaks (#11106)

### What problem does this PR solve?

Refactor

### Type of change

- [x] Refactoring

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2025-11-07 15:44:57 +08:00
committed by GitHub
parent fa98cc2bb9
commit 307f53dae8
2 changed files with 15 additions and 20 deletions

View File

@ -466,10 +466,7 @@ def upload():
if "run" in form_data.keys(): if "run" in form_data.keys():
if request.form.get("run").strip() == "1": if request.form.get("run").strip() == "1":
try: try:
info = {"run": 1, "progress": 0} info = {"run": 1, "progress": 0, "progress_msg": "", "chunk_num": 0, "token_num": 0}
info["progress_msg"] = ""
info["chunk_num"] = 0
info["token_num"] = 0
DocumentService.update_by_id(doc["id"], info) DocumentService.update_by_id(doc["id"], info)
# if str(req["run"]) == TaskStatus.CANCEL.value: # if str(req["run"]) == TaskStatus.CANCEL.value:
tenant_id = DocumentService.get_tenant_id(doc["id"]) tenant_id = DocumentService.get_tenant_id(doc["id"])
@ -726,8 +723,7 @@ def completion_faq():
if "quote" not in req: if "quote" not in req:
req["quote"] = True req["quote"] = True
msg = [] msg = [{"role": "user", "content": req["word"]}]
msg.append({"role": "user", "content": req["word"]})
if not msg[-1].get("id"): if not msg[-1].get("id"):
msg[-1]["id"] = get_uuid() msg[-1]["id"] = get_uuid()
message_id = msg[-1]["id"] message_id = msg[-1]["id"]

View File

@ -410,22 +410,22 @@ def test_db_connect():
ibm_db.close(conn) ibm_db.close(conn)
return get_json_result(data="Database Connection Successful!") return get_json_result(data="Database Connection Successful!")
elif req["db_type"] == 'trino': elif req["db_type"] == 'trino':
def _parse_catalog_schema(db: str): def _parse_catalog_schema(db_name: str):
if not db: if not db_name:
return None, None return None, None
if "." in db: if "." in db_name:
c, s = db.split(".", 1) catalog_name, schema_name = db_name.split(".", 1)
elif "/" in db: elif "/" in db_name:
c, s = db.split("/", 1) catalog_name, schema_name = db_name.split("/", 1)
else: else:
c, s = db, "default" catalog_name, schema_name = db_name, "default"
return c, s return catalog_name, schema_name
try: try:
import trino import trino
import os import os
from trino.auth import BasicAuthentication from trino.auth import BasicAuthentication
except Exception: except Exception as e:
return server_error_response("Missing dependency 'trino'. Please install: pip install trino") return server_error_response(f"Missing dependency 'trino'. Please install: pip install trino, detail: {e}")
catalog, schema = _parse_catalog_schema(req["database"]) catalog, schema = _parse_catalog_schema(req["database"])
if not catalog: if not catalog:
@ -479,7 +479,6 @@ def getlistversion(canvas_id):
@login_required @login_required
def getversion( version_id): def getversion( version_id):
try: try:
e, version = UserCanvasVersionService.get_by_id(version_id) e, version = UserCanvasVersionService.get_by_id(version_id)
if version: if version:
return get_json_result(data=version.to_dict()) return get_json_result(data=version.to_dict())
@ -546,11 +545,11 @@ def trace():
cvs_id = request.args.get("canvas_id") cvs_id = request.args.get("canvas_id")
msg_id = request.args.get("message_id") msg_id = request.args.get("message_id")
try: try:
bin = REDIS_CONN.get(f"{cvs_id}-{msg_id}-logs") binary = REDIS_CONN.get(f"{cvs_id}-{msg_id}-logs")
if not bin: if not binary:
return get_json_result(data={}) return get_json_result(data={})
return get_json_result(data=json.loads(bin.encode("utf-8"))) return get_json_result(data=json.loads(binary.encode("utf-8")))
except Exception as e: except Exception as e:
logging.exception(e) logging.exception(e)