Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AvenCores committed Apr 24, 2023
0 parents commit ffb25ae
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/ora/__pycache__
17 changes: 17 additions & 0 deletions BUILD/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from sys import platform
from os import system


if platform == "win32":
system("rd /s /q build")
system("rd /s /q dist")
system("del /q *.spec")
system(f'pyinstaller --noconfirm --onefile --icon "cli.ico" --add-data "../ora;." "../main.py"')
system("del /q *.spec")
system("rd /s /q build")
system("rd /s /q %USERPROFILE%\AppData\Local\pyinstaller")
system("explorer dist")

if platform == "linux" or platform == "linux2" or platform == "unix":
print("Для данной системы не поддерживается автоматическая сборка (возможно в будущем добавлю)!")
input()
Binary file added BUILD/cli.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions BUILD/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyinstaller
termcolor
requests
openai
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[![Youtube](https://user-images.githubusercontent.com/64781822/185656066-cdb875f1-ade6-4499-ae50-79a4f61fdc3e.png)](https://www.youtube.com/@hzfmain/) [![Telegram](https://user-images.githubusercontent.com/64781822/185657127-657c530b-3849-4931-ab91-63d6f0508330.png)](https://t.me/hzfnews) [![VK](https://user-images.githubusercontent.com/64781822/185657778-21a240e2-da1f-4b72-b37e-447c9adebfcb.png)](https://vk.com/hzforum1) [![Discord](https://user-images.githubusercontent.com/64781822/185659753-b997c6db-c91a-42c0-8876-6826d46568ba.png)](https://discord.com/invite/7bneGfUS5h)
___
# 💻 Меню
![menu-windows](https://i.imgur.com/6ylMPJa.png)
___
# 👻 Установка
* **pip install -r requirements.txt**
___
# 💎 Запуск
* **python main.py** or **main.exe**
___
# 💰 Поддержать проект:

+ #### **QIWI Кошелёк**
+ [**`Перевод по никнейму`**](https://qiwi.com/n/AVENCORESDONATE)
+ **Сбер:** 2202 2050 7215 4401
+ **ВТБ:** 2200 2404 1001 8580
Binary file added main.exe
Binary file not shown.
38 changes: 38 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from termcolor import colored
from sys import platform
from os import system
import ora

def clear():
if platform == "linux" or platform == "linux2" or platform == "unix":
system("clear")
elif platform == "win32":
system("cls")
else:
system("clear")

clear()
colors = ['red', 'yellow', 'green', 'cyan', 'light_blue', 'magenta']
color_index = 0
bannercli ="""███████╗██████╗░███████╗███████╗  ░█████╗░██╗░░██╗░█████╗░████████╗░██████╗░██████╗░████████╗
██╔════╝██╔══██╗██╔════╝██╔════╝  ██╔══██╗██║░░██║██╔══██╗╚══██╔══╝██╔════╝░██╔══██╗╚══██╔══╝
█████╗░░██████╔╝█████╗░░█████╗░░  ██║░░╚═╝███████║███████║░░░██║░░░██║░░██╗░██████╔╝░░░██║░░░
██╔══╝░░██╔══██╗██╔══╝░░██╔══╝░░  ██║░░██╗██╔══██║██╔══██║░░░██║░░░██║░░╚██╗██╔═══╝░░░░██║░░░
██║░░░░░██║░░██║███████╗███████╗  ╚█████╔╝██║░░██║██║░░██║░░░██║░░░╚██████╔╝██║░░░░░░░░██║░░░
╚═╝░░░░░╚═╝░░╚═╝╚══════╝╚══════╝  ░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░░╚═════╝░╚═╝░░░░░░░░╚═╝░░░"""

for i in range(len(bannercli)):
color = colors[i % len(colors)]
print(colored(bannercli[i], color), end="")
print(colored("\n\nAuthor: ", "red") + "@avencores")
print(colored("Telegram channel: ", "red") + "@hzfnews")
while True:
youinput = input(colored("\n👨 You ", "yellow") + colored(">> ", "green"))
try:
model = ora.CompletionModel.create('gpt-4')
prompt = youinput
response = ora.Completion.create(model = model, prompt = prompt, includeHistory = True)
output = response.completion.choices[0].text
print(colored("\n🤖 CHATGPT V4.0 ", "cyan") + colored(">> ", "green") + output)
except Exception as e:
print(colored("\n🛑 ERROR ", "light_red") + colored(">> ", "green") + str(e))
41 changes: 41 additions & 0 deletions ora/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
### Example: `ora` (use like openai pypi package) <a name="example-ora"></a>

### load model (new)

more gpt4 models in `/testing/ora_gpt4.py`

```python
# normal gpt-4: b8b12eaa-5d47-44d3-92a6-4d706f2bcacf
model = ora.CompletionModel.load(chatbot_id, 'gpt-4') # or gpt-3.5
```

#### create model / chatbot:
```python
# import ora
import ora

# create model
model = ora.CompletionModel.create(
system_prompt = 'You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible',
description = 'ChatGPT Openai Language Model',
name = 'gpt-3.5')

# init conversation (will give you a conversationId)
init = ora.Completion.create(
model = model,
prompt = 'hello world')

print(init.completion.choices[0].text)

while True:
# pass in conversationId to continue conversation

prompt = input('>>> ')
response = ora.Completion.create(
model = model,
prompt = prompt,
includeHistory = True, # remember history
conversationId = init.id)

print(response.completion.choices[0].text)
```
49 changes: 49 additions & 0 deletions ora/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from ora.model import CompletionModel
from ora.typing import OraResponse
from requests import post
from time import time
from random import randint

class Completion:
def create(
model : CompletionModel,
prompt: str,
includeHistory: bool = True,
conversationId: str or None = None) -> OraResponse:

extra = {
'conversationId': conversationId} if conversationId else {}

response = post('https://ora.sh/api/conversation',
headers = {
"host" : "ora.sh",
"authorization" : f"Bearer AY0{randint(1111, 9999)}",
"user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
"origin" : "https://ora.sh",
"referer" : "https://ora.sh/chat/",
},
json = extra | {
'chatbotId': model.id,
'input' : prompt,
'userId' : model.createdBy,
'model' : model.modelName,
'provider' : 'OPEN_AI',
'includeHistory': includeHistory}).json()

return OraResponse({
'id' : response['conversationId'],
'object' : 'text_completion',
'created': int(time()),
'model' : model.slug,
'choices': [{
'text' : response['response'],
'index' : 0,
'logprobs' : None,
'finish_reason' : 'stop'
}],
'usage': {
'prompt_tokens' : len(prompt),
'completion_tokens' : len(response['response']),
'total_tokens' : len(prompt) + len(response['response'])
}
})
55 changes: 55 additions & 0 deletions ora/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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.',
description : str = 'ChatGPT Openai Language Model',
name : str = 'gpt-3.5'):

CompletionModel.system_prompt = system_prompt
CompletionModel.description = description
CompletionModel.slug = name

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 = {
'prompt' : system_prompt,
'userId' : f'auto:{uuid4()}',
'name' : name,
'description': description})

# 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
39 changes: 39 additions & 0 deletions ora/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class OraResponse:

class Completion:

class Choices:
def __init__(self, choice: dict) -> None:
self.text = choice['text']
self.content = self.text.encode()
self.index = choice['index']
self.logprobs = choice['logprobs']
self.finish_reason = choice['finish_reason']

def __repr__(self) -> str:
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>'''

def __init__(self, choices: dict) -> None:
self.choices = [self.Choices(choice) for choice in choices]

class Usage:
def __init__(self, usage_dict: dict) -> None:
self.prompt_tokens = usage_dict['prompt_tokens']
self.completion_tokens = usage_dict['completion_tokens']
self.total_tokens = usage_dict['total_tokens']

def __repr__(self):
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>'''

def __init__(self, response_dict: dict) -> None:

self.response_dict = response_dict
self.id = response_dict['id']
self.object = response_dict['object']
self.created = response_dict['created']
self.model = response_dict['model']
self.completion = self.Completion(response_dict['choices'])
self.usage = self.Usage(response_dict['usage'])

def json(self) -> dict:
return self.response_dict
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
websocket-client
tls-client
termcolor
curl_cffi
requests
pypasser
names

0 comments on commit ffb25ae

Please sign in to comment.