summaryrefslogtreecommitdiffstats
path: root/ora/model.py
blob: 34720c2df938a62ee5ce2e68be4bda67b2e9e744 (plain) (blame)
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
from uuid     import uuid4
from requests import post

class CompletionModel:
    system_prompt = None
    description   = None
    createdBy     = None
    createdAt     = None
    slug          = None
    id            = None
    modelName     = None
    model         = 'gpt-3.5-turbo'
    
    def create(
        system_prompt: str = 'You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible', 
        description  : str = 'ChatGPT Openai Language Model',
        name         : str = 'gpt-3.5'):

        CompletionModel.system_prompt = system_prompt
        CompletionModel.description   = description
        CompletionModel.slug          = name
        
        json_data = {
            'prompt'     : system_prompt,
            'userId'     : f'auto:{uuid4()}',
            'name'       : name,
            'description': description}
        
        headers = {
            'Origin'    : 'https://ora.sh',
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15',
            'Referer'   : 'https://ora.sh/',
            'Host'      : 'ora.sh',
        }
        
        response = post('https://ora.sh/api/assistant', headers = headers, json = json_data)
        
        print(response.json())
        
        CompletionModel.id        = response.json()['id']
        CompletionModel.createdBy = response.json()['createdBy']
        CompletionModel.createdAt = response.json()['createdAt']
        
        return CompletionModel
    
    def load(chatbotId: str, modelName: str = 'gpt-3.5-turbo', userId: str = None):
        if userId is None: userId = f'{uuid4()}'

        CompletionModel.system_prompt = None
        CompletionModel.description   = None
        CompletionModel.slug          = None
        CompletionModel.id        = chatbotId
        CompletionModel.createdBy = userId
        CompletionModel.createdAt = None
        CompletionModel.modelName = modelName
        
        return CompletionModel