rag/wwwroot/api/doc_upload.dspy
ymq 00262a6d2a feat(rag-api): 对外B2B API+内部tools包装
- wwwroot/api/ 六个对外端点(Bearer Key 鉴权,路由授 any、业务鉴权在 api_core):
  kb_create/kb_delete/doc_upload/doc_delete/tag_create/doc_set_tags/search
- rag/api_core.py: verify_api_key + make_api_env(org注入) + 六个业务核心
  (复用 init.py 底层检索/入库能力,杜绝双实现分叉)
- 统一返回格式 {"status":"ok"|"error","data":...}
- rag/ingest.py: 入库管线从 upload_file.dspy 抽出共享(UI/API同一引擎)
- rag/tools.py: RAG_TOOL_SCHEMAS + exec_rag_tool(与API同构,供内部助手调用)
- rag_api_keys 表 model(key 只存 SHA256);管理端 api_key_create/list/revoke
- load_path.py 注册 7 个 API 端点(any) + 3 个管理端点(logined)
2026-09-03 15:51:19 +08:00

15 lines
652 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 对外 API文件上传原始字节 body
# POST /rag/api/doc_upload.dspy?kb_id=X&file_name=Y Authorization: Bearer <api-key>
# Content-Type: application/octet-stream请求体即文件原始字节
from rag import api_core as C
_ctx, _e = await C.verify_api_key(request)
if _e:
return C._err(_e, code="unauthorized")
if not C.require_scope(_ctx, "doc.upload"):
return C._err("api key lacks scope: doc.upload", code="forbidden")
_ns = dict(params_kw or {})
_file_data = await request.read()
_file_name = _ns.get('file_name', '') or 'upload.bin'
env = C.make_api_env(_ctx)
return await C.doc_upload(env, _ns, _file_data, _file_name)