mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-01 09:27:46 +00:00
### What problem does this PR solve? #9082 #6365 <u> **WARNING: it's not compatible with the older version of `Agent` module, which means that `Agent` from older versions can not work anymore.**</u> ### Type of change - [x] New Feature (non-breaking change which adds functionality)
21 lines
504 B
Python
21 lines
504 B
Python
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
|