summaryrefslogtreecommitdiffstats
path: root/ora
diff options
context:
space:
mode:
authorRaju Komati <komatiraju032@gmail.com>2023-04-24 20:36:24 +0200
committerRaju Komati <komatiraju032@gmail.com>2023-04-24 20:36:24 +0200
commit98afd5b9854c242dd05808951935ef61ffc36e98 (patch)
treeca4d9b08f9aca88a4daf2fc0571699359c55824c /ora
parentadded validation for model parameter (diff)
parentuserid and session_token (diff)
downloadgpt4free-98afd5b9854c242dd05808951935ef61ffc36e98.tar
gpt4free-98afd5b9854c242dd05808951935ef61ffc36e98.tar.gz
gpt4free-98afd5b9854c242dd05808951935ef61ffc36e98.tar.bz2
gpt4free-98afd5b9854c242dd05808951935ef61ffc36e98.tar.lz
gpt4free-98afd5b9854c242dd05808951935ef61ffc36e98.tar.xz
gpt4free-98afd5b9854c242dd05808951935ef61ffc36e98.tar.zst
gpt4free-98afd5b9854c242dd05808951935ef61ffc36e98.zip
Diffstat (limited to '')
-rw-r--r--ora/README.md10
-rw-r--r--ora/__init__.py16
2 files changed, 21 insertions, 5 deletions
diff --git a/ora/README.md b/ora/README.md
index b4ae0878..36bc2806 100644
--- a/ora/README.md
+++ b/ora/README.md
@@ -4,7 +4,14 @@
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
```
@@ -14,6 +21,7 @@ model = ora.CompletionModel.load(chatbot_id, 'gpt-4') # or gpt-3.5
# 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',
@@ -38,4 +46,4 @@ while True:
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
index b6389f64..36e14cd5 100644
--- a/ora/__init__.py
+++ b/ora/__init__.py
@@ -4,18 +4,23 @@ from requests import post
from time import time
from random import randint
+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 {}
- response = post('https://ora.sh/api/conversation',
- headers = {
+ cookies = {
+ "cookie" : f"__Secure-next-auth.session-token={session_token}"} if session_token else {}
+
+ 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",
@@ -25,10 +30,13 @@ class Completion:
json = extra | {
'chatbotId': model.id,
'input' : prompt,
- 'userId' : model.createdBy,
+ 'userId' : user_id if user_id else model.createdBy,
'model' : model.modelName,
'provider' : 'OPEN_AI',
'includeHistory': includeHistory}).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'],