31 lines
798 B
Python
31 lines
798 B
Python
"""
|
||
最小可用的 RAG 服务占位实现。
|
||
|
||
当前版本支持两种简单来源:
|
||
- RAG_STATIC_CONTEXT:直接写在环境变量中的固定知识
|
||
- RAG_CONTEXT_FILE:读取本地文件全文作为知识上下文
|
||
|
||
后续如果要接真正的向量检索,可以直接替换 retrieve 方法实现。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from pathlib import Path
|
||
|
||
from utils.env import env_str
|
||
|
||
|
||
class RagService:
|
||
async def retrieve(self, query: str) -> str:
|
||
_ = query
|
||
context_file = env_str("RAG_CONTEXT_FILE")
|
||
if context_file:
|
||
path = Path(context_file).expanduser()
|
||
if path.exists() and path.is_file():
|
||
return path.read_text(encoding="utf-8")
|
||
|
||
return env_str("RAG_STATIC_CONTEXT")
|
||
|
||
|
||
rag_service = RagService()
|