__init__.py 664 B

12345678910111213141516171819202122232425
  1. import os
  2. from utils import load_file
  3. PROMPT_DIR = os.path.dirname(__file__)
  4. TEMPLATE_WITH_TOOL = load_file(os.path.join(PROMPT_DIR, 'template_with_tool.txt'))
  5. class PromptTemplate:
  6. """A prompt template."""
  7. def __init__(self, template: str):
  8. self.template: str = template
  9. def __call__(self, **kwargs) -> str:
  10. return self.template.format(**kwargs)
  11. class ToolPromptTemplate(PromptTemplate):
  12. def __init__(self, use_tool: bool):
  13. if use_tool:
  14. template = TEMPLATE_WITH_TOOL
  15. else:
  16. raise NotImplementedError('Evaluation without tool is not supported yet.')
  17. super().__init__(template)