ka1kuk commited on
Commit
727a876
1 Parent(s): f5845e5

Update g4f/Provider/Providers/DeepAi.py

Browse files
Files changed (1) hide show
  1. g4f/Provider/Providers/DeepAi.py +58 -79
g4f/Provider/Providers/DeepAi.py CHANGED
@@ -1,95 +1,74 @@
1
- import os
2
- import time
3
  import json
4
- import uuid
5
- import random
6
- import hashlib
7
  import requests
8
-
9
  from ...typing import sha256, Dict, get_type_hints
10
- from datetime import datetime
11
 
12
- url: str = 'https://ai.ls'
13
- model: str = 'gpt-3.5-turbo'
 
14
  supports_stream = True
15
  needs_auth = False
16
- working = True
17
-
18
-
19
- class Utils:
20
- def hash(json_data: Dict[str, str]) -> sha256:
21
-
22
- secretKey: bytearray = bytearray([79, 86, 98, 105, 91, 84, 80, 78, 123, 83,
23
- 35, 41, 99, 123, 51, 54, 37, 57, 63, 103, 59, 117, 115, 108, 41, 67, 76])
24
-
25
- base_string: str = '%s:%s:%s:%s' % (
26
- json_data['t'],
27
- json_data['m'],
28
- 'WI,2rU#_r:r~aF4aJ36[.Z(/8Rv93Rf',
29
- len(json_data['m'])
30
- )
31
-
32
- return hashlib.sha256(base_string.encode()).hexdigest()
33
-
34
- def format_timestamp(timestamp: int) -> str:
35
-
36
- e = timestamp
37
- n = e % 10
38
- r = n + 1 if n % 2 == 0 else n
39
- return str(e - n + r)
40
- def getV():
41
- crossref = requests.get("https://ai.ls"+ requests.get("https://ai.ls/?chat=1").text.split('crossorigin href="')[1].split('"')[0]).text.split('G4="')[1].split('"')[0]
42
- return crossref
43
 
44
- def _create_completion(model: str, messages: list, stream: bool = False, temperature: float = 0.6, **kwargs):
 
45
 
46
- headers = {
47
- 'authority': 'api.caipacity.com',
48
- 'accept': '*/*',
49
- 'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
50
- 'authorization': 'Bearer free',
51
- 'client-id': str(uuid.uuid4()),
52
- 'client-v': Utils.getV(),
53
- 'content-type': 'application/json',
54
- 'origin': 'https://ai.ls',
55
- 'referer': 'https://ai.ls/',
56
- 'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
57
- 'sec-ch-ua-mobile': '?0',
58
- 'sec-ch-ua-platform': '"Windows"',
59
- 'sec-fetch-dest': 'empty',
60
- 'sec-fetch-mode': 'cors',
61
- 'sec-fetch-site': 'cross-site',
62
- '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',
63
- }
64
 
65
- params = {
66
- 'full': 'false',
67
- }
68
 
69
- timestamp = Utils.format_timestamp(int(time.time() * 1000))
 
70
 
71
- sig = {
72
- 'd': datetime.now().strftime('%Y-%m-%d'),
73
- 't': timestamp,
74
- 's': Utils.hash({
75
- 't': timestamp,
76
- 'm': messages[-1]['content']})}
77
 
78
- json_data = json.dumps(separators=(',', ':'), obj={
79
- 'model': 'gpt-3.5-turbo',
80
- 'temperature': temperature,
81
- 'stream': True,
82
- 'messages': messages} | sig)
83
 
84
- response = requests.post('https://api.caipacity.com/v1/chat/completions',
85
- headers=headers, data=json_data, stream=True)
 
86
 
87
- for token in response.iter_lines():
88
- if b'content' in token:
89
- completion_chunk = json.loads(token.decode().replace('data: ', ''))
90
- token = completion_chunk['choices'][0]['delta'].get('content')
91
- if token != None:
92
- yield token
93
 
94
  params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
95
- '(%s)' % ', '.join([f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
 
 
 
 
1
  import json
2
+ import os
 
 
3
  import requests
4
+ import js2py
5
  from ...typing import sha256, Dict, get_type_hints
 
6
 
7
+
8
+ url = "https://api.deepai.org/"
9
+ model = ['gpt-3.5-turbo']
10
  supports_stream = True
11
  needs_auth = False
12
+ working = True
13
+
14
+ token_js = """
15
+ var agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36'
16
+ var a, b, c, d, e, h, f, l, g, k, m, n, r, x, C, E, N, F, T, O, P, w, D, G, Q, R, W, I, aa, fa, na, oa, ha, ba, X, ia, ja, ka, J, la, K, L, ca, S, U, M, ma, B, da, V, Y;
17
+ h = Math.round(1E11 * Math.random()) + "";
18
+ f = function () {
19
+ for (var p = [], q = 0; 64 > q;) p[q] = 0 | 4294967296 * Math.sin(++q % Math.PI);
20
+
21
+ return function (t) {
22
+ var v, y, H, ea = [v = 1732584193, y = 4023233417, ~v, ~y],
23
+ Z = [],
24
+ A = unescape(encodeURI(t)) + "\u0080",
25
+ z = A.length;
26
+ t = --z / 4 + 2 | 15;
27
+ for (Z[--t] = 8 * z; ~z;) Z[z >> 2] |= A.charCodeAt(z) << 8 * z--;
28
+ for (q = A = 0; q < t; q += 16) {
29
+ for (z = ea; 64 > A; z = [H = z[3], v + ((H = z[0] + [v & y | ~v & H, H & v | ~H & y, v ^ y ^ H, y ^ (v | ~H)][z = A >> 4] + p[A] + ~~Z[q | [A, 5 * A + 1, 3 * A + 5, 7 * A][z] & 15]) << (z = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21][4 * z + A++ % 4]) | H >>> -z), v, y]) v = z[1] | 0, y = z[2];
30
+ for (A = 4; A;) ea[--A] += z[A]
31
+ }
32
+ for (t = ""; 32 > A;) t += (ea[A >> 3] >> 4 * (1 ^ A++) & 15).toString(16);
33
+ return t.split("").reverse().join("")
34
+ }
35
+ }();
 
 
 
36
 
37
+ "tryit-" + h + "-" + f(agent + f(agent + f(agent + h + "x")));
38
+ """
39
 
40
+ uuid4_js = """
41
+ function uuidv4() {
42
+ for (var a = [], b = 0; 36 > b; b++) a[b] = "0123456789abcdef".substr(Math.floor(16 * Math.random()), 1);
43
+ a[14] = "4";
44
+ a[19] = "0123456789abcdef".substr(a[19] & 3 | 8, 1);
45
+ a[8] = a[13] = a[18] = a[23] = "-";
46
+ return a.join("")
47
+ }
48
+ uuidv4();"""
 
 
 
 
 
 
 
 
 
49
 
50
+ def create_session():
51
+ url = "https://api.deepai.org/save_chat_session"
 
52
 
53
+ payload = {'uuid': js2py.eval_js(uuid4_js), "title":"", "chat_style": "chat", "messages": '[]'}
54
+ headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"}
55
 
56
+ response = requests.request("POST", url, headers=headers, data=payload)
57
+ return response
 
 
 
 
58
 
59
+ def _create_completion(model: str, messages:list, stream: bool = True, **kwargs):
60
+ create_session()
61
+ url = "https://api.deepai.org/make_me_a_pizza"
 
 
62
 
63
+ payload = {'chas_style': "chat", "chatHistory": json.dumps(messages)}
64
+ api_key = js2py.eval_js(token_js)
65
+ headers = {"api-key": api_key, "User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"}
66
 
67
+ response = requests.request("POST", url, headers=headers, data=payload, stream=True)
68
+ for chunk in response.iter_content(chunk_size=None):
69
+ response.raise_for_status()
70
+ yield chunk.decode()
 
 
71
 
72
  params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
73
+ '(%s)' % ', '.join(
74
+ [f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])