mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-04-20 02:37:26 +08:00
Revert "Refactor: dataset / kb API to RESTFul style" (#13646)
Reverts infiniflow/ragflow#13619
This commit is contained in:
@ -28,6 +28,7 @@ from typing import Any
|
||||
|
||||
import requests
|
||||
from quart import (
|
||||
Response,
|
||||
jsonify,
|
||||
request,
|
||||
has_app_context,
|
||||
@ -233,17 +234,6 @@ def active_required(func):
|
||||
return wrapper
|
||||
|
||||
|
||||
def add_tenant_id_to_kwargs(func):
|
||||
@wraps(func)
|
||||
async def wrapper(**kwargs):
|
||||
from api.apps import current_user
|
||||
kwargs["tenant_id"] = current_user.id
|
||||
if inspect.iscoroutinefunction(func):
|
||||
return await func(**kwargs)
|
||||
return func(**kwargs)
|
||||
return wrapper
|
||||
|
||||
|
||||
def get_json_result(code: RetCode = RetCode.SUCCESS, message="success", data=None):
|
||||
response = {"code": code, "message": message, "data": data}
|
||||
return _safe_jsonify(response)
|
||||
@ -523,7 +513,7 @@ def check_duplicate_ids(ids, id_type="item"):
|
||||
return list(set(ids)), duplicate_messages
|
||||
|
||||
|
||||
def verify_embedding_availability(embd_id: str, tenant_id: str) -> tuple[bool, str | None]:
|
||||
def verify_embedding_availability(embd_id: str, tenant_id: str) -> tuple[bool, Response | None]:
|
||||
from api.db.services.llm_service import LLMService
|
||||
from api.db.services.tenant_llm_service import TenantLLMService
|
||||
|
||||
@ -569,16 +559,13 @@ def verify_embedding_availability(embd_id: str, tenant_id: str) -> tuple[bool, s
|
||||
|
||||
is_builtin_model = llm_factory == "Builtin"
|
||||
if not (is_builtin_model or is_tenant_model or in_llm_service):
|
||||
return False, f"Unsupported model: <{embd_id}>"
|
||||
return False, get_error_argument_result(f"Unsupported model: <{embd_id}>")
|
||||
|
||||
if not (is_builtin_model or is_tenant_model):
|
||||
return False, f"Unauthorized model: <{embd_id}>"
|
||||
return False, get_error_argument_result(f"Unauthorized model: <{embd_id}>")
|
||||
except OperationalError as e:
|
||||
logging.exception(e)
|
||||
return False, "Database operation failed"
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
return False, "Internal server error"
|
||||
return False, get_error_data_result(message="Database operation failed")
|
||||
|
||||
return True, None
|
||||
|
||||
|
||||
@ -27,7 +27,6 @@ from pydantic import (
|
||||
ValidationError,
|
||||
field_validator,
|
||||
model_validator,
|
||||
ValidationInfo
|
||||
)
|
||||
from pydantic_core import PydanticCustomError
|
||||
from werkzeug.exceptions import BadRequest, UnsupportedMediaType
|
||||
@ -163,15 +162,6 @@ def validate_and_parse_request_args(request: Request, validator: type[BaseModel]
|
||||
- Preserves type conversion from Pydantic validation
|
||||
"""
|
||||
args = request.args.to_dict(flat=True)
|
||||
|
||||
# Handle ext parameter: parse JSON string to dict if it's a string
|
||||
if 'ext' in args and isinstance(args['ext'], str):
|
||||
import json
|
||||
try:
|
||||
args['ext'] = json.loads(args['ext'])
|
||||
except json.JSONDecodeError:
|
||||
pass # Keep the string and let validation handle the error
|
||||
|
||||
try:
|
||||
if extras is not None:
|
||||
args.update(extras)
|
||||
@ -346,7 +336,6 @@ class RaptorConfig(Base):
|
||||
max_cluster: Annotated[int, Field(default=64, ge=1, le=1024)]
|
||||
random_seed: Annotated[int, Field(default=0, ge=0)]
|
||||
auto_disable_for_structured_data: Annotated[bool, Field(default=True)]
|
||||
ext: Annotated[dict, Field(default={})]
|
||||
|
||||
|
||||
class GraphragConfig(Base):
|
||||
@ -388,7 +377,6 @@ class ParserConfig(Base):
|
||||
filename_embd_weight: Annotated[float | None, Field(default=0.1, ge=0.0, le=1.0)]
|
||||
task_page_size: Annotated[int | None, Field(default=None, ge=1)]
|
||||
pages: Annotated[list[list[int]] | None, Field(default=None)]
|
||||
ext: Annotated[dict, Field(default={})]
|
||||
|
||||
|
||||
class CreateDatasetReq(Base):
|
||||
@ -402,25 +390,6 @@ class CreateDatasetReq(Base):
|
||||
pipeline_id: Annotated[str | None, Field(default=None, min_length=32, max_length=32, serialization_alias="pipeline_id")]
|
||||
parser_config: Annotated[ParserConfig | None, Field(default=None)]
|
||||
auto_metadata_config: Annotated[AutoMetadataConfig | None, Field(default=None)]
|
||||
ext: Annotated[dict, Field(default={})]
|
||||
|
||||
@field_validator("pipeline_id", mode="before")
|
||||
@classmethod
|
||||
def handle_pipeline_id(cls, v: str | None, info: ValidationInfo):
|
||||
if v is None:
|
||||
return v
|
||||
if info.data.get("chunk_method") is not None and isinstance(v, str):
|
||||
v = None
|
||||
return v
|
||||
|
||||
@field_validator("parse_type", mode="before")
|
||||
@classmethod
|
||||
def handle_parse_type(cls, v: int | None, info: ValidationInfo):
|
||||
if v is None:
|
||||
return v
|
||||
if info.data.get("chunk_method") is not None and isinstance(v, int):
|
||||
v = None
|
||||
return v
|
||||
|
||||
@field_validator("avatar", mode="after")
|
||||
@classmethod
|
||||
@ -778,4 +747,3 @@ class BaseListReq(BaseModel):
|
||||
|
||||
class ListDatasetReq(BaseListReq):
|
||||
include_parsing_status: Annotated[bool, Field(default=False)]
|
||||
ext: Annotated[dict, Field(default={})]
|
||||
|
||||
Reference in New Issue
Block a user