Update g4f/Provider/Providers/DeepAi.py
Browse files- g4f/Provider/Providers/DeepAi.py +59 -30
g4f/Provider/Providers/DeepAi.py
CHANGED
|
@@ -1,46 +1,75 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import json
|
| 3 |
import random
|
| 4 |
-
import
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
from ...typing import sha256, Dict, get_type_hints
|
| 8 |
|
| 9 |
-
url =
|
| 10 |
model = ['gpt-3.5-turbo']
|
| 11 |
-
supports_stream =
|
| 12 |
needs_auth = False
|
| 13 |
|
| 14 |
-
def _create_completion(model: str, messages: list, stream: bool, **kwargs):
|
| 15 |
-
def md5(text: str) -> str:
|
| 16 |
-
return hashlib.md5(text.encode()).hexdigest()[::-1]
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def get_api_key(user_agent: str) -> str:
|
| 20 |
-
part1 = str(random.randint(0, 10**11))
|
| 21 |
-
part2 = md5(user_agent + md5(user_agent + md5(user_agent + part1 + "x")))
|
| 22 |
-
|
| 23 |
-
return f"tryit-{part1}-{part2}"
|
| 24 |
-
|
| 25 |
-
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
headers = {
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
"
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
|
| 45 |
'(%s)' % ', '.join(
|
| 46 |
-
[f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
|
|
|
|
| 1 |
import os
|
| 2 |
+
import requests
|
| 3 |
import json
|
| 4 |
import random
|
| 5 |
+
import time
|
| 6 |
+
import string
|
|
|
|
| 7 |
from ...typing import sha256, Dict, get_type_hints
|
| 8 |
|
| 9 |
+
url = "https://wewordle.org/gptapi/v1/android/turbo"
|
| 10 |
model = ['gpt-3.5-turbo']
|
| 11 |
+
supports_stream = False
|
| 12 |
needs_auth = False
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
def _create_completion(model: str, messages: list, stream: bool, **kwargs):
|
| 16 |
+
base = ''
|
| 17 |
+
for message in messages:
|
| 18 |
+
base += '%s: %s\n' % (message['role'], message['content'])
|
| 19 |
+
base += 'assistant:'
|
| 20 |
+
# randomize user id and app id
|
| 21 |
+
_user_id = ''.join(random.choices(
|
| 22 |
+
f'{string.ascii_lowercase}{string.digits}', k=16))
|
| 23 |
+
_app_id = ''.join(random.choices(
|
| 24 |
+
f'{string.ascii_lowercase}{string.digits}', k=31))
|
| 25 |
+
# make current date with format utc
|
| 26 |
+
_request_date = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime())
|
| 27 |
headers = {
|
| 28 |
+
'accept': '*/*',
|
| 29 |
+
'pragma': 'no-cache',
|
| 30 |
+
'Content-Type': 'application/json',
|
| 31 |
+
'Connection': 'keep-alive'
|
| 32 |
}
|
| 33 |
+
data = {
|
| 34 |
+
"user": _user_id,
|
| 35 |
+
"messages": [
|
| 36 |
+
{"role": "user", "content": base}
|
| 37 |
+
],
|
| 38 |
+
"subscriber": {
|
| 39 |
+
"originalPurchaseDate": None,
|
| 40 |
+
"originalApplicationVersion": None,
|
| 41 |
+
"allPurchaseDatesMillis": {},
|
| 42 |
+
"entitlements": {
|
| 43 |
+
"active": {},
|
| 44 |
+
"all": {}
|
| 45 |
+
},
|
| 46 |
+
"allPurchaseDates": {},
|
| 47 |
+
"allExpirationDatesMillis": {},
|
| 48 |
+
"allExpirationDates": {},
|
| 49 |
+
"originalAppUserId": f"$RCAnonymousID:{_app_id}",
|
| 50 |
+
"latestExpirationDate": None,
|
| 51 |
+
"requestDate": _request_date,
|
| 52 |
+
"latestExpirationDateMillis": None,
|
| 53 |
+
"nonSubscriptionTransactions": [],
|
| 54 |
+
"originalPurchaseDateMillis": None,
|
| 55 |
+
"managementURL": None,
|
| 56 |
+
"allPurchasedProductIdentifiers": [],
|
| 57 |
+
"firstSeen": _request_date,
|
| 58 |
+
"activeSubscriptions": []
|
| 59 |
+
}
|
| 60 |
}
|
| 61 |
+
response = requests.post(url, headers=headers, data=json.dumps(data))
|
| 62 |
+
if response.status_code == 200:
|
| 63 |
+
_json = response.json()
|
| 64 |
+
if 'message' in _json:
|
| 65 |
+
message_content = _json['message']['content']
|
| 66 |
+
message_content = message_content.replace('**assistant:** ', '')
|
| 67 |
+
yield message_content
|
| 68 |
+
else:
|
| 69 |
+
print(f"Error Occurred::{response.status_code}")
|
| 70 |
+
return None
|
| 71 |
|
| 72 |
|
| 73 |
params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
|
| 74 |
'(%s)' % ', '.join(
|
| 75 |
+
[f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
|