Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions api/apps/document_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,37 +556,3 @@ def read(self):
txt = FileService.parse_docs(file_objs, current_user.id)

return get_json_result(data=txt)


@manager.route("/upload_info", methods=["POST"]) # noqa: F821
@login_required
async def upload_info():
files = await request.files
file_objs = files.getlist("file") if files and files.get("file") else []
url = request.args.get("url")

if file_objs and url:
return get_json_result(
data=False,
message="Provide either multipart file(s) or ?url=..., not both.",
code=RetCode.BAD_REQUEST,
)

if not file_objs and not url:
return get_json_result(
data=False,
message="Missing input: provide multipart file(s) or url",
code=RetCode.BAD_REQUEST,
)

try:
if url and not file_objs:
return get_json_result(data=FileService.upload_info(current_user.id, None, url))

if len(file_objs) == 1:
return get_json_result(data=FileService.upload_info(current_user.id, file_objs[0], None))

results = [FileService.upload_info(current_user.id, f, None) for f in file_objs]
return get_json_result(data=results)
except Exception as e:
return server_error_response(e)
55 changes: 55 additions & 0 deletions api/apps/restful_apis/document_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,61 @@
from common.metadata_utils import convert_conditions, meta_filter, turn2jsonschema
from common.misc_utils import thread_pool_exec


@manager.route("/documents/upload", methods=["POST"]) # noqa: F821
@login_required
@add_tenant_id_to_kwargs
async def upload_info(tenant_id: str):
"""
Upload a document and get its parsed info.
---
tags:
- Documents
security:
- ApiKeyAuth: []
parameters:
- in: header
name: Authorization
type: string
required: true
description: Bearer token for authentication.
- in: formData
name: file
type: file
required: false
description: File to upload.
- in: query
name: url
type: string
required: false
description: URL to fetch file from.
responses:
200:
description: Successful operation.
"""
files = await request.files
file_objs = files.getlist("file") if files and files.get("file") else []
url = request.args.get("url")

if file_objs and url:
return get_error_argument_result("Provide either multipart file(s) or ?url=..., not both.")

if not file_objs and not url:
return get_error_argument_result("Missing input: provide multipart file(s) or url")

try:
if url and not file_objs:
return get_result(data=FileService.upload_info(tenant_id, None, url))

if len(file_objs) == 1:
return get_result(data=FileService.upload_info(tenant_id, file_objs[0], None))

results = [FileService.upload_info(tenant_id, f, None) for f in file_objs]
return get_result(data=results)
except Exception as e:
return server_error_response(e)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.


@manager.route("/datasets/<dataset_id>/documents/<document_id>", methods=["PATCH"]) # noqa: F821
@login_required
@add_tenant_id_to_kwargs
Expand Down
4 changes: 2 additions & 2 deletions web/src/hooks/use-chat-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,9 @@ export function useUploadAndParseFile() {
formData.append('file', file);
formData.append('conversation_id', conversationId || id);

const { data } = await chatService.uploadAndParse(
const { data } = await chatService.documentInfoUpload(
{
url: api.uploadAndParse,
url: api.documentInfoUpload,
signal: controller.current.signal,
data: formData,
onUploadProgress: ({ progress }) => {
Expand Down
6 changes: 3 additions & 3 deletions web/src/services/next-chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const {
chatsTts,
chatsMindmap,
chatsRelatedQuestions,
uploadAndParse,
documentInfoUpload,
fetchExternalChatInfo,
} = api;

Expand Down Expand Up @@ -92,9 +92,9 @@ const methods = {
url: chatsRelatedQuestions,
method: 'post',
},
uploadAndParse: {
documentInfoUpload: {
method: 'post',
url: uploadAndParse,
url: documentInfoUpload,
},
fetchExternalChatInfo: {
url: fetchExternalChatInfo,
Expand Down
2 changes: 1 addition & 1 deletion web/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default {
documentUpload: (datasetId: string) =>
`${restAPIv1}/datasets/${datasetId}/documents`,
webCrawl: `${webAPI}/document/web_crawl`,
uploadAndParse: `${webAPI}/document/upload_info`,
documentInfoUpload: `${restAPIv1}/documents/upload`,
setMeta: `${webAPI}/document/set_meta`,
getDatasetFilter: (datasetId: string) =>
`${restAPIv1}/datasets/${datasetId}/documents?type=filter`,
Expand Down