-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
45 lines (33 loc) · 986 Bytes
/
model.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
from abc import abstractmethod
import logging
mdl_logger = logging.getLogger('model')
def backoff_handler(details):
mdl_logger.warn("Backing off {wait:0.1f} seconds after {tries} tries ".format(**details))
class TextCompletionModel:
@abstractmethod
def __init__(self, args):
pass
@abstractmethod
def complete(self, prompt, args=None):
"""Should return the completion of the prompt"""
pass
@abstractmethod
def get_num_tokens(self, prompt, args=None):
pass
@abstractmethod
def cleanup():
pass
class ChatCompletionModel:
@abstractmethod
def __init__(self, args):
pass
@abstractmethod
def complete(self, prompt, args=None):
"""Should return the completion of the prompt, appended to preexisting chat history"""
pass
@abstractmethod
def get_num_tokens(self, prompt, args=None):
pass
@abstractmethod
def cleanup(self):
pass