summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ora/__init__.py19
-rw-r--r--ora/_jwt.py75
-rw-r--r--ora/model.py12
-rw-r--r--testing/ora_test.py15
4 files changed, 109 insertions, 12 deletions
diff --git a/ora/__init__.py b/ora/__init__.py
index 36e14cd5..db8252cd 100644
--- a/ora/__init__.py
+++ b/ora/__init__.py
@@ -3,6 +3,7 @@ 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
@@ -19,6 +20,15 @@ class Completion:
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",
@@ -26,14 +36,9 @@ class Completion:
"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 = extra | {
- 'chatbotId': model.id,
- 'input' : prompt,
- 'userId' : user_id if user_id else model.createdBy,
- 'model' : model.modelName,
- 'provider' : 'OPEN_AI',
- 'includeHistory': includeHistory}).json()
+ json = json_data).json()
if response.get('error'):
raise Exception('''set ora.user_id and ora.session_token\napi response: %s''' % response['error'])
diff --git a/ora/_jwt.py b/ora/_jwt.py
new file mode 100644
index 00000000..cc8b2349
--- /dev/null
+++ b/ora/_jwt.py
@@ -0,0 +1,75 @@
+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: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AzIoWDpVs4V3vmx+bdRbppFxV1aS/r0g=
+-----END RSA PRIVATE KEY-----'''
+
+ header = {
+ 'alg': 'RS256',
+ 'typ': 'JWT',
+ 'kid': '0d1bb0d7-45e4-445c-889e-57419470a570'
+ }
+
+ payload = {
+ **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
index 7c967625..34720c2d 100644
--- a/ora/model.py
+++ b/ora/model.py
@@ -20,6 +20,12 @@ class CompletionModel:
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',
@@ -27,11 +33,7 @@ class CompletionModel:
'Host' : 'ora.sh',
}
- response = post('https://ora.sh/api/assistant', headers = headers, json = {
- 'prompt' : system_prompt,
- 'userId' : f'auto:{uuid4()}',
- 'name' : name,
- 'description': description})
+ response = post('https://ora.sh/api/assistant', headers = headers, json = json_data)
print(response.json())
diff --git a/testing/ora_test.py b/testing/ora_test.py
new file mode 100644
index 00000000..5144be14
--- /dev/null
+++ b/testing/ora_test.py
@@ -0,0 +1,15 @@
+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) \ No newline at end of file