[OND211-2329]: Fixed ruff checks.
This commit is contained in:
parent
8a9ada69dc
commit
b0ecda42fb
1 changed files with 12 additions and 31 deletions
|
|
@ -15,8 +15,6 @@
|
||||||
#
|
#
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
@ -27,24 +25,17 @@ from quart import (
|
||||||
request,
|
request,
|
||||||
Response,
|
Response,
|
||||||
)
|
)
|
||||||
import trio
|
|
||||||
|
|
||||||
from agent.canvas import Canvas
|
from agent.canvas import Canvas
|
||||||
from agent.component import LLM
|
from agent.component import LLM
|
||||||
from api.apps import current_user, login_required
|
from api.apps import current_user, login_required
|
||||||
from api.common.permission_utils import has_permission
|
from api.common.permission_utils import has_permission
|
||||||
from api.db import CanvasCategory, FileType
|
from api.db import CanvasCategory
|
||||||
from api.db.db_models import APIToken, Task
|
from api.db.db_models import APIToken, Task
|
||||||
from api.db.services.canvas_service import (
|
from api.db.services.canvas_service import (
|
||||||
API4ConversationService,
|
API4ConversationService,
|
||||||
CanvasTemplateService,
|
CanvasTemplateService,
|
||||||
UserCanvasService,
|
UserCanvasService,
|
||||||
)
|
)
|
||||||
from functools import partial
|
|
||||||
from quart import request, Response, make_response
|
|
||||||
from agent.component import LLM
|
|
||||||
from api.db import CanvasCategory
|
|
||||||
from api.db.services.canvas_service import CanvasTemplateService, UserCanvasService, API4ConversationService
|
|
||||||
from api.db.services.document_service import DocumentService
|
from api.db.services.document_service import DocumentService
|
||||||
from api.db.services.file_service import FileService
|
from api.db.services.file_service import FileService
|
||||||
from api.db.services.pipeline_operation_log_service import (
|
from api.db.services.pipeline_operation_log_service import (
|
||||||
|
|
@ -64,19 +55,9 @@ from api.utils.api_utils import (
|
||||||
server_error_response,
|
server_error_response,
|
||||||
validate_request,
|
validate_request,
|
||||||
)
|
)
|
||||||
from api.utils.file_utils import filename_type, read_potential_broken_pdf
|
|
||||||
from common import settings
|
from common import settings
|
||||||
from common.constants import RetCode, StatusEnum
|
from common.constants import RetCode, StatusEnum
|
||||||
from common.misc_utils import get_uuid
|
from common.misc_utils import get_uuid
|
||||||
from common.constants import RetCode
|
|
||||||
from common.misc_utils import get_uuid
|
|
||||||
from api.utils.api_utils import get_json_result, server_error_response, validate_request, get_data_error_result, \
|
|
||||||
request_json
|
|
||||||
from agent.canvas import Canvas
|
|
||||||
from peewee import MySQLDatabase, PostgresqlDatabase
|
|
||||||
from api.db.db_models import APIToken, Task
|
|
||||||
import time
|
|
||||||
|
|
||||||
from rag.flow.pipeline import Pipeline
|
from rag.flow.pipeline import Pipeline
|
||||||
from rag.nlp import search
|
from rag.nlp import search
|
||||||
from rag.utils.redis_conn import REDIS_CONN
|
from rag.utils.redis_conn import REDIS_CONN
|
||||||
|
|
@ -112,7 +93,7 @@ async def save() -> Any:
|
||||||
if not isinstance(req["dsl"], str):
|
if not isinstance(req["dsl"], str):
|
||||||
req["dsl"] = json.dumps(req["dsl"], ensure_ascii=False)
|
req["dsl"] = json.dumps(req["dsl"], ensure_ascii=False)
|
||||||
req["dsl"] = json.loads(req["dsl"])
|
req["dsl"] = json.loads(req["dsl"])
|
||||||
|
|
||||||
# Validate shared_tenant_id if provided
|
# Validate shared_tenant_id if provided
|
||||||
shared_tenant_id: Optional[str] = req.get("shared_tenant_id")
|
shared_tenant_id: Optional[str] = req.get("shared_tenant_id")
|
||||||
if shared_tenant_id:
|
if shared_tenant_id:
|
||||||
|
|
@ -131,7 +112,7 @@ async def save() -> Any:
|
||||||
message="You are not a member of the selected team",
|
message="You are not a member of the selected team",
|
||||||
code=RetCode.PERMISSION_ERROR
|
code=RetCode.PERMISSION_ERROR
|
||||||
)
|
)
|
||||||
|
|
||||||
cate = req.get("canvas_category", CanvasCategory.Agent)
|
cate = req.get("canvas_category", CanvasCategory.Agent)
|
||||||
if "id" not in req:
|
if "id" not in req:
|
||||||
# Check create permission if sharing with team
|
# Check create permission if sharing with team
|
||||||
|
|
@ -279,8 +260,8 @@ async def rerun():
|
||||||
doc["chunk_num"] = 0
|
doc["chunk_num"] = 0
|
||||||
doc["token_num"] = 0
|
doc["token_num"] = 0
|
||||||
DocumentService.clear_chunk_num_when_rerun(doc["id"])
|
DocumentService.clear_chunk_num_when_rerun(doc["id"])
|
||||||
DocumentService.update_by_id(id, doc)
|
DocumentService.update_by_id(doc["id"], doc)
|
||||||
TaskService.filter_delete([Task.doc_id == id])
|
TaskService.filter_delete([Task.doc_id == doc["id"]])
|
||||||
|
|
||||||
dsl = req["dsl"]
|
dsl = req["dsl"]
|
||||||
dsl["path"] = [req["component_id"]]
|
dsl["path"] = [req["component_id"]]
|
||||||
|
|
@ -338,7 +319,7 @@ async def upload(canvas_id):
|
||||||
try:
|
try:
|
||||||
return get_json_result(data=FileService.upload_info(user_id, file, request.args.get("url")))
|
return get_json_result(data=FileService.upload_info(user_id, file, request.args.get("url")))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return server_error_response(e)
|
return server_error_response(e)
|
||||||
|
|
||||||
|
|
||||||
@manager.route('/input_form', methods=['GET']) # noqa: F821
|
@manager.route('/input_form', methods=['GET']) # noqa: F821
|
||||||
|
|
@ -383,7 +364,7 @@ async def debug():
|
||||||
|
|
||||||
if isinstance(component, LLM):
|
if isinstance(component, LLM):
|
||||||
component.set_debug_inputs(req["params"])
|
component.set_debug_inputs(req["params"])
|
||||||
component.invoke(**{k: o["value"] for k,o in req["params"].items()})
|
component.invoke(**{k: o["value"] for k, o in req["params"].items()})
|
||||||
outputs = component.output()
|
outputs = component.output()
|
||||||
for k in outputs.keys():
|
for k in outputs.keys():
|
||||||
if isinstance(outputs[k], partial):
|
if isinstance(outputs[k], partial):
|
||||||
|
|
@ -495,7 +476,7 @@ async def test_db_connect():
|
||||||
@login_required
|
@login_required
|
||||||
def getlistversion(canvas_id):
|
def getlistversion(canvas_id):
|
||||||
try:
|
try:
|
||||||
versions =sorted([c.to_dict() for c in UserCanvasVersionService.list_by_canvas_id(canvas_id)], key=lambda x: x["update_time"]*-1)
|
versions = sorted([c.to_dict() for c in UserCanvasVersionService.list_by_canvas_id(canvas_id)], key=lambda x: x["update_time"] * -1)
|
||||||
return get_json_result(data=versions)
|
return get_json_result(data=versions)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return get_data_error_result(message=f"Error getting history files: {e}")
|
return get_data_error_result(message=f"Error getting history files: {e}")
|
||||||
|
|
@ -504,7 +485,7 @@ def getlistversion(canvas_id):
|
||||||
#api get version dsl of canvas
|
#api get version dsl of canvas
|
||||||
@manager.route('/getversion/<version_id>', methods=['GET']) # noqa: F821
|
@manager.route('/getversion/<version_id>', methods=['GET']) # noqa: F821
|
||||||
@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:
|
||||||
|
|
@ -525,7 +506,7 @@ def list_canvas():
|
||||||
desc = False
|
desc = False
|
||||||
else:
|
else:
|
||||||
desc = True
|
desc = True
|
||||||
owner_ids = [id for id in request.args.get("owner_ids", "").strip().split(",") if id]
|
owner_ids = [owner_id for owner_id in request.args.get("owner_ids", "").strip().split(",") if owner_id]
|
||||||
if not owner_ids:
|
if not owner_ids:
|
||||||
tenants = TenantService.get_joined_tenants_by_user_id(current_user.id)
|
tenants = TenantService.get_joined_tenants_by_user_id(current_user.id)
|
||||||
tenants = [m["tenant_id"] for m in tenants]
|
tenants = [m["tenant_id"] for m in tenants]
|
||||||
|
|
@ -556,7 +537,7 @@ async def setting():
|
||||||
code=RetCode.PERMISSION_ERROR
|
code=RetCode.PERMISSION_ERROR
|
||||||
)
|
)
|
||||||
|
|
||||||
e,flow = UserCanvasService.get_by_id(req["id"])
|
e, flow = UserCanvasService.get_by_id(req["id"])
|
||||||
if not e:
|
if not e:
|
||||||
return get_data_error_result(message="canvas not found.")
|
return get_data_error_result(message="canvas not found.")
|
||||||
flow = flow.to_dict()
|
flow = flow.to_dict()
|
||||||
|
|
@ -566,7 +547,7 @@ async def setting():
|
||||||
if value := req.get(key):
|
if value := req.get(key):
|
||||||
flow[key] = value
|
flow[key] = value
|
||||||
|
|
||||||
num= UserCanvasService.update_by_id(req["id"], flow)
|
num = UserCanvasService.update_by_id(req["id"], flow)
|
||||||
return get_json_result(data=num)
|
return get_json_result(data=num)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue