t.me/xtekky
commited on
Commit
·
493c37a
1
Parent(s):
66cd4b0
gpt 3.5 / customize models (site: ora.sh)
Browse files- ora/__init__.py +36 -0
- ora/model.py +32 -0
- ora/typing.py +39 -0
ora/__init__.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ora.model import CompletionModel
|
2 |
+
from ora.typing import OraResponse
|
3 |
+
from requests import post
|
4 |
+
from time import time
|
5 |
+
|
6 |
+
class Completion:
|
7 |
+
def create(
|
8 |
+
model : CompletionModel,
|
9 |
+
prompt: str,
|
10 |
+
conversationId: str or None = None) -> OraResponse:
|
11 |
+
|
12 |
+
extra = {
|
13 |
+
'conversationId': conversationId} if conversationId else {}
|
14 |
+
|
15 |
+
response = post('https://ora.sh/api/conversation', json = extra | {
|
16 |
+
'chatbotId': model.id,
|
17 |
+
'input' : prompt,
|
18 |
+
'userId' : model.createdBy}).json()
|
19 |
+
|
20 |
+
return OraResponse({
|
21 |
+
'id' : response['conversationId'],
|
22 |
+
'object' : 'text_completion',
|
23 |
+
'created': int(time()),
|
24 |
+
'model' : model.slug,
|
25 |
+
'choices': [{
|
26 |
+
'text' : response['response'],
|
27 |
+
'index' : 0,
|
28 |
+
'logprobs' : None,
|
29 |
+
'finish_reason' : 'stop'
|
30 |
+
}],
|
31 |
+
'usage': {
|
32 |
+
'prompt_tokens' : len(prompt),
|
33 |
+
'completion_tokens' : len(response['response']),
|
34 |
+
'total_tokens' : len(prompt) + len(response['response'])
|
35 |
+
}
|
36 |
+
})
|
ora/model.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from uuid import uuid4
|
2 |
+
from requests import post
|
3 |
+
|
4 |
+
class CompletionModel:
|
5 |
+
system_prompt = None
|
6 |
+
description = None
|
7 |
+
createdBy = None
|
8 |
+
createdAt = None
|
9 |
+
slug = None
|
10 |
+
id = None
|
11 |
+
|
12 |
+
def create(
|
13 |
+
system_prompt: str = 'You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible',
|
14 |
+
description : str = 'ChatGPT Openai Language Model',
|
15 |
+
name : str = 'gpt-3.5'):
|
16 |
+
|
17 |
+
CompletionModel.system_prompt = system_prompt
|
18 |
+
CompletionModel.description = description
|
19 |
+
CompletionModel.slug = name
|
20 |
+
|
21 |
+
response = post('https://ora.sh/api/assistant', json = {
|
22 |
+
'prompt' : system_prompt,
|
23 |
+
'userId' : f'auto:{uuid4()}',
|
24 |
+
'name' : name,
|
25 |
+
'description': description})
|
26 |
+
|
27 |
+
CompletionModel.id = response.json()['id']
|
28 |
+
CompletionModel.createdBy = response.json()['createdBy']
|
29 |
+
CompletionModel.createdAt = response.json()['createdAt']
|
30 |
+
|
31 |
+
return CompletionModel
|
32 |
+
|
ora/typing.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class OraResponse:
|
2 |
+
|
3 |
+
class Completion:
|
4 |
+
|
5 |
+
class Choices:
|
6 |
+
def __init__(self, choice: dict) -> None:
|
7 |
+
self.text = choice['text']
|
8 |
+
self.content = self.text.encode()
|
9 |
+
self.index = choice['index']
|
10 |
+
self.logprobs = choice['logprobs']
|
11 |
+
self.finish_reason = choice['finish_reason']
|
12 |
+
|
13 |
+
def __repr__(self) -> str:
|
14 |
+
return f'''<__main__.APIResponse.Completion.Choices(\n text = {self.text.encode()},\n index = {self.index},\n logprobs = {self.logprobs},\n finish_reason = {self.finish_reason})object at 0x1337>'''
|
15 |
+
|
16 |
+
def __init__(self, choices: dict) -> None:
|
17 |
+
self.choices = [self.Choices(choice) for choice in choices]
|
18 |
+
|
19 |
+
class Usage:
|
20 |
+
def __init__(self, usage_dict: dict) -> None:
|
21 |
+
self.prompt_tokens = usage_dict['prompt_tokens']
|
22 |
+
self.completion_tokens = usage_dict['completion_tokens']
|
23 |
+
self.total_tokens = usage_dict['total_tokens']
|
24 |
+
|
25 |
+
def __repr__(self):
|
26 |
+
return f'''<__main__.APIResponse.Usage(\n prompt_tokens = {self.prompt_tokens},\n completion_tokens = {self.completion_tokens},\n total_tokens = {self.total_tokens})object at 0x1337>'''
|
27 |
+
|
28 |
+
def __init__(self, response_dict: dict) -> None:
|
29 |
+
|
30 |
+
self.response_dict = response_dict
|
31 |
+
self.id = response_dict['id']
|
32 |
+
self.object = response_dict['object']
|
33 |
+
self.created = response_dict['created']
|
34 |
+
self.model = response_dict['model']
|
35 |
+
self.completion = self.Completion(response_dict['choices'])
|
36 |
+
self.usage = self.Usage(response_dict['usage'])
|
37 |
+
|
38 |
+
def json(self) -> dict:
|
39 |
+
return self.response_dict
|