File size: 516 Bytes
fce98ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from abc import ABC, abstractmethod
import replicate

class GenericModel:
  def __init__(self, name: str):
    self.name = name

  @abstractmethod
  def load(self):
    pass

  @abstractmethod
  def generate(self, prompt: str):
    pass

class ReplicateModel(GenericModel):
  def __init__(self, name: str):
    super().__init__(name)

  def load(self):
    return self

  def generate(self, prompt: str):
    iterator = replicate.run(self.name, input={'prompt': prompt})
    return ''.join(item for item in iterator)