0.5 缩减重构

This commit is contained in:
lix-2026
2026-04-13 19:21:42 +08:00
parent af92c4b149
commit 71fb1aee7e
2023 changed files with 21113 additions and 394493 deletions
+19 -19
View File
@@ -1,19 +1,19 @@
"""LightRAG 集成占位。阶段 1 会在这里封装真正的查询与索引。"""
from app.config import settings
class LightRAGService:
def __init__(self) -> None:
self.collection = settings.lightrag_collection
async def queue_index(self, document_id: str, raw_text: str) -> None:
"""预留方法:后续调用 LightRAG.update_index。"""
return None
async def query(self, query_text: str, user_id: str) -> str:
"""预留方法:后续调用 LightRAG.query,当前返回占位回答。"""
return f"[mock] {query_text}"
lightrag_service = LightRAGService()
"""LightRAG 集成占位。阶段 1 会在这里封装真正的查询与索引。"""
from app.config import settings
class LightRAGService:
def __init__(self) -> None:
self.collection = settings.lightrag_collection
async def queue_index(self, document_id: str, raw_text: str) -> None:
"""预留方法:后续调用 LightRAG.update_index。"""
return None
async def query(self, query_text: str, user_id: str) -> str:
"""预留方法:后续调用 LightRAG.query,当前返回占位回答。"""
return f"[mock] {query_text}"
lightrag_service = LightRAGService()
+13 -13
View File
@@ -1,13 +1,13 @@
"""MinerU OCR 占位服务。"""
class MinerUService:
async def extract_markdown(self, file_url: str) -> str:
"""
阶段 0:直接返回固定内容,保证前端流程贯通。
阶段 1:调用 MinerU CLI / SDK,从 Supabase Storage 下载文件后解析。
"""
return f"# OCR Placeholder\n\n源文件:{file_url}"
mineru_service = MinerUService()
"""MinerU OCR 占位服务。"""
class MinerUService:
async def extract_markdown(self, file_url: str) -> str:
"""
阶段 0:直接返回固定内容,保证前端流程贯通。
阶段 1:调用 MinerU CLI / SDK,从 Supabase Storage 下载文件后解析。
"""
return f"# OCR Placeholder\n\n源文件:{file_url}"
mineru_service = MinerUService()
+57 -57
View File
@@ -1,57 +1,57 @@
from __future__ import annotations
from typing import Any, Dict, Optional
import httpx
from app.config import settings
class SupabaseRestClient:
"""轻量封装 Supabase RESTful API,兼容本地 sb_secret 密钥。"""
def __init__(self) -> None:
base_url = settings.supabase_url.rstrip("/")
self.client = httpx.Client(
base_url=f"{base_url}/rest/v1",
headers={
"apikey": settings.supabase_service_role_key,
"Authorization": f"Bearer {settings.supabase_service_role_key}",
},
timeout=10.0,
)
def insert(self, table: str, payload: Dict[str, Any]) -> Dict[str, Any]:
response = self.client.post(
f"/{table}",
json=payload,
headers={"Prefer": "return=representation"},
)
response.raise_for_status()
data = response.json()
if isinstance(data, list):
return data[0]
return data
def select_one(self, table: str, filters: Dict[str, Any]) -> Optional[Dict[str, Any]]:
params = {key: f"eq.{value}" for key, value in filters.items()}
params["select"] = "*"
response = self.client.get(f"/{table}", params=params)
response.raise_for_status()
data = response.json()
if isinstance(data, list) and data:
return data[0]
return None
def update(self, table: str, filters: Dict[str, Any], payload: Dict[str, Any]) -> None:
params = {key: f"eq.{value}" for key, value in filters.items()}
response = self.client.patch(
f"/{table}",
params=params,
json=payload,
headers={"Prefer": "return=minimal"},
)
response.raise_for_status()
supabase_rest = SupabaseRestClient()
from __future__ import annotations
from typing import Any, Dict, Optional
import httpx
from app.config import settings
class SupabaseRestClient:
"""轻量封装 Supabase RESTful API,兼容本地 sb_secret 密钥。"""
def __init__(self) -> None:
base_url = settings.supabase_url.rstrip("/")
self.client = httpx.Client(
base_url=f"{base_url}/rest/v1",
headers={
"apikey": settings.supabase_service_role_key,
"Authorization": f"Bearer {settings.supabase_service_role_key}",
},
timeout=10.0,
)
def insert(self, table: str, payload: Dict[str, Any]) -> Dict[str, Any]:
response = self.client.post(
f"/{table}",
json=payload,
headers={"Prefer": "return=representation"},
)
response.raise_for_status()
data = response.json()
if isinstance(data, list):
return data[0]
return data
def select_one(self, table: str, filters: Dict[str, Any]) -> Optional[Dict[str, Any]]:
params = {key: f"eq.{value}" for key, value in filters.items()}
params["select"] = "*"
response = self.client.get(f"/{table}", params=params)
response.raise_for_status()
data = response.json()
if isinstance(data, list) and data:
return data[0]
return None
def update(self, table: str, filters: Dict[str, Any], payload: Dict[str, Any]) -> None:
params = {key: f"eq.{value}" for key, value in filters.items()}
response = self.client.patch(
f"/{table}",
params=params,
json=payload,
headers={"Prefer": "return=minimal"},
)
response.raise_for_status()
supabase_rest = SupabaseRestClient()