TwitterTosChatBot / src /prompt.py
zinoubm's picture
refactoring the code on the SOLID principles
5a1b165
raw
history blame
856 Bytes
from abc import ABC, abstractmethod
class Prompt(ABC):
def load_prompt(path):
with open(path) as f:
lines = f.readlines()
return "".join(lines)
@abstractmethod
def load(self, path):
pass
class QuestionAnsweringPrompt(Prompt):
def __init__(self, result, question):
result = result
question = question
def load(self, path):
prompt = (
self.load_prompt(path)
.replace("<<PASSAGE>>", self.result["index"]["content"])
.replace("<<QUESTION>>", self.question)
)
return prompt
class PassageSummarizationPrompt(Prompt):
def __init__(self, answers):
self.answers = answers
def load(self, path):
prompt = self.load_prompt(path).replace("<<PASSAGE>>", "\n".join(self.answers))
return prompt