diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c00742 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/ora/__pycache__ \ No newline at end of file diff --git a/BUILD/build.py b/BUILD/build.py new file mode 100644 index 0000000..a8e1427 --- /dev/null +++ b/BUILD/build.py @@ -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() diff --git a/BUILD/cli.ico b/BUILD/cli.ico new file mode 100644 index 0000000..77b09b9 Binary files /dev/null and b/BUILD/cli.ico differ diff --git a/BUILD/requirements.txt b/BUILD/requirements.txt new file mode 100644 index 0000000..9e66065 --- /dev/null +++ b/BUILD/requirements.txt @@ -0,0 +1,4 @@ +pyinstaller +termcolor +requests +openai diff --git a/README.md b/README.md new file mode 100644 index 0000000..c9f3ba4 --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/main.exe b/main.exe new file mode 100644 index 0000000..f71237e Binary files /dev/null and b/main.exe differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..53b6233 --- /dev/null +++ b/main.py @@ -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)) diff --git a/ora/README.md b/ora/README.md new file mode 100644 index 0000000..b4ae087 --- /dev/null +++ b/ora/README.md @@ -0,0 +1,41 @@ +### Example: `ora` (use like openai pypi package) + +### 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) +``` \ No newline at end of file diff --git a/ora/__init__.py b/ora/__init__.py new file mode 100644 index 0000000..b6389f6 --- /dev/null +++ b/ora/__init__.py @@ -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']) + } + }) \ No newline at end of file diff --git a/ora/model.py b/ora/model.py new file mode 100644 index 0000000..e75e587 --- /dev/null +++ b/ora/model.py @@ -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 \ No newline at end of file diff --git a/ora/typing.py b/ora/typing.py new file mode 100644 index 0000000..f3f0aeb --- /dev/null +++ b/ora/typing.py @@ -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 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1579270 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +websocket-client +tls-client +termcolor +curl_cffi +requests +pypasser +names