Spaces:
No application file
No application file
File size: 1,491 Bytes
5a1b165 64ef551 fa46f05 64ef551 5a1b165 64ef551 5a1b165 64ef551 5a1b165 64ef551 5a1b165 64ef551 5a1b165 64ef551 fa46f05 5a1b165 64ef551 5a1b165 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
from abc import ABC, abstractmethod
# Prompt Loaders
class PromptLoader(ABC):
@abstractmethod
def load_prompt(self, path):
pass
class TextPromptLoader(PromptLoader):
def load_prompt(self, path):
with open(path) as f:
lines = f.readlines()
return "".join(lines)
# Prompts
class Prompt(ABC):
def __init__(self, prompt_loader: PromptLoader):
self.prompt_loader = prompt_loader
def load_prompt(self, path):
return self.prompt_loader.load_prompt(path)
@abstractmethod
def load(self, path):
pass
class QuestionAnsweringPrompt(Prompt):
def __init__(self, passage, question, prompt_loader):
super().__init__(prompt_loader=prompt_loader)
self.passage = passage
self.question = question
# trust me, you'll need this later
# .replace("<<PASSAGE>>", self.result["index"]["content"])
def load(self, path):
prompt = (
self.load_prompt(path)
.replace("<<PASSAGE>>", self.passage)
.replace("<<QUESTION>>", self.question)
)
return prompt
class PassageSummarizationPrompt(Prompt):
def __init__(self, passage, prompt_loader):
super().__init__(prompt_loader=prompt_loader)
self.passage = passage
# prompt = self.load_prompt(path).replace("<<PASSAGE>>", )
def load(self, path):
prompt = self.load_prompt(path).replace("<<PASSAGE>>", self.passage)
return prompt
|