summaryrefslogtreecommitdiffstats
path: root/ora
diff options
context:
space:
mode:
Diffstat (limited to 'ora')
-rw-r--r--ora/README.md49
-rw-r--r--ora/__init__.py62
-rw-r--r--ora/_jwt.py75
-rw-r--r--ora/model.py57
-rw-r--r--ora/typing.py39
5 files changed, 0 insertions, 282 deletions
diff --git a/ora/README.md b/ora/README.md
deleted file mode 100644
index 36bc2806..00000000
--- a/ora/README.md
+++ /dev/null
@@ -1,49 +0,0 @@
-### Example: `ora` (use like openai pypi package) <a name="example-ora"></a>
-
-### load model (new)
-
-more gpt4 models in `/testing/ora_gpt4.py`
-
-find the userid by visiting https://ora.sh/api/auth/session ( must be logged in on the site )
-and session_token in the cookies, it should be: __Secure-next-auth.session-token
-
-```python
-# if using CompletionModel.load set these
-ora.user_id = '...'
-ora.session_token = '...'
-
-# 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)
-```
diff --git a/ora/__init__.py b/ora/__init__.py
deleted file mode 100644
index db8252cd..00000000
--- a/ora/__init__.py
+++ /dev/null
@@ -1,62 +0,0 @@
-from ora.model import CompletionModel
-from ora.typing import OraResponse
-from requests import post
-from time import time
-from random import randint
-from ora._jwt import do_jwt
-
-user_id = None
-session_token = None
-
-class Completion:
- def create(
- model : CompletionModel,
- prompt: str,
- includeHistory: bool = True,
- conversationId: str or None = None) -> OraResponse:
- extra = {
- 'conversationId': conversationId} if conversationId else {}
-
- cookies = {
- "cookie" : f"__Secure-next-auth.session-token={session_token}"} if session_token else {}
-
- json_data = extra | {
- 'chatbotId': model.id,
- 'input' : prompt,
- 'userId' : user_id if user_id else model.createdBy,
- 'model' : model.modelName,
- 'provider' : 'OPEN_AI',
- 'includeHistory': includeHistory}
-
-
- response = post('https://ora.sh/api/conversation',
- headers = cookies | {
- "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/",
- "x-signed-token": do_jwt(json_data)
- },
- json = json_data).json()
-
- if response.get('error'):
- raise Exception('''set ora.user_id and ora.session_token\napi response: %s''' % response['error'])
-
- 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/_jwt.py b/ora/_jwt.py
deleted file mode 100644
index cc8b2349..00000000
--- a/ora/_jwt.py
+++ /dev/null
@@ -1,75 +0,0 @@
-import jwt
-from datetime import datetime, timedelta
-# from cryptography.hazmat.primitives import serialization
-# from cryptography.hazmat.primitives.serialization import load_pem_private_key
-# from cryptography.hazmat.backends import default_backend
-
-
-def do_jwt(json_data: dict):
-
- private_key = b'''-----BEGIN RSA PRIVATE KEY-----
-MIIJKAIBAAKCAgEAxv9TLZP2TnsR512LqzT52N6Z9ixKmUA11jy0IXH0dEbdbfBw
-eeWrXoTuIYcY8Dkg/+q33ppfujYf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{
- **json_data,
- 'iat': int(datetime.now().timestamp()),
- 'exp': int((datetime.now() + timedelta(minutes=10)).timestamp()),
- 'iss': 'https://ora.sh'
- }
-
- return jwt.encode(payload, private_key, algorithm='RS256', headers=header) \ No newline at end of file
diff --git a/ora/model.py b/ora/model.py
deleted file mode 100644
index 34720c2d..00000000
--- a/ora/model.py
+++ /dev/null
@@ -1,57 +0,0 @@
-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 \ No newline at end of file
diff --git a/ora/typing.py b/ora/typing.py
deleted file mode 100644
index f3f0aebf..00000000
--- a/ora/typing.py
+++ /dev/null
@@ -1,39 +0,0 @@
-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