将flask改成fastapi
This commit is contained in:
20
rag/prompts/template.py
Normal file
20
rag/prompts/template.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
|
||||
|
||||
PROMPT_DIR = os.path.dirname(__file__)
|
||||
|
||||
_loaded_prompts = {}
|
||||
|
||||
|
||||
def load_prompt(name: str) -> str:
|
||||
if name in _loaded_prompts:
|
||||
return _loaded_prompts[name]
|
||||
|
||||
path = os.path.join(PROMPT_DIR, f"{name}.md")
|
||||
if not os.path.isfile(path):
|
||||
raise FileNotFoundError(f"Prompt file '{name}.md' not found in prompts/ directory.")
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
content = f.read().strip()
|
||||
_loaded_prompts[name] = content
|
||||
return content
|
||||
Reference in New Issue
Block a user