Spaces:
Sleeping
Sleeping
File size: 975 Bytes
a44bd4e | 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 |
class ContextAttributeError(BaseException):
def __init__(self, message):
self.message = message
super().__init__(self.message)
class Context:
def __init__(self) -> None:
self.msg = []
pass
def add_system_prompt(self, prompt: str):
pt = {
'role': 'system',
'content': prompt
}
# replace the last system prompt if it exists or insert to 0 if it doesn't
if len(self.msg) > 0 and self.msg[0]['role'] == 'system':
self.msg[0] = pt
else:
self.msg.insert(0, pt)
def add_user_prompt(self, prompt: str):
pt = {
'role': 'user',
'content': prompt
}
self.msg.append(pt)
def remove_last_prompt(self):
self.msg.pop(-1)
def add_assistant_prompt(self, prompt: str):
pt = {
'role': 'assistant',
'content': prompt
}
self.msg.append(pt)
|