-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_llm.py
75 lines (60 loc) · 1.36 KB
/
base_llm.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from abc import ABC, abstractmethod
class BaseLLM(ABC):
"""
Abstract Language Model manager class for managing interactions with language models.
"""
def __init__(self):
"""
Initialize the Language Model Manager.
"""
self.messages = []
@property
@abstractmethod
def save_history(self):
pass
@property
@abstractmethod
def context(self):
pass
@property
@abstractmethod
def instruction_tokens(self):
pass
@property
@abstractmethod
def generated_tokens(self):
pass
@abstractmethod
def clear_token_count(self):
pass
@abstractmethod
def prompt(self, instruction, max_tokens=1024) -> str:
"""
Abstract method to prompt the language model with an instruction and return the response.
Args:
instruction (str): The instruction to prompt the language model with.
max_tokens (int): Maximum number of tokens to generate in the response.
Returns:
str: The response from the language model.
"""
pass
@abstractmethod
def clear_context(self):
"""
Abstract method to clear context of the conversation.
"""
pass
@abstractmethod
def add_response(self, response):
"""
Abstract method to add response to context of the conversation.
Args:
response (str): Response to be added to history of the conversation.
"""
pass
@abstractmethod
def get_name(self):
"""
Abstract method to get name of a model.
"""
pass