Create DeepAi.py
Browse files- Providers/DeepAi.py +46 -0
Providers/DeepAi.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import random
|
4 |
+
import hashlib
|
5 |
+
import requests
|
6 |
+
|
7 |
+
from ...typing import sha256, Dict, get_type_hints
|
8 |
+
|
9 |
+
url = 'https://deepai.org'
|
10 |
+
model = ['gpt-3.5-turbo']
|
11 |
+
supports_stream = True
|
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 |
+
"api-key": get_api_key(user_agent),
|
29 |
+
"user-agent": user_agent
|
30 |
+
}
|
31 |
+
|
32 |
+
files = {
|
33 |
+
"chat_style": (None, "chat"),
|
34 |
+
"chatHistory": (None, json.dumps(messages))
|
35 |
+
}
|
36 |
+
|
37 |
+
r = requests.post("https://api.deepai.org/chat_response", headers=headers, files=files, stream=True)
|
38 |
+
|
39 |
+
for chunk in r.iter_content(chunk_size=None):
|
40 |
+
r.raise_for_status()
|
41 |
+
yield chunk.decode()
|
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]])
|