From 2cdba3d1e6c0a1f87fa52691f100f8bcdfad1a6c Mon Sep 17 00:00:00 2001 From: YngvarHuang <625452882@qq.com> Date: Fri, 10 Oct 2025 18:36:20 +0800 Subject: [PATCH] Fix: Fixed the issue where swagger apidocs could not be opened properly(#9522) (#10461) ### What problem does this PR solve? Fix: Fixed the issue where swagger apidocs could not be opened properly(#9522) ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Co-authored-by: virgilwong --- api/apps/sdk/dify_retrieval.py | 83 ++++++++++++++++++++++++++++++++++ api/apps/sdk/doc.py | 2 +- api/apps/sdk/files.py | 32 ++++++------- 3 files changed, 100 insertions(+), 17 deletions(-) diff --git a/api/apps/sdk/dify_retrieval.py b/api/apps/sdk/dify_retrieval.py index dc5476f34..cbfb6e748 100644 --- a/api/apps/sdk/dify_retrieval.py +++ b/api/apps/sdk/dify_retrieval.py @@ -31,6 +31,89 @@ from api.db.services.dialog_service import meta_filter, convert_conditions @apikey_required @validate_request("knowledge_id", "query") def retrieval(tenant_id): + """ + Dify-compatible retrieval API + --- + tags: + - SDK + security: + - ApiKeyAuth: [] + parameters: + - in: body + name: body + required: true + schema: + type: object + required: + - knowledge_id + - query + properties: + knowledge_id: + type: string + description: Knowledge base ID + query: + type: string + description: Query text + use_kg: + type: boolean + description: Whether to use knowledge graph + default: false + retrieval_setting: + type: object + description: Retrieval configuration + properties: + score_threshold: + type: number + description: Similarity threshold + default: 0.0 + top_k: + type: integer + description: Number of results to return + default: 1024 + metadata_condition: + type: object + description: Metadata filter condition + properties: + conditions: + type: array + items: + type: object + properties: + name: + type: string + description: Field name + comparison_operator: + type: string + description: Comparison operator + value: + type: string + description: Field value + responses: + 200: + description: Retrieval succeeded + schema: + type: object + properties: + records: + type: array + items: + type: object + properties: + content: + type: string + description: Content text + score: + type: number + description: Similarity score + title: + type: string + description: Document title + metadata: + type: object + description: Metadata info + 404: + description: Knowledge base or document not found + """ req = request.json question = req["query"] kb_id = req["knowledge_id"] diff --git a/api/apps/sdk/doc.py b/api/apps/sdk/doc.py index 2cc2926df..0c6405c14 100644 --- a/api/apps/sdk/doc.py +++ b/api/apps/sdk/doc.py @@ -458,7 +458,7 @@ def list_docs(dataset_id, tenant_id): required: false default: true description: Order in descending. - - in: query + - in: query name: create_time_from type: integer required: false diff --git a/api/apps/sdk/files.py b/api/apps/sdk/files.py index 17af87dc0..d2a3de21f 100644 --- a/api/apps/sdk/files.py +++ b/api/apps/sdk/files.py @@ -62,22 +62,22 @@ def upload(tenant_id): type: object properties: data: - type: array - items: - type: object - properties: - id: - type: string - description: File ID - name: - type: string - description: File name - size: - type: integer - description: File size in bytes - type: - type: string - description: File type (e.g., document, folder) + type: array + items: + type: object + properties: + id: + type: string + description: File ID + name: + type: string + description: File name + size: + type: integer + description: File size in bytes + type: + type: string + description: File type (e.g., document, folder) """ pf_id = request.form.get("parent_id")