diff options
author | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-04-24 19:59:42 +0200 |
---|---|---|
committer | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-04-24 19:59:42 +0200 |
commit | 78662c779a76c5fd826205ed7028115269fd3501 (patch) | |
tree | 2e0a116d4a5f1ff68b0b5232f6c5b0e4c7461dc3 /ora/__init__.py | |
parent | Merge pull request #90 from Whoffie/main (diff) | |
download | gpt4free-78662c779a76c5fd826205ed7028115269fd3501.tar gpt4free-78662c779a76c5fd826205ed7028115269fd3501.tar.gz gpt4free-78662c779a76c5fd826205ed7028115269fd3501.tar.bz2 gpt4free-78662c779a76c5fd826205ed7028115269fd3501.tar.lz gpt4free-78662c779a76c5fd826205ed7028115269fd3501.tar.xz gpt4free-78662c779a76c5fd826205ed7028115269fd3501.tar.zst gpt4free-78662c779a76c5fd826205ed7028115269fd3501.zip |
Diffstat (limited to '')
-rw-r--r-- | ora/__init__.py | 16 |
1 files changed, 12 insertions, 4 deletions
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'], |