starsaround commited on
Commit
35e3615
1 Parent(s): 256b5af

Upload 122 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. g4f/Provider/AItianhu.py +73 -0
  2. g4f/Provider/Acytoo.py +51 -0
  3. g4f/Provider/AiService.py +36 -0
  4. g4f/Provider/Aichat.py +54 -0
  5. g4f/Provider/Ails.py +106 -0
  6. g4f/Provider/Bard.py +91 -0
  7. g4f/Provider/Bing.py +283 -0
  8. g4f/Provider/ChatgptAi.py +75 -0
  9. g4f/Provider/ChatgptLogin.py +67 -0
  10. g4f/Provider/DeepAi.py +63 -0
  11. g4f/Provider/DfeHub.py +77 -0
  12. g4f/Provider/EasyChat.py +111 -0
  13. g4f/Provider/Equing.py +81 -0
  14. g4f/Provider/FastGpt.py +86 -0
  15. g4f/Provider/Forefront.py +40 -0
  16. g4f/Provider/GetGpt.py +88 -0
  17. g4f/Provider/H2o.py +101 -0
  18. g4f/Provider/HuggingChat.py +106 -0
  19. g4f/Provider/Liaobots.py +91 -0
  20. g4f/Provider/Lockchat.py +64 -0
  21. g4f/Provider/Opchatgpts.py +8 -0
  22. g4f/Provider/OpenAssistant.py +102 -0
  23. g4f/Provider/OpenaiChat.py +94 -0
  24. g4f/Provider/Raycast.py +72 -0
  25. g4f/Provider/Theb.py +97 -0
  26. g4f/Provider/V50.py +67 -0
  27. g4f/Provider/Vercel.py +353 -0
  28. g4f/Provider/Wewordle.py +65 -0
  29. g4f/Provider/Wuguokai.py +68 -0
  30. g4f/Provider/You.py +40 -0
  31. g4f/Provider/Yqcloud.py +48 -0
  32. g4f/Provider/__init__.py +68 -29
  33. g4f/Provider/__pycache__/AItianhu.cpython-311.pyc +0 -0
  34. g4f/Provider/__pycache__/AItianhu.cpython-38.pyc +0 -0
  35. g4f/Provider/__pycache__/Acytoo.cpython-311.pyc +0 -0
  36. g4f/Provider/__pycache__/Acytoo.cpython-38.pyc +0 -0
  37. g4f/Provider/__pycache__/AiService.cpython-311.pyc +0 -0
  38. g4f/Provider/__pycache__/AiService.cpython-38.pyc +0 -0
  39. g4f/Provider/__pycache__/Aichat.cpython-311.pyc +0 -0
  40. g4f/Provider/__pycache__/Aichat.cpython-38.pyc +0 -0
  41. g4f/Provider/__pycache__/Ails.cpython-311.pyc +0 -0
  42. g4f/Provider/__pycache__/Ails.cpython-38.pyc +0 -0
  43. g4f/Provider/__pycache__/Bard.cpython-311.pyc +0 -0
  44. g4f/Provider/__pycache__/Bard.cpython-38.pyc +0 -0
  45. g4f/Provider/__pycache__/Bing.cpython-311.pyc +0 -0
  46. g4f/Provider/__pycache__/Bing.cpython-38.pyc +0 -0
  47. g4f/Provider/__pycache__/ChatgptAi.cpython-311.pyc +0 -0
  48. g4f/Provider/__pycache__/ChatgptAi.cpython-38.pyc +0 -0
  49. g4f/Provider/__pycache__/ChatgptLogin.cpython-311.pyc +0 -0
  50. g4f/Provider/__pycache__/ChatgptLogin.cpython-38.pyc +0 -0
g4f/Provider/AItianhu.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from aiohttp import ClientSession, http
5
+
6
+ from ..typing import AsyncGenerator
7
+ from .base_provider import AsyncGeneratorProvider, format_prompt
8
+
9
+
10
+ class AItianhu(AsyncGeneratorProvider):
11
+ url = "https://www.aitianhu.com"
12
+ working = True
13
+ supports_gpt_35_turbo = True
14
+
15
+ @classmethod
16
+ async def create_async_generator(
17
+ cls,
18
+ model: str,
19
+ messages: list[dict[str, str]],
20
+ proxy: str = None,
21
+ **kwargs
22
+ ) -> AsyncGenerator:
23
+ headers = {
24
+ "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0",
25
+ "Accept": "application/json, text/plain, */*",
26
+ "Accept-Language": "de,en-US;q=0.7,en;q=0.3",
27
+ "Content-Type": "application/json",
28
+ "Origin": cls.url,
29
+ "Connection": "keep-alive",
30
+ "Referer": cls.url + "/",
31
+ "Sec-Fetch-Dest": "empty",
32
+ "Sec-Fetch-Mode": "cors",
33
+ "Sec-Fetch-Site": "same-origin",
34
+ }
35
+ async with ClientSession(
36
+ headers=headers,
37
+ version=http.HttpVersion10
38
+ ) as session:
39
+ data = {
40
+ "prompt": format_prompt(messages),
41
+ "options": {},
42
+ "systemMessage": "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully.",
43
+ "temperature": 0.8,
44
+ "top_p": 1,
45
+ **kwargs
46
+ }
47
+ async with session.post(
48
+ cls.url + "/api/chat-process",
49
+ proxy=proxy,
50
+ json=data,
51
+ ssl=False,
52
+ ) as response:
53
+ response.raise_for_status()
54
+ async for line in response.content:
55
+ line = json.loads(line.decode('utf-8'))
56
+ token = line["detail"]["choices"][0]["delta"].get("content")
57
+ if token:
58
+ yield token
59
+
60
+
61
+ @classmethod
62
+ @property
63
+ def params(cls):
64
+ params = [
65
+ ("model", "str"),
66
+ ("messages", "list[dict[str, str]]"),
67
+ ("stream", "bool"),
68
+ ("proxy", "str"),
69
+ ("temperature", "float"),
70
+ ("top_p", "int"),
71
+ ]
72
+ param = ", ".join([": ".join(p) for p in params])
73
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/Acytoo.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from aiohttp import ClientSession
4
+
5
+ from ..typing import AsyncGenerator
6
+ from .base_provider import AsyncGeneratorProvider
7
+
8
+
9
+ class Acytoo(AsyncGeneratorProvider):
10
+ url = 'https://chat.acytoo.com'
11
+ working = True
12
+ supports_gpt_35_turbo = True
13
+
14
+ @classmethod
15
+ async def create_async_generator(
16
+ cls,
17
+ model: str,
18
+ messages: list[dict[str, str]],
19
+ proxy: str = None,
20
+ **kwargs
21
+ ) -> AsyncGenerator:
22
+
23
+ async with ClientSession(
24
+ headers=_create_header()
25
+ ) as session:
26
+ async with session.post(
27
+ cls.url + '/api/completions',
28
+ proxy=proxy,
29
+ json=_create_payload(messages, **kwargs)
30
+ ) as response:
31
+ response.raise_for_status()
32
+ async for stream in response.content.iter_any():
33
+ if stream:
34
+ yield stream.decode()
35
+
36
+
37
+ def _create_header():
38
+ return {
39
+ 'accept': '*/*',
40
+ 'content-type': 'application/json',
41
+ }
42
+
43
+
44
+ def _create_payload(messages: list[dict[str, str]], temperature: float = 0.5, **kwargs):
45
+ return {
46
+ 'key' : '',
47
+ 'model' : 'gpt-3.5-turbo',
48
+ 'messages' : messages,
49
+ 'temperature' : temperature,
50
+ 'password' : ''
51
+ }
g4f/Provider/AiService.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import requests
4
+
5
+ from ..typing import Any, CreateResult
6
+ from .base_provider import BaseProvider
7
+
8
+
9
+ class AiService(BaseProvider):
10
+ url = "https://aiservice.vercel.app/"
11
+ working = False
12
+ supports_gpt_35_turbo = True
13
+
14
+ @staticmethod
15
+ def create_completion(
16
+ model: str,
17
+ messages: list[dict[str, str]],
18
+ stream: bool,
19
+ **kwargs: Any,
20
+ ) -> CreateResult:
21
+ base = "\n".join(f"{message['role']}: {message['content']}" for message in messages)
22
+ base += "\nassistant: "
23
+
24
+ headers = {
25
+ "accept": "*/*",
26
+ "content-type": "text/plain;charset=UTF-8",
27
+ "sec-fetch-dest": "empty",
28
+ "sec-fetch-mode": "cors",
29
+ "sec-fetch-site": "same-origin",
30
+ "Referer": "https://aiservice.vercel.app/chat",
31
+ }
32
+ data = {"input": base}
33
+ url = "https://aiservice.vercel.app/api/chat/answer"
34
+ response = requests.post(url, headers=headers, json=data)
35
+ response.raise_for_status()
36
+ yield response.json()["data"]
g4f/Provider/Aichat.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from aiohttp import ClientSession
4
+
5
+ from .base_provider import AsyncProvider, format_prompt
6
+
7
+
8
+ class Aichat(AsyncProvider):
9
+ url = "https://chat-gpt.org/chat"
10
+ working = True
11
+ supports_gpt_35_turbo = True
12
+
13
+ @staticmethod
14
+ async def create_async(
15
+ model: str,
16
+ messages: list[dict[str, str]],
17
+ proxy: str = None,
18
+ **kwargs
19
+ ) -> str:
20
+ headers = {
21
+ "authority": "chat-gpt.org",
22
+ "accept": "*/*",
23
+ "cache-control": "no-cache",
24
+ "content-type": "application/json",
25
+ "origin": "https://chat-gpt.org",
26
+ "pragma": "no-cache",
27
+ "referer": "https://chat-gpt.org/chat",
28
+ "sec-ch-ua-mobile": "?0",
29
+ "sec-ch-ua-platform": '"macOS"',
30
+ "sec-fetch-dest": "empty",
31
+ "sec-fetch-mode": "cors",
32
+ "sec-fetch-site": "same-origin",
33
+ "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
34
+ }
35
+ async with ClientSession(
36
+ headers=headers
37
+ ) as session:
38
+ json_data = {
39
+ "message": format_prompt(messages),
40
+ "temperature": kwargs.get('temperature', 0.5),
41
+ "presence_penalty": 0,
42
+ "top_p": kwargs.get('top_p', 1),
43
+ "frequency_penalty": 0,
44
+ }
45
+ async with session.post(
46
+ "https://chat-gpt.org/api/text",
47
+ proxy=proxy,
48
+ json=json_data
49
+ ) as response:
50
+ response.raise_for_status()
51
+ result = await response.json()
52
+ if not result['response']:
53
+ raise Exception(f"Error Response: {result}")
54
+ return result["message"]
g4f/Provider/Ails.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import hashlib
4
+ import time
5
+ import uuid
6
+ import json
7
+ from datetime import datetime
8
+ from aiohttp import ClientSession
9
+
10
+ from ..typing import SHA256, AsyncGenerator
11
+ from .base_provider import AsyncGeneratorProvider
12
+
13
+
14
+ class Ails(AsyncGeneratorProvider):
15
+ url: str = "https://ai.ls"
16
+ working = True
17
+ supports_gpt_35_turbo = True
18
+
19
+ @staticmethod
20
+ async def create_async_generator(
21
+ model: str,
22
+ messages: list[dict[str, str]],
23
+ stream: bool,
24
+ proxy: str = None,
25
+ **kwargs
26
+ ) -> AsyncGenerator:
27
+ headers = {
28
+ "authority": "api.caipacity.com",
29
+ "accept": "*/*",
30
+ "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",
31
+ "authorization": "Bearer free",
32
+ "client-id": str(uuid.uuid4()),
33
+ "client-v": "0.1.278",
34
+ "content-type": "application/json",
35
+ "origin": "https://ai.ls",
36
+ "referer": "https://ai.ls/",
37
+ "sec-ch-ua": '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
38
+ "sec-ch-ua-mobile": "?0",
39
+ "sec-ch-ua-platform": '"Windows"',
40
+ "sec-fetch-dest": "empty",
41
+ "sec-fetch-mode": "cors",
42
+ "sec-fetch-site": "cross-site",
43
+ "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",
44
+ "from-url": "https://ai.ls/?chat=1"
45
+ }
46
+ async with ClientSession(
47
+ headers=headers
48
+ ) as session:
49
+ timestamp = _format_timestamp(int(time.time() * 1000))
50
+ json_data = {
51
+ "model": "gpt-3.5-turbo",
52
+ "temperature": kwargs.get("temperature", 0.6),
53
+ "stream": True,
54
+ "messages": messages,
55
+ "d": datetime.now().strftime("%Y-%m-%d"),
56
+ "t": timestamp,
57
+ "s": _hash({"t": timestamp, "m": messages[-1]["content"]}),
58
+ }
59
+ async with session.post(
60
+ "https://api.caipacity.com/v1/chat/completions",
61
+ proxy=proxy,
62
+ json=json_data
63
+ ) as response:
64
+ response.raise_for_status()
65
+ start = "data: "
66
+ async for line in response.content:
67
+ line = line.decode('utf-8')
68
+ if line.startswith(start) and line != "data: [DONE]":
69
+ line = line[len(start):-1]
70
+ line = json.loads(line)
71
+ token = line["choices"][0]["delta"].get("content")
72
+ if token:
73
+ if "ai.ls" in token or "ai.ci" in token:
74
+ raise Exception("Response Error: " + token)
75
+ yield token
76
+
77
+
78
+ @classmethod
79
+ @property
80
+ def params(cls):
81
+ params = [
82
+ ("model", "str"),
83
+ ("messages", "list[dict[str, str]]"),
84
+ ("stream", "bool"),
85
+ ("temperature", "float"),
86
+ ]
87
+ param = ", ".join([": ".join(p) for p in params])
88
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
89
+
90
+
91
+ def _hash(json_data: dict[str, str]) -> SHA256:
92
+ base_string: str = "%s:%s:%s:%s" % (
93
+ json_data["t"],
94
+ json_data["m"],
95
+ "WI,2rU#_r:r~aF4aJ36[.Z(/8Rv93Rf",
96
+ len(json_data["m"]),
97
+ )
98
+
99
+ return SHA256(hashlib.sha256(base_string.encode()).hexdigest())
100
+
101
+
102
+ def _format_timestamp(timestamp: int) -> str:
103
+ e = timestamp
104
+ n = e % 10
105
+ r = n + 1 if n % 2 == 0 else n
106
+ return str(e - n + r)
g4f/Provider/Bard.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import random
5
+ import re
6
+
7
+ from aiohttp import ClientSession
8
+
9
+ from .base_provider import AsyncProvider, format_prompt, get_cookies
10
+
11
+
12
+ class Bard(AsyncProvider):
13
+ url = "https://bard.google.com"
14
+ needs_auth = True
15
+ working = True
16
+
17
+ @classmethod
18
+ async def create_async(
19
+ cls,
20
+ model: str,
21
+ messages: list[dict[str, str]],
22
+ proxy: str = None,
23
+ cookies: dict = None,
24
+ **kwargs
25
+ ) -> str:
26
+ prompt = format_prompt(messages)
27
+ if proxy and "://" not in proxy:
28
+ proxy = f"http://{proxy}"
29
+ if not cookies:
30
+ cookies = get_cookies(".google.com")
31
+
32
+ headers = {
33
+ 'authority': 'bard.google.com',
34
+ 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
35
+ 'origin': 'https://bard.google.com',
36
+ 'referer': 'https://bard.google.com/',
37
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
38
+ 'x-same-domain': '1',
39
+ }
40
+
41
+ async with ClientSession(
42
+ cookies=cookies,
43
+ headers=headers
44
+ ) as session:
45
+ async with session.get(cls.url, proxy=proxy) as response:
46
+ text = await response.text()
47
+
48
+ match = re.search(r'SNlM0e\":\"(.*?)\"', text)
49
+ if not match:
50
+ raise RuntimeError("No snlm0e value.")
51
+ snlm0e = match.group(1)
52
+
53
+ params = {
54
+ 'bl': 'boq_assistant-bard-web-server_20230326.21_p0',
55
+ '_reqid': random.randint(1111, 9999),
56
+ 'rt': 'c'
57
+ }
58
+
59
+ data = {
60
+ 'at': snlm0e,
61
+ 'f.req': json.dumps([None, json.dumps([[prompt]])])
62
+ }
63
+
64
+ intents = '.'.join([
65
+ 'assistant',
66
+ 'lamda',
67
+ 'BardFrontendService'
68
+ ])
69
+
70
+ async with session.post(
71
+ f'{cls.url}/_/BardChatUi/data/{intents}/StreamGenerate',
72
+ data=data,
73
+ params=params,
74
+ proxy=proxy
75
+ ) as response:
76
+ response = await response.text()
77
+ response = json.loads(response.splitlines()[3])[0][2]
78
+ response = json.loads(response)[4][0][1][0]
79
+ return response
80
+
81
+ @classmethod
82
+ @property
83
+ def params(cls):
84
+ params = [
85
+ ("model", "str"),
86
+ ("messages", "list[dict[str, str]]"),
87
+ ("stream", "bool"),
88
+ ("proxy", "str"),
89
+ ]
90
+ param = ", ".join([": ".join(p) for p in params])
91
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/Bing.py ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import random
4
+ import json
5
+ import os
6
+ from aiohttp import ClientSession, ClientTimeout
7
+ from ..typing import AsyncGenerator
8
+ from .base_provider import AsyncGeneratorProvider, get_cookies
9
+
10
+
11
+ class Bing(AsyncGeneratorProvider):
12
+ url = "https://bing.com/chat"
13
+ working = True
14
+ supports_gpt_4 = True
15
+
16
+ @staticmethod
17
+ def create_async_generator(
18
+ model: str,
19
+ messages: list[dict[str, str]],
20
+ cookies: dict = None, **kwargs) -> AsyncGenerator:
21
+
22
+ if not cookies:
23
+ cookies = get_cookies(".bing.com")
24
+ if len(messages) < 2:
25
+ prompt = messages[0]["content"]
26
+ context = None
27
+ else:
28
+ prompt = messages[-1]["content"]
29
+ context = create_context(messages[:-1])
30
+
31
+ if not cookies or "SRCHD" not in cookies:
32
+ cookies = {
33
+ 'SRCHD' : 'AF=NOFORM',
34
+ 'PPLState' : '1',
35
+ 'KievRPSSecAuth': '',
36
+ 'SUID' : '',
37
+ 'SRCHUSR' : '',
38
+ 'SRCHHPGUSR' : '',
39
+ }
40
+ return stream_generate(prompt, context, cookies)
41
+
42
+ def create_context(messages: list[dict[str, str]]):
43
+ context = "".join(f"[{message['role']}](#message)\n{message['content']}\n\n" for message in messages)
44
+
45
+ return context
46
+
47
+ class Conversation():
48
+ def __init__(self, conversationId: str, clientId: str, conversationSignature: str) -> None:
49
+ self.conversationId = conversationId
50
+ self.clientId = clientId
51
+ self.conversationSignature = conversationSignature
52
+
53
+ async def create_conversation(session: ClientSession) -> Conversation:
54
+ url = 'https://www.bing.com/turing/conversation/create'
55
+ async with await session.get(url) as response:
56
+ response = await response.json()
57
+ conversationId = response.get('conversationId')
58
+ clientId = response.get('clientId')
59
+ conversationSignature = response.get('conversationSignature')
60
+
61
+ if not conversationId or not clientId or not conversationSignature:
62
+ raise Exception('Failed to create conversation.')
63
+
64
+ return Conversation(conversationId, clientId, conversationSignature)
65
+
66
+ async def list_conversations(session: ClientSession) -> list:
67
+ url = "https://www.bing.com/turing/conversation/chats"
68
+ async with session.get(url) as response:
69
+ response = await response.json()
70
+ return response["chats"]
71
+
72
+ async def delete_conversation(session: ClientSession, conversation: Conversation) -> list:
73
+ url = "https://sydney.bing.com/sydney/DeleteSingleConversation"
74
+ json = {
75
+ "conversationId": conversation.conversationId,
76
+ "conversationSignature": conversation.conversationSignature,
77
+ "participant": {"id": conversation.clientId},
78
+ "source": "cib",
79
+ "optionsSets": ["autosave"]
80
+ }
81
+ async with session.post(url, json=json) as response:
82
+ response = await response.json()
83
+ return response["result"]["value"] == "Success"
84
+
85
+ class Defaults:
86
+ delimiter = "\x1e"
87
+ ip_address = f"13.{random.randint(104, 107)}.{random.randint(0, 255)}.{random.randint(0, 255)}"
88
+
89
+ allowedMessageTypes = [
90
+ "Chat",
91
+ "Disengaged",
92
+ "AdsQuery",
93
+ "SemanticSerp",
94
+ "GenerateContentQuery",
95
+ "SearchQuery",
96
+ "ActionRequest",
97
+ "Context",
98
+ "Progress",
99
+ "AdsQuery",
100
+ "SemanticSerp",
101
+ ]
102
+
103
+ sliceIds = [
104
+ "winmuid3tf",
105
+ "osbsdusgreccf",
106
+ "ttstmout",
107
+ "crchatrev",
108
+ "winlongmsgtf",
109
+ "ctrlworkpay",
110
+ "norespwtf",
111
+ "tempcacheread",
112
+ "temptacache",
113
+ "505scss0",
114
+ "508jbcars0",
115
+ "515enbotdets0",
116
+ "5082tsports",
117
+ "515vaoprvs",
118
+ "424dagslnv1s0",
119
+ "kcimgattcf",
120
+ "427startpms0",
121
+ ]
122
+
123
+ location = {
124
+ "locale": "en-US",
125
+ "market": "en-US",
126
+ "region": "US",
127
+ "locationHints": [
128
+ {
129
+ "country": "United States",
130
+ "state": "California",
131
+ "city": "Los Angeles",
132
+ "timezoneoffset": 8,
133
+ "countryConfidence": 8,
134
+ "Center": {"Latitude": 34.0536909, "Longitude": -118.242766},
135
+ "RegionType": 2,
136
+ "SourceType": 1,
137
+ }
138
+ ],
139
+ }
140
+
141
+ headers = {
142
+ 'accept': '*/*',
143
+ 'accept-language': 'en-US,en;q=0.9',
144
+ 'cache-control': 'max-age=0',
145
+ 'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"',
146
+ 'sec-ch-ua-arch': '"x86"',
147
+ 'sec-ch-ua-bitness': '"64"',
148
+ 'sec-ch-ua-full-version': '"110.0.1587.69"',
149
+ 'sec-ch-ua-full-version-list': '"Chromium";v="110.0.5481.192", "Not A(Brand";v="24.0.0.0", "Microsoft Edge";v="110.0.1587.69"',
150
+ 'sec-ch-ua-mobile': '?0',
151
+ 'sec-ch-ua-model': '""',
152
+ 'sec-ch-ua-platform': '"Windows"',
153
+ 'sec-ch-ua-platform-version': '"15.0.0"',
154
+ 'sec-fetch-dest': 'document',
155
+ 'sec-fetch-mode': 'navigate',
156
+ 'sec-fetch-site': 'none',
157
+ 'sec-fetch-user': '?1',
158
+ 'upgrade-insecure-requests': '1',
159
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.69',
160
+ 'x-edge-shopping-flag': '1',
161
+ 'x-forwarded-for': ip_address,
162
+ }
163
+
164
+ optionsSets = {
165
+ "optionsSets": [
166
+ 'saharasugg',
167
+ 'enablenewsfc',
168
+ 'clgalileo',
169
+ 'gencontentv3',
170
+ "nlu_direct_response_filter",
171
+ "deepleo",
172
+ "disable_emoji_spoken_text",
173
+ "responsible_ai_policy_235",
174
+ "enablemm",
175
+ "h3precise"
176
+ "dtappid",
177
+ "cricinfo",
178
+ "cricinfov2",
179
+ "dv3sugg",
180
+ "nojbfedge"
181
+ ]
182
+ }
183
+
184
+ def format_message(msg: dict) -> str:
185
+ return json.dumps(msg, ensure_ascii=False) + Defaults.delimiter
186
+
187
+ def create_message(conversation: Conversation, prompt: str, context: str=None) -> str:
188
+ struct = {
189
+ 'arguments': [
190
+ {
191
+ **Defaults.optionsSets,
192
+ 'source': 'cib',
193
+ 'allowedMessageTypes': Defaults.allowedMessageTypes,
194
+ 'sliceIds': Defaults.sliceIds,
195
+ 'traceId': os.urandom(16).hex(),
196
+ 'isStartOfSession': True,
197
+ 'message': Defaults.location | {
198
+ 'author': 'user',
199
+ 'inputMethod': 'Keyboard',
200
+ 'text': prompt,
201
+ 'messageType': 'Chat'
202
+ },
203
+ 'conversationSignature': conversation.conversationSignature,
204
+ 'participant': {
205
+ 'id': conversation.clientId
206
+ },
207
+ 'conversationId': conversation.conversationId
208
+ }
209
+ ],
210
+ 'invocationId': '0',
211
+ 'target': 'chat',
212
+ 'type': 4
213
+ }
214
+
215
+ if context:
216
+ struct['arguments'][0]['previousMessages'] = [{
217
+ "author": "user",
218
+ "description": context,
219
+ "contextType": "WebPage",
220
+ "messageType": "Context",
221
+ "messageId": "discover-web--page-ping-mriduna-----"
222
+ }]
223
+ return format_message(struct)
224
+
225
+ async def stream_generate(
226
+ prompt: str,
227
+ context: str=None,
228
+ cookies: dict=None
229
+ ):
230
+ async with ClientSession(
231
+ timeout=ClientTimeout(total=900),
232
+ cookies=cookies,
233
+ headers=Defaults.headers,
234
+ ) as session:
235
+ conversation = await create_conversation(session)
236
+ try:
237
+ async with session.ws_connect(
238
+ 'wss://sydney.bing.com/sydney/ChatHub',
239
+ autoping=False,
240
+ ) as wss:
241
+
242
+ await wss.send_str(format_message({'protocol': 'json', 'version': 1}))
243
+ msg = await wss.receive(timeout=900)
244
+
245
+ await wss.send_str(create_message(conversation, prompt, context))
246
+
247
+ response_txt = ''
248
+ result_text = ''
249
+ returned_text = ''
250
+ final = False
251
+
252
+ while not final:
253
+ msg = await wss.receive(timeout=900)
254
+ objects = msg.data.split(Defaults.delimiter)
255
+ for obj in objects:
256
+ if obj is None or not obj:
257
+ continue
258
+
259
+ response = json.loads(obj)
260
+ if response.get('type') == 1 and response['arguments'][0].get('messages'):
261
+ message = response['arguments'][0]['messages'][0]
262
+ if (message['contentOrigin'] != 'Apology'):
263
+ response_txt = result_text + \
264
+ message['adaptiveCards'][0]['body'][0].get('text', '')
265
+
266
+ if message.get('messageType'):
267
+ inline_txt = message['adaptiveCards'][0]['body'][0]['inlines'][0].get('text')
268
+ response_txt += inline_txt + '\n'
269
+ result_text += inline_txt + '\n'
270
+
271
+ if response_txt.startswith(returned_text):
272
+ new = response_txt[len(returned_text):]
273
+ if new != "\n":
274
+ yield new
275
+ returned_text = response_txt
276
+ elif response.get('type') == 2:
277
+ result = response['item']['result']
278
+ if result.get('error'):
279
+ raise Exception(f"{result['value']}: {result['message']}")
280
+ final = True
281
+ break
282
+ finally:
283
+ await delete_conversation(session, conversation)
g4f/Provider/ChatgptAi.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ import html
5
+ import json
6
+ from aiohttp import ClientSession
7
+
8
+ from ..typing import AsyncGenerator
9
+ from .base_provider import AsyncGeneratorProvider
10
+
11
+
12
+ class ChatgptAi(AsyncGeneratorProvider):
13
+ url: str = "https://chatgpt.ai/"
14
+ working = True
15
+ supports_gpt_35_turbo = True
16
+ _system_data = None
17
+
18
+ @classmethod
19
+ async def create_async_generator(
20
+ cls,
21
+ model: str,
22
+ messages: list[dict[str, str]],
23
+ proxy: str = None,
24
+ **kwargs
25
+ ) -> AsyncGenerator:
26
+ headers = {
27
+ "authority" : "chatgpt.ai",
28
+ "accept" : "*/*",
29
+ "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",
30
+ "cache-control" : "no-cache",
31
+ "origin" : "https://chatgpt.ai",
32
+ "pragma" : "no-cache",
33
+ "referer" : cls.url,
34
+ "sec-ch-ua" : '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
35
+ "sec-ch-ua-mobile" : "?0",
36
+ "sec-ch-ua-platform" : '"Windows"',
37
+ "sec-fetch-dest" : "empty",
38
+ "sec-fetch-mode" : "cors",
39
+ "sec-fetch-site" : "same-origin",
40
+ "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",
41
+ }
42
+ async with ClientSession(
43
+ headers=headers
44
+ ) as session:
45
+ if not cls._system_data:
46
+ async with session.get(cls.url, proxy=proxy) as response:
47
+ response.raise_for_status()
48
+ match = re.findall(r"data-system='([^']+)'", await response.text())
49
+ if not match:
50
+ raise RuntimeError("No system data")
51
+ cls._system_data = json.loads(html.unescape(match[0]))
52
+
53
+ data = {
54
+ "botId": cls._system_data["botId"],
55
+ "clientId": "",
56
+ "contextId": cls._system_data["contextId"],
57
+ "id": cls._system_data["id"],
58
+ "messages": messages[:-1],
59
+ "newMessage": messages[-1]["content"],
60
+ "session": cls._system_data["sessionId"],
61
+ "stream": True
62
+ }
63
+ async with session.post(
64
+ "https://chatgpt.ai/wp-json/mwai-ui/v1/chats/submit",
65
+ proxy=proxy,
66
+ json=data
67
+ ) as response:
68
+ response.raise_for_status()
69
+ start = "data: "
70
+ async for line in response.content:
71
+ line = line.decode('utf-8')
72
+ if line.startswith(start):
73
+ line = json.loads(line[len(start):-1])
74
+ if line["type"] == "live":
75
+ yield line["data"]
g4f/Provider/ChatgptLogin.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import os, re
4
+ from aiohttp import ClientSession
5
+
6
+ from .base_provider import AsyncProvider, format_prompt
7
+
8
+
9
+ class ChatgptLogin(AsyncProvider):
10
+ url = "https://opchatgpts.net"
11
+ supports_gpt_35_turbo = True
12
+ working = True
13
+ _nonce = None
14
+
15
+ @classmethod
16
+ async def create_async(
17
+ cls,
18
+ model: str,
19
+ messages: list[dict[str, str]],
20
+ **kwargs
21
+ ) -> str:
22
+ headers = {
23
+ "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
24
+ "Accept" : "*/*",
25
+ "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",
26
+ "Origin" : "https://opchatgpts.net",
27
+ "Alt-Used" : "opchatgpts.net",
28
+ "Referer" : "https://opchatgpts.net/chatgpt-free-use/",
29
+ "Sec-Fetch-Dest" : "empty",
30
+ "Sec-Fetch-Mode" : "cors",
31
+ "Sec-Fetch-Site" : "same-origin",
32
+ }
33
+ async with ClientSession(
34
+ headers=headers
35
+ ) as session:
36
+ if not cls._nonce:
37
+ async with session.get(
38
+ "https://opchatgpts.net/chatgpt-free-use/",
39
+ params={"id": os.urandom(6).hex()},
40
+ ) as response:
41
+ result = re.search(r'data-nonce="(.*?)"', await response.text())
42
+ if not result:
43
+ raise RuntimeError("No nonce value")
44
+ cls._nonce = result.group(1)
45
+ data = {
46
+ "_wpnonce": cls._nonce,
47
+ "post_id": 28,
48
+ "url": "https://opchatgpts.net/chatgpt-free-use",
49
+ "action": "wpaicg_chat_shortcode_message",
50
+ "message": format_prompt(messages),
51
+ "bot_id": 0
52
+ }
53
+ async with session.post("https://opchatgpts.net/wp-admin/admin-ajax.php", data=data) as response:
54
+ response.raise_for_status()
55
+ return (await response.json())["data"]
56
+
57
+ @classmethod
58
+ @property
59
+ def params(cls):
60
+ params = [
61
+ ("model", "str"),
62
+ ("messages", "list[dict[str, str]]"),
63
+ ("stream", "bool"),
64
+ ("temperature", "float"),
65
+ ]
66
+ param = ", ".join([": ".join(p) for p in params])
67
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/DeepAi.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import js2py
5
+ from aiohttp import ClientSession
6
+
7
+ from ..typing import AsyncGenerator
8
+ from .base_provider import AsyncGeneratorProvider
9
+
10
+
11
+ class DeepAi(AsyncGeneratorProvider):
12
+ url: str = "https://deepai.org"
13
+ working = True
14
+ supports_gpt_35_turbo = True
15
+
16
+ @staticmethod
17
+ async def create_async_generator(
18
+ model: str,
19
+ messages: list[dict[str, str]],
20
+ proxy: str = None,
21
+ **kwargs
22
+ ) -> AsyncGenerator:
23
+
24
+ token_js = """
25
+ 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'
26
+ 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;
27
+ h = Math.round(1E11 * Math.random()) + "";
28
+ f = function () {
29
+ for (var p = [], q = 0; 64 > q;) p[q] = 0 | 4294967296 * Math.sin(++q % Math.PI);
30
+
31
+ return function (t) {
32
+ var v, y, H, ea = [v = 1732584193, y = 4023233417, ~v, ~y],
33
+ Z = [],
34
+ A = unescape(encodeURI(t)) + "\u0080",
35
+ z = A.length;
36
+ t = --z / 4 + 2 | 15;
37
+ for (Z[--t] = 8 * z; ~z;) Z[z >> 2] |= A.charCodeAt(z) << 8 * z--;
38
+ for (q = A = 0; q < t; q += 16) {
39
+ 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];
40
+ for (A = 4; A;) ea[--A] += z[A]
41
+ }
42
+ for (t = ""; 32 > A;) t += (ea[A >> 3] >> 4 * (1 ^ A++) & 15).toString(16);
43
+ return t.split("").reverse().join("")
44
+ }
45
+ }();
46
+
47
+ "tryit-" + h + "-" + f(agent + f(agent + f(agent + h + "x")));
48
+ """
49
+
50
+ payload = {"chas_style": "chat", "chatHistory": json.dumps(messages)}
51
+ api_key = js2py.eval_js(token_js)
52
+ headers = {
53
+ "api-key": api_key,
54
+ "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
+ async with ClientSession(
57
+ headers=headers
58
+ ) as session:
59
+ async with session.post("https://api.deepai.org/make_me_a_pizza", proxy=proxy, data=payload) as response:
60
+ response.raise_for_status()
61
+ async for stream in response.content.iter_any():
62
+ if stream:
63
+ yield stream.decode()
g4f/Provider/DfeHub.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import re
5
+ import time
6
+
7
+ import requests
8
+
9
+ from ..typing import Any, CreateResult
10
+ from .base_provider import BaseProvider
11
+
12
+
13
+ class DfeHub(BaseProvider):
14
+ url = "https://chat.dfehub.com/"
15
+ supports_stream = True
16
+ supports_gpt_35_turbo = True
17
+
18
+ @staticmethod
19
+ def create_completion(
20
+ model: str,
21
+ messages: list[dict[str, str]],
22
+ stream: bool, **kwargs: Any) -> CreateResult:
23
+
24
+ headers = {
25
+ "authority" : "chat.dfehub.com",
26
+ "accept" : "*/*",
27
+ "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",
28
+ "content-type" : "application/json",
29
+ "origin" : "https://chat.dfehub.com",
30
+ "referer" : "https://chat.dfehub.com/",
31
+ "sec-ch-ua" : '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
32
+ "sec-ch-ua-mobile" : "?0",
33
+ "sec-ch-ua-platform": '"macOS"',
34
+ "sec-fetch-dest" : "empty",
35
+ "sec-fetch-mode" : "cors",
36
+ "sec-fetch-site" : "same-origin",
37
+ "user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
38
+ "x-requested-with" : "XMLHttpRequest",
39
+ }
40
+
41
+ json_data = {
42
+ "messages" : messages,
43
+ "model" : "gpt-3.5-turbo",
44
+ "temperature" : kwargs.get("temperature", 0.5),
45
+ "presence_penalty" : kwargs.get("presence_penalty", 0),
46
+ "frequency_penalty" : kwargs.get("frequency_penalty", 0),
47
+ "top_p" : kwargs.get("top_p", 1),
48
+ "stream" : True
49
+ }
50
+
51
+ response = requests.post("https://chat.dfehub.com/api/openai/v1/chat/completions",
52
+ headers=headers, json=json_data, timeout=3)
53
+
54
+ for chunk in response.iter_lines():
55
+ if b"detail" in chunk:
56
+ delay = re.findall(r"\d+\.\d+", chunk.decode())
57
+ delay = float(delay[-1])
58
+ time.sleep(delay)
59
+ yield from DfeHub.create_completion(model, messages, stream, **kwargs)
60
+ if b"content" in chunk:
61
+ data = json.loads(chunk.decode().split("data: ")[1])
62
+ yield (data["choices"][0]["delta"]["content"])
63
+
64
+ @classmethod
65
+ @property
66
+ def params(cls):
67
+ params = [
68
+ ("model", "str"),
69
+ ("messages", "list[dict[str, str]]"),
70
+ ("stream", "bool"),
71
+ ("temperature", "float"),
72
+ ("presence_penalty", "int"),
73
+ ("frequency_penalty", "int"),
74
+ ("top_p", "int"),
75
+ ]
76
+ param = ", ".join([": ".join(p) for p in params])
77
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/EasyChat.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import random
5
+
6
+ import requests
7
+
8
+ from ..typing import Any, CreateResult
9
+ from .base_provider import BaseProvider
10
+
11
+
12
+ class EasyChat(BaseProvider):
13
+ url: str = "https://free.easychat.work"
14
+ supports_stream = True
15
+ supports_gpt_35_turbo = True
16
+ working = True
17
+
18
+ @staticmethod
19
+ def create_completion(
20
+ model: str,
21
+ messages: list[dict[str, str]],
22
+ stream: bool, **kwargs: Any) -> CreateResult:
23
+
24
+ active_servers = [
25
+ "https://chat10.fastgpt.me",
26
+ "https://chat9.fastgpt.me",
27
+ "https://chat1.fastgpt.me",
28
+ "https://chat2.fastgpt.me",
29
+ "https://chat3.fastgpt.me",
30
+ "https://chat4.fastgpt.me",
31
+ "https://gxos1h1ddt.fastgpt.me"
32
+ ]
33
+
34
+ server = active_servers[kwargs.get("active_server", random.randint(0, 5))]
35
+ headers = {
36
+ "authority" : f"{server}".replace("https://", ""),
37
+ "accept" : "text/event-stream",
38
+ "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,fa=0.2",
39
+ "content-type" : "application/json",
40
+ "origin" : f"{server}",
41
+ "referer" : f"{server}/",
42
+ "x-requested-with" : "XMLHttpRequest",
43
+ 'plugins' : '0',
44
+ 'sec-ch-ua' : '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
45
+ 'sec-ch-ua-mobile' : '?0',
46
+ 'sec-ch-ua-platform': '"Windows"',
47
+ 'sec-fetch-dest' : 'empty',
48
+ 'sec-fetch-mode' : 'cors',
49
+ 'sec-fetch-site' : 'same-origin',
50
+ 'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
51
+ 'usesearch' : 'false',
52
+ 'x-requested-with' : 'XMLHttpRequest'
53
+ }
54
+
55
+ json_data = {
56
+ "messages" : messages,
57
+ "stream" : stream,
58
+ "model" : model,
59
+ "temperature" : kwargs.get("temperature", 0.5),
60
+ "presence_penalty" : kwargs.get("presence_penalty", 0),
61
+ "frequency_penalty" : kwargs.get("frequency_penalty", 0),
62
+ "top_p" : kwargs.get("top_p", 1)
63
+ }
64
+
65
+ session = requests.Session()
66
+ # init cookies from server
67
+ session.get(f"{server}/")
68
+
69
+ response = session.post(f"{server}/api/openai/v1/chat/completions",
70
+ headers=headers, json=json_data, stream=stream)
71
+
72
+ if response.status_code == 200:
73
+
74
+ if stream == False:
75
+ json_data = response.json()
76
+
77
+ if "choices" in json_data:
78
+ yield json_data["choices"][0]["message"]["content"]
79
+ else:
80
+ raise Exception("No response from server")
81
+
82
+ else:
83
+
84
+ for chunk in response.iter_lines():
85
+
86
+ if b"content" in chunk:
87
+ splitData = chunk.decode().split("data:")
88
+
89
+ if len(splitData) > 1:
90
+ yield json.loads(splitData[1])["choices"][0]["delta"]["content"]
91
+ else:
92
+ continue
93
+ else:
94
+ raise Exception(f"Error {response.status_code} from server : {response.reason}")
95
+
96
+
97
+ @classmethod
98
+ @property
99
+ def params(cls):
100
+ params = [
101
+ ("model", "str"),
102
+ ("messages", "list[dict[str, str]]"),
103
+ ("stream", "bool"),
104
+ ("temperature", "float"),
105
+ ("presence_penalty", "int"),
106
+ ("frequency_penalty", "int"),
107
+ ("top_p", "int"),
108
+ ("active_server", "int"),
109
+ ]
110
+ param = ", ".join([": ".join(p) for p in params])
111
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/Equing.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from abc import ABC, abstractmethod
5
+
6
+ import requests
7
+
8
+ from ..typing import Any, CreateResult
9
+
10
+
11
+ class Equing(ABC):
12
+ url: str = 'https://next.eqing.tech/'
13
+ working = True
14
+ needs_auth = False
15
+ supports_stream = True
16
+ supports_gpt_35_turbo = True
17
+ supports_gpt_4 = False
18
+
19
+ @staticmethod
20
+ @abstractmethod
21
+ def create_completion(
22
+ model: str,
23
+ messages: list[dict[str, str]],
24
+ stream: bool, **kwargs: Any) -> CreateResult:
25
+
26
+ headers = {
27
+ 'authority' : 'next.eqing.tech',
28
+ 'accept' : 'text/event-stream',
29
+ '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',
30
+ 'cache-control' : 'no-cache',
31
+ 'content-type' : 'application/json',
32
+ 'origin' : 'https://next.eqing.tech',
33
+ 'plugins' : '0',
34
+ 'pragma' : 'no-cache',
35
+ 'referer' : 'https://next.eqing.tech/',
36
+ 'sec-ch-ua' : '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
37
+ 'sec-ch-ua-mobile' : '?0',
38
+ 'sec-ch-ua-platform': '"macOS"',
39
+ 'sec-fetch-dest' : 'empty',
40
+ 'sec-fetch-mode' : 'cors',
41
+ 'sec-fetch-site' : 'same-origin',
42
+ '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',
43
+ 'usesearch' : 'false',
44
+ 'x-requested-with' : 'XMLHttpRequest'
45
+ }
46
+
47
+ json_data = {
48
+ 'messages' : messages,
49
+ 'stream' : stream,
50
+ 'model' : model,
51
+ 'temperature' : kwargs.get('temperature', 0.5),
52
+ 'presence_penalty' : kwargs.get('presence_penalty', 0),
53
+ 'frequency_penalty' : kwargs.get('frequency_penalty', 0),
54
+ 'top_p' : kwargs.get('top_p', 1),
55
+ }
56
+
57
+ response = requests.post('https://next.eqing.tech/api/openai/v1/chat/completions',
58
+ headers=headers, json=json_data, stream=stream)
59
+
60
+ if not stream:
61
+ yield response.json()["choices"][0]["message"]["content"]
62
+ return
63
+
64
+ for line in response.iter_content(chunk_size=1024):
65
+ if line:
66
+ if b'content' in line:
67
+ line_json = json.loads(line.decode('utf-8').split('data: ')[1])
68
+ token = line_json['choices'][0]['delta'].get('content')
69
+ if token:
70
+ yield token
71
+
72
+ @classmethod
73
+ @property
74
+ def params(cls):
75
+ params = [
76
+ ("model", "str"),
77
+ ("messages", "list[dict[str, str]]"),
78
+ ("stream", "bool"),
79
+ ]
80
+ param = ", ".join([": ".join(p) for p in params])
81
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/FastGpt.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import random
5
+ from abc import ABC, abstractmethod
6
+
7
+ import requests
8
+
9
+ from ..typing import Any, CreateResult
10
+
11
+
12
+ class FastGpt(ABC):
13
+ url: str = 'https://chat9.fastgpt.me/'
14
+ working = False
15
+ needs_auth = False
16
+ supports_stream = True
17
+ supports_gpt_35_turbo = True
18
+ supports_gpt_4 = False
19
+
20
+ @staticmethod
21
+ @abstractmethod
22
+ def create_completion(
23
+ model: str,
24
+ messages: list[dict[str, str]],
25
+ stream: bool, **kwargs: Any) -> CreateResult:
26
+
27
+ headers = {
28
+ 'authority' : 'chat9.fastgpt.me',
29
+ 'accept' : 'text/event-stream',
30
+ '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',
31
+ 'cache-control' : 'no-cache',
32
+ 'content-type' : 'application/json',
33
+ 'origin' : 'https://chat9.fastgpt.me',
34
+ 'plugins' : '0',
35
+ 'pragma' : 'no-cache',
36
+ 'referer' : 'https://chat9.fastgpt.me/',
37
+ 'sec-ch-ua' : '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
38
+ 'sec-ch-ua-mobile' : '?0',
39
+ 'sec-ch-ua-platform': '"macOS"',
40
+ 'sec-fetch-dest' : 'empty',
41
+ 'sec-fetch-mode' : 'cors',
42
+ 'sec-fetch-site' : 'same-origin',
43
+ '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',
44
+ 'usesearch' : 'false',
45
+ 'x-requested-with' : 'XMLHttpRequest',
46
+ }
47
+
48
+ json_data = {
49
+ 'messages' : messages,
50
+ 'stream' : stream,
51
+ 'model' : model,
52
+ 'temperature' : kwargs.get('temperature', 0.5),
53
+ 'presence_penalty' : kwargs.get('presence_penalty', 0),
54
+ 'frequency_penalty' : kwargs.get('frequency_penalty', 0),
55
+ 'top_p' : kwargs.get('top_p', 1),
56
+ }
57
+
58
+ subdomain = random.choice([
59
+ 'jdaen979ew',
60
+ 'chat9'
61
+ ])
62
+
63
+ response = requests.post(f'https://{subdomain}.fastgpt.me/api/openai/v1/chat/completions',
64
+ headers=headers, json=json_data, stream=stream)
65
+
66
+ for line in response.iter_lines():
67
+ if line:
68
+ try:
69
+ if b'content' in line:
70
+ line_json = json.loads(line.decode('utf-8').split('data: ')[1])
71
+ token = line_json['choices'][0]['delta'].get('content')
72
+ if token:
73
+ yield token
74
+ except:
75
+ continue
76
+
77
+ @classmethod
78
+ @property
79
+ def params(cls):
80
+ params = [
81
+ ("model", "str"),
82
+ ("messages", "list[dict[str, str]]"),
83
+ ("stream", "bool"),
84
+ ]
85
+ param = ", ".join([": ".join(p) for p in params])
86
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/Forefront.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+
5
+ import requests
6
+
7
+ from ..typing import Any, CreateResult
8
+ from .base_provider import BaseProvider
9
+
10
+
11
+ class Forefront(BaseProvider):
12
+ url = "https://forefront.com"
13
+ supports_stream = True
14
+ supports_gpt_35_turbo = True
15
+
16
+ @staticmethod
17
+ def create_completion(
18
+ model: str,
19
+ messages: list[dict[str, str]],
20
+ stream: bool, **kwargs: Any) -> CreateResult:
21
+
22
+ json_data = {
23
+ "text" : messages[-1]["content"],
24
+ "action" : "noauth",
25
+ "id" : "",
26
+ "parentId" : "",
27
+ "workspaceId" : "",
28
+ "messagePersona": "607e41fe-95be-497e-8e97-010a59b2e2c0",
29
+ "model" : "gpt-4",
30
+ "messages" : messages[:-1] if len(messages) > 1 else [],
31
+ "internetMode" : "auto",
32
+ }
33
+
34
+ response = requests.post("https://streaming.tenant-forefront-default.knative.chi.coreweave.com/free-chat",
35
+ json=json_data, stream=True)
36
+
37
+ response.raise_for_status()
38
+ for token in response.iter_lines():
39
+ if b"delta" in token:
40
+ yield json.loads(token.decode().split("data: ")[1])["delta"]
g4f/Provider/GetGpt.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import os
5
+ import uuid
6
+
7
+ import requests
8
+ from Crypto.Cipher import AES
9
+
10
+ from ..typing import Any, CreateResult
11
+ from .base_provider import BaseProvider
12
+
13
+
14
+ class GetGpt(BaseProvider):
15
+ url = 'https://chat.getgpt.world/'
16
+ supports_stream = True
17
+ working = True
18
+ supports_gpt_35_turbo = True
19
+
20
+ @staticmethod
21
+ def create_completion(
22
+ model: str,
23
+ messages: list[dict[str, str]],
24
+ stream: bool, **kwargs: Any) -> CreateResult:
25
+
26
+ headers = {
27
+ 'Content-Type' : 'application/json',
28
+ 'Referer' : 'https://chat.getgpt.world/',
29
+ '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',
30
+ }
31
+
32
+ data = json.dumps(
33
+ {
34
+ 'messages' : messages,
35
+ 'frequency_penalty' : kwargs.get('frequency_penalty', 0),
36
+ 'max_tokens' : kwargs.get('max_tokens', 4000),
37
+ 'model' : 'gpt-3.5-turbo',
38
+ 'presence_penalty' : kwargs.get('presence_penalty', 0),
39
+ 'temperature' : kwargs.get('temperature', 1),
40
+ 'top_p' : kwargs.get('top_p', 1),
41
+ 'stream' : True,
42
+ 'uuid' : str(uuid.uuid4())
43
+ }
44
+ )
45
+
46
+ res = requests.post('https://chat.getgpt.world/api/chat/stream',
47
+ headers=headers, json={'signature': _encrypt(data)}, stream=True)
48
+
49
+ res.raise_for_status()
50
+ for line in res.iter_lines():
51
+ if b'content' in line:
52
+ line_json = json.loads(line.decode('utf-8').split('data: ')[1])
53
+ yield (line_json['choices'][0]['delta']['content'])
54
+
55
+ @classmethod
56
+ @property
57
+ def params(cls):
58
+ params = [
59
+ ('model', 'str'),
60
+ ('messages', 'list[dict[str, str]]'),
61
+ ('stream', 'bool'),
62
+ ('temperature', 'float'),
63
+ ('presence_penalty', 'int'),
64
+ ('frequency_penalty', 'int'),
65
+ ('top_p', 'int'),
66
+ ('max_tokens', 'int'),
67
+ ]
68
+ param = ', '.join([': '.join(p) for p in params])
69
+ return f'g4f.provider.{cls.__name__} supports: ({param})'
70
+
71
+
72
+ def _encrypt(e: str):
73
+ t = os.urandom(8).hex().encode('utf-8')
74
+ n = os.urandom(8).hex().encode('utf-8')
75
+ r = e.encode('utf-8')
76
+
77
+ cipher = AES.new(t, AES.MODE_CBC, n)
78
+ ciphertext = cipher.encrypt(_pad_data(r))
79
+
80
+ return ciphertext.hex() + t.decode('utf-8') + n.decode('utf-8')
81
+
82
+
83
+ def _pad_data(data: bytes) -> bytes:
84
+ block_size = AES.block_size
85
+ padding_size = block_size - len(data) % block_size
86
+ padding = bytes([padding_size] * padding_size)
87
+
88
+ return data + padding
g4f/Provider/H2o.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import uuid
5
+
6
+ from aiohttp import ClientSession
7
+
8
+ from ..typing import AsyncGenerator
9
+ from .base_provider import AsyncGeneratorProvider, format_prompt
10
+
11
+
12
+ class H2o(AsyncGeneratorProvider):
13
+ url = "https://gpt-gm.h2o.ai"
14
+ working = True
15
+ model = "h2oai/h2ogpt-gm-oasst1-en-2048-falcon-40b-v1"
16
+
17
+ @classmethod
18
+ async def create_async_generator(
19
+ cls,
20
+ model: str,
21
+ messages: list[dict[str, str]],
22
+ proxy: str = None,
23
+ **kwargs
24
+ ) -> AsyncGenerator:
25
+ model = model if model else cls.model
26
+ headers = {"Referer": "https://gpt-gm.h2o.ai/"}
27
+
28
+ async with ClientSession(
29
+ headers=headers
30
+ ) as session:
31
+ data = {
32
+ "ethicsModalAccepted": "true",
33
+ "shareConversationsWithModelAuthors": "true",
34
+ "ethicsModalAcceptedAt": "",
35
+ "activeModel": model,
36
+ "searchEnabled": "true",
37
+ }
38
+ async with session.post(
39
+ "https://gpt-gm.h2o.ai/settings",
40
+ proxy=proxy,
41
+ data=data
42
+ ) as response:
43
+ response.raise_for_status()
44
+
45
+ async with session.post(
46
+ "https://gpt-gm.h2o.ai/conversation",
47
+ proxy=proxy,
48
+ json={"model": model},
49
+ ) as response:
50
+ response.raise_for_status()
51
+ conversationId = (await response.json())["conversationId"]
52
+
53
+ data = {
54
+ "inputs": format_prompt(messages),
55
+ "parameters": {
56
+ "temperature": 0.4,
57
+ "truncate": 2048,
58
+ "max_new_tokens": 1024,
59
+ "do_sample": True,
60
+ "repetition_penalty": 1.2,
61
+ "return_full_text": False,
62
+ **kwargs
63
+ },
64
+ "stream": True,
65
+ "options": {
66
+ "id": str(uuid.uuid4()),
67
+ "response_id": str(uuid.uuid4()),
68
+ "is_retry": False,
69
+ "use_cache": False,
70
+ "web_search_id": "",
71
+ },
72
+ }
73
+ async with session.post(
74
+ f"https://gpt-gm.h2o.ai/conversation/{conversationId}",
75
+ proxy=proxy,
76
+ json=data
77
+ ) as response:
78
+ start = "data:"
79
+ async for line in response.content:
80
+ line = line.decode("utf-8")
81
+ if line and line.startswith(start):
82
+ line = json.loads(line[len(start):-1])
83
+ if not line["token"]["special"]:
84
+ yield line["token"]["text"]
85
+
86
+ @classmethod
87
+ @property
88
+ def params(cls):
89
+ params = [
90
+ ("model", "str"),
91
+ ("messages", "list[dict[str, str]]"),
92
+ ("stream", "bool"),
93
+ ("temperature", "float"),
94
+ ("truncate", "int"),
95
+ ("max_new_tokens", "int"),
96
+ ("do_sample", "bool"),
97
+ ("repetition_penalty", "float"),
98
+ ("return_full_text", "bool"),
99
+ ]
100
+ param = ", ".join([": ".join(p) for p in params])
101
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/HuggingChat.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+
5
+ from aiohttp import ClientSession
6
+
7
+ from ..typing import AsyncGenerator
8
+ from .base_provider import AsyncGeneratorProvider, format_prompt, get_cookies
9
+
10
+
11
+ class HuggingChat(AsyncGeneratorProvider):
12
+ url = "https://huggingface.co/chat/"
13
+ needs_auth = True
14
+ working = True
15
+ model = "OpenAssistant/oasst-sft-6-llama-30b-xor"
16
+
17
+ @classmethod
18
+ async def create_async_generator(
19
+ cls,
20
+ model: str,
21
+ messages: list[dict[str, str]],
22
+ stream: bool = True,
23
+ proxy: str = None,
24
+ cookies: dict = None,
25
+ **kwargs
26
+ ) -> AsyncGenerator:
27
+ model = model if model else cls.model
28
+ if not cookies:
29
+ cookies = get_cookies(".huggingface.co")
30
+ if proxy and "://" not in proxy:
31
+ proxy = f"http://{proxy}"
32
+
33
+ headers = {
34
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
35
+ }
36
+ async with ClientSession(
37
+ cookies=cookies,
38
+ headers=headers
39
+ ) as session:
40
+ async with session.post("https://huggingface.co/chat/conversation", proxy=proxy, json={"model": model}) as response:
41
+ conversation_id = (await response.json())["conversationId"]
42
+
43
+ send = {
44
+ "inputs": format_prompt(messages),
45
+ "parameters": {
46
+ "temperature": 0.2,
47
+ "truncate": 1000,
48
+ "max_new_tokens": 1024,
49
+ "stop": ["</s>"],
50
+ "top_p": 0.95,
51
+ "repetition_penalty": 1.2,
52
+ "top_k": 50,
53
+ "return_full_text": False,
54
+ **kwargs
55
+ },
56
+ "stream": stream,
57
+ "options": {
58
+ "id": "9e9b8bc4-6604-40c6-994e-8eb78fa32e37",
59
+ "response_id": "04ce2602-3bea-45e8-8efc-cef00680376a",
60
+ "is_retry": False,
61
+ "use_cache": False,
62
+ "web_search_id": ""
63
+ }
64
+ }
65
+ async with session.post(f"https://huggingface.co/chat/conversation/{conversation_id}", proxy=proxy, json=send) as response:
66
+ if not stream:
67
+ data = await response.json()
68
+ if "error" in data:
69
+ raise RuntimeError(data["error"])
70
+ elif isinstance(data, list):
71
+ yield data[0]["generated_text"]
72
+ else:
73
+ raise RuntimeError(f"Response: {data}")
74
+ else:
75
+ start = "data:"
76
+ first = True
77
+ async for line in response.content:
78
+ line = line.decode("utf-8")
79
+ if not line:
80
+ continue
81
+ if line.startswith(start):
82
+ line = json.loads(line[len(start):-1])
83
+ if "token" not in line:
84
+ raise RuntimeError(f"Response: {line}")
85
+ if not line["token"]["special"]:
86
+ if first:
87
+ yield line["token"]["text"].lstrip()
88
+ first = False
89
+ else:
90
+ yield line["token"]["text"]
91
+
92
+ async with session.delete(f"https://huggingface.co/chat/conversation/{conversation_id}", proxy=proxy) as response:
93
+ response.raise_for_status()
94
+
95
+
96
+ @classmethod
97
+ @property
98
+ def params(cls):
99
+ params = [
100
+ ("model", "str"),
101
+ ("messages", "list[dict[str, str]]"),
102
+ ("stream", "bool"),
103
+ ("proxy", "str"),
104
+ ]
105
+ param = ", ".join([": ".join(p) for p in params])
106
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/Liaobots.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import uuid
5
+
6
+ from aiohttp import ClientSession
7
+
8
+ from ..typing import AsyncGenerator
9
+ from .base_provider import AsyncGeneratorProvider
10
+
11
+ models = {
12
+ "gpt-4": {
13
+ "id": "gpt-4",
14
+ "name": "GPT-4",
15
+ "maxLength": 24000,
16
+ "tokenLimit": 8000,
17
+ },
18
+ "gpt-3.5-turbo": {
19
+ "id": "gpt-3.5-turbo",
20
+ "name": "GPT-3.5",
21
+ "maxLength": 12000,
22
+ "tokenLimit": 4000,
23
+ },
24
+ "gpt-3.5-turbo-16k": {
25
+ "id": "gpt-3.5-turbo-16k",
26
+ "name": "GPT-3.5-16k",
27
+ "maxLength": 48000,
28
+ "tokenLimit": 16000,
29
+ },
30
+ }
31
+
32
+ class Liaobots(AsyncGeneratorProvider):
33
+ url = "https://liaobots.com"
34
+ working = True
35
+ supports_gpt_35_turbo = True
36
+ supports_gpt_4 = True
37
+ _auth_code = None
38
+
39
+ @classmethod
40
+ async def create_async_generator(
41
+ cls,
42
+ model: str,
43
+ messages: list[dict[str, str]],
44
+ auth: str = None,
45
+ proxy: str = None,
46
+ **kwargs
47
+ ) -> AsyncGenerator:
48
+ model = model if model in models else "gpt-3.5-turbo"
49
+ if proxy and "://" not in proxy:
50
+ proxy = f"http://{proxy}"
51
+ headers = {
52
+ "authority": "liaobots.com",
53
+ "content-type": "application/json",
54
+ "origin": cls.url,
55
+ "referer": cls.url + "/",
56
+ "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
57
+ }
58
+ async with ClientSession(
59
+ headers=headers
60
+ ) as session:
61
+ auth_code = auth if isinstance(auth, str) else cls._auth_code
62
+ if not auth_code:
63
+ async with session.post(cls.url + "/api/user", proxy=proxy, json={"authcode": ""}) as response:
64
+ response.raise_for_status()
65
+ auth_code = cls._auth_code = json.loads(await response.text())["authCode"]
66
+ data = {
67
+ "conversationId": str(uuid.uuid4()),
68
+ "model": models[model],
69
+ "messages": messages,
70
+ "key": "",
71
+ "prompt": "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully.",
72
+ }
73
+ async with session.post(cls.url + "/api/chat", proxy=proxy, json=data, headers={"x-auth-code": auth_code}) as response:
74
+ response.raise_for_status()
75
+ async for stream in response.content.iter_any():
76
+ if stream:
77
+ yield stream.decode()
78
+
79
+
80
+ @classmethod
81
+ @property
82
+ def params(cls):
83
+ params = [
84
+ ("model", "str"),
85
+ ("messages", "list[dict[str, str]]"),
86
+ ("stream", "bool"),
87
+ ("proxy", "str"),
88
+ ("auth", "str"),
89
+ ]
90
+ param = ", ".join([": ".join(p) for p in params])
91
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/Lockchat.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+
5
+ import requests
6
+
7
+ from ..typing import Any, CreateResult
8
+ from .base_provider import BaseProvider
9
+
10
+
11
+ class Lockchat(BaseProvider):
12
+ url: str = "http://supertest.lockchat.app"
13
+ supports_stream = True
14
+ supports_gpt_35_turbo = True
15
+ supports_gpt_4 = True
16
+
17
+ @staticmethod
18
+ def create_completion(
19
+ model: str,
20
+ messages: list[dict[str, str]],
21
+ stream: bool, **kwargs: Any) -> CreateResult:
22
+
23
+ temperature = float(kwargs.get("temperature", 0.7))
24
+ payload = {
25
+ "temperature": temperature,
26
+ "messages" : messages,
27
+ "model" : model,
28
+ "stream" : True,
29
+ }
30
+
31
+ headers = {
32
+ "user-agent": "ChatX/39 CFNetwork/1408.0.4 Darwin/22.5.0",
33
+ }
34
+ response = requests.post("http://supertest.lockchat.app/v1/chat/completions",
35
+ json=payload, headers=headers, stream=True)
36
+
37
+ response.raise_for_status()
38
+ for token in response.iter_lines():
39
+ if b"The model: `gpt-4` does not exist" in token:
40
+ print("error, retrying...")
41
+ Lockchat.create_completion(
42
+ model = model,
43
+ messages = messages,
44
+ stream = stream,
45
+ temperature = temperature,
46
+ **kwargs)
47
+
48
+ if b"content" in token:
49
+ token = json.loads(token.decode("utf-8").split("data: ")[1])
50
+ token = token["choices"][0]["delta"].get("content")
51
+ if token:
52
+ yield (token)
53
+
54
+ @classmethod
55
+ @property
56
+ def params(cls):
57
+ params = [
58
+ ("model", "str"),
59
+ ("messages", "list[dict[str, str]]"),
60
+ ("stream", "bool"),
61
+ ("temperature", "float"),
62
+ ]
63
+ param = ", ".join([": ".join(p) for p in params])
64
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/Opchatgpts.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from .ChatgptLogin import ChatgptLogin
4
+
5
+
6
+ class Opchatgpts(ChatgptLogin):
7
+ url = "https://opchatgpts.net"
8
+ working = True
g4f/Provider/OpenAssistant.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+
5
+ from aiohttp import ClientSession
6
+
7
+ from ..typing import Any, AsyncGenerator
8
+ from .base_provider import AsyncGeneratorProvider, format_prompt, get_cookies
9
+
10
+
11
+ class OpenAssistant(AsyncGeneratorProvider):
12
+ url = "https://open-assistant.io/chat"
13
+ needs_auth = True
14
+ working = True
15
+ model = "OA_SFT_Llama_30B_6"
16
+
17
+ @classmethod
18
+ async def create_async_generator(
19
+ cls,
20
+ model: str,
21
+ messages: list[dict[str, str]],
22
+ proxy: str = None,
23
+ cookies: dict = None,
24
+ **kwargs: Any
25
+ ) -> AsyncGenerator:
26
+ if proxy and "://" not in proxy:
27
+ proxy = f"http://{proxy}"
28
+ if not cookies:
29
+ cookies = get_cookies("open-assistant.io")
30
+
31
+ headers = {
32
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
33
+ }
34
+ async with ClientSession(
35
+ cookies=cookies,
36
+ headers=headers
37
+ ) as session:
38
+ async with session.post("https://open-assistant.io/api/chat", proxy=proxy) as response:
39
+ chat_id = (await response.json())["id"]
40
+
41
+ data = {
42
+ "chat_id": chat_id,
43
+ "content": f"<s>[INST]\n{format_prompt(messages)}\n[/INST]",
44
+ "parent_id": None
45
+ }
46
+ async with session.post("https://open-assistant.io/api/chat/prompter_message", proxy=proxy, json=data) as response:
47
+ parent_id = (await response.json())["id"]
48
+
49
+ data = {
50
+ "chat_id": chat_id,
51
+ "parent_id": parent_id,
52
+ "model_config_name": model if model else cls.model,
53
+ "sampling_parameters":{
54
+ "top_k": 50,
55
+ "top_p": None,
56
+ "typical_p": None,
57
+ "temperature": 0.35,
58
+ "repetition_penalty": 1.1111111111111112,
59
+ "max_new_tokens": 1024,
60
+ **kwargs
61
+ },
62
+ "plugins":[]
63
+ }
64
+ async with session.post("https://open-assistant.io/api/chat/assistant_message", proxy=proxy, json=data) as response:
65
+ data = await response.json()
66
+ if "id" in data:
67
+ message_id = data["id"]
68
+ elif "message" in data:
69
+ raise RuntimeError(data["message"])
70
+ else:
71
+ response.raise_for_status()
72
+
73
+ params = {
74
+ 'chat_id': chat_id,
75
+ 'message_id': message_id,
76
+ }
77
+ async with session.post("https://open-assistant.io/api/chat/events", proxy=proxy, params=params) as response:
78
+ start = "data: "
79
+ async for line in response.content:
80
+ line = line.decode("utf-8")
81
+ if line and line.startswith(start):
82
+ line = json.loads(line[len(start):])
83
+ if line["event_type"] == "token":
84
+ yield line["text"]
85
+
86
+ params = {
87
+ 'chat_id': chat_id,
88
+ }
89
+ async with session.delete("https://open-assistant.io/api/chat", proxy=proxy, params=params) as response:
90
+ response.raise_for_status()
91
+
92
+ @classmethod
93
+ @property
94
+ def params(cls):
95
+ params = [
96
+ ("model", "str"),
97
+ ("messages", "list[dict[str, str]]"),
98
+ ("stream", "bool"),
99
+ ("proxy", "str"),
100
+ ]
101
+ param = ", ".join([": ".join(p) for p in params])
102
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/OpenaiChat.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from curl_cffi.requests import AsyncSession
4
+ import uuid
5
+ import json
6
+
7
+ from .base_provider import AsyncProvider, get_cookies, format_prompt
8
+ from ..typing import AsyncGenerator
9
+
10
+
11
+ class OpenaiChat(AsyncProvider):
12
+ url = "https://chat.openai.com"
13
+ needs_auth = True
14
+ working = True
15
+ supports_gpt_35_turbo = True
16
+ _access_token = None
17
+
18
+ @classmethod
19
+ async def create_async(
20
+ cls,
21
+ model: str,
22
+ messages: list[dict[str, str]],
23
+ proxy: str = None,
24
+ access_token: str = None,
25
+ cookies: dict = None,
26
+ **kwargs: dict
27
+ ) -> AsyncGenerator:
28
+ proxies = None
29
+ if proxy:
30
+ if "://" not in proxy:
31
+ proxy = f"http://{proxy}"
32
+ proxies = {
33
+ "http": proxy,
34
+ "https": proxy
35
+ }
36
+ if not access_token:
37
+ access_token = await cls.get_access_token(cookies)
38
+ headers = {
39
+ "Accept": "text/event-stream",
40
+ "Authorization": f"Bearer {access_token}",
41
+ }
42
+ async with AsyncSession(proxies=proxies, headers=headers, impersonate="chrome107") as session:
43
+ messages = [
44
+ {
45
+ "id": str(uuid.uuid4()),
46
+ "author": {"role": "user"},
47
+ "content": {"content_type": "text", "parts": [format_prompt(messages)]},
48
+ },
49
+ ]
50
+ data = {
51
+ "action": "next",
52
+ "messages": messages,
53
+ "conversation_id": None,
54
+ "parent_message_id": str(uuid.uuid4()),
55
+ "model": "text-davinci-002-render-sha",
56
+ "history_and_training_disabled": True,
57
+ }
58
+ response = await session.post("https://chat.openai.com/backend-api/conversation", json=data)
59
+ response.raise_for_status()
60
+ last_message = None
61
+ for line in response.content.decode().splitlines():
62
+ if line.startswith("data: "):
63
+ line = line[6:]
64
+ if line != "[DONE]":
65
+ line = json.loads(line)
66
+ if "message" in line:
67
+ last_message = line["message"]["content"]["parts"][0]
68
+ return last_message
69
+
70
+
71
+ @classmethod
72
+ async def get_access_token(cls, cookies: dict = None, proxies: dict = None):
73
+ if not cls._access_token:
74
+ cookies = cookies if cookies else get_cookies("chat.openai.com")
75
+ async with AsyncSession(proxies=proxies, cookies=cookies, impersonate="chrome107") as session:
76
+ response = await session.get("https://chat.openai.com/api/auth/session")
77
+ response.raise_for_status()
78
+ cls._access_token = response.json()["accessToken"]
79
+ return cls._access_token
80
+
81
+
82
+ @classmethod
83
+ @property
84
+ def params(cls):
85
+ params = [
86
+ ("model", "str"),
87
+ ("messages", "list[dict[str, str]]"),
88
+ ("stream", "bool"),
89
+ ("proxy", "str"),
90
+ ("access_token", "str"),
91
+ ("cookies", "dict[str, str]")
92
+ ]
93
+ param = ", ".join([": ".join(p) for p in params])
94
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/Raycast.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+
5
+ import requests
6
+
7
+ from ..typing import Any, CreateResult
8
+ from .base_provider import BaseProvider
9
+
10
+
11
+ class Raycast(BaseProvider):
12
+ url = "https://raycast.com"
13
+ supports_gpt_35_turbo = True
14
+ supports_gpt_4 = True
15
+ supports_stream = True
16
+ needs_auth = True
17
+ working = True
18
+
19
+ @staticmethod
20
+ def create_completion(
21
+ model: str,
22
+ messages: list[dict[str, str]],
23
+ stream: bool,
24
+ **kwargs: Any,
25
+ ) -> CreateResult:
26
+ auth = kwargs.get('auth')
27
+ headers = {
28
+ 'Accept': 'application/json',
29
+ 'Accept-Language': 'en-US,en;q=0.9',
30
+ 'Authorization': f'Bearer {auth}',
31
+ 'Content-Type': 'application/json',
32
+ 'User-Agent': 'Raycast/0 CFNetwork/1410.0.3 Darwin/22.6.0',
33
+ }
34
+ parsed_messages = []
35
+ for message in messages:
36
+ parsed_messages.append({
37
+ 'author': message['role'],
38
+ 'content': {'text': message['content']}
39
+ })
40
+ data = {
41
+ "debug": False,
42
+ "locale": "en-CN",
43
+ "messages": parsed_messages,
44
+ "model": model,
45
+ "provider": "openai",
46
+ "source": "ai_chat",
47
+ "system_instruction": "markdown",
48
+ "temperature": 0.5
49
+ }
50
+ response = requests.post("https://backend.raycast.com/api/v1/ai/chat_completions", headers=headers, json=data, stream=True)
51
+ for token in response.iter_lines():
52
+ if b'data: ' not in token:
53
+ continue
54
+ completion_chunk = json.loads(token.decode().replace('data: ', ''))
55
+ token = completion_chunk['text']
56
+ if token != None:
57
+ yield token
58
+
59
+ @classmethod
60
+ @property
61
+ def params(cls):
62
+ params = [
63
+ ("model", "str"),
64
+ ("messages", "list[dict[str, str]]"),
65
+ ("stream", "bool"),
66
+ ("temperature", "float"),
67
+ ("top_p", "int"),
68
+ ("model", "str"),
69
+ ("auth", "str"),
70
+ ]
71
+ param = ", ".join([": ".join(p) for p in params])
72
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/Theb.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import random
5
+
6
+ import requests
7
+
8
+ from ..typing import Any, CreateResult
9
+ from .base_provider import BaseProvider
10
+
11
+
12
+ class Theb(BaseProvider):
13
+ url = "https://theb.ai"
14
+ working = True
15
+ supports_stream = True
16
+ supports_gpt_35_turbo = True
17
+ needs_auth = True
18
+
19
+ @staticmethod
20
+ def create_completion(
21
+ model: str,
22
+ messages: list[dict[str, str]],
23
+ stream: bool, **kwargs: Any) -> CreateResult:
24
+
25
+ conversation = "\n".join(f"{message['role']}: {message['content']}" for message in messages)
26
+ conversation += "\nassistant: "
27
+
28
+ auth = kwargs.get("auth", {
29
+ "bearer_token":"free",
30
+ "org_id":"theb",
31
+ })
32
+
33
+ bearer_token = auth["bearer_token"]
34
+ org_id = auth["org_id"]
35
+
36
+ headers = {
37
+ 'authority' : 'beta.theb.ai',
38
+ 'accept' : 'text/event-stream',
39
+ 'accept-language' : 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
40
+ 'authorization' : 'Bearer '+bearer_token,
41
+ 'content-type' : 'application/json',
42
+ 'origin' : 'https://beta.theb.ai',
43
+ 'referer' : 'https://beta.theb.ai/home',
44
+ 'sec-ch-ua' : '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
45
+ 'sec-ch-ua-mobile' : '?0',
46
+ 'sec-ch-ua-platform': '"Windows"',
47
+ 'sec-fetch-dest' : 'empty',
48
+ 'sec-fetch-mode' : 'cors',
49
+ 'sec-fetch-site' : 'same-origin',
50
+ 'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
51
+ 'x-ai-model' : 'ee8d4f29cb7047f78cbe84313ed6ace8',
52
+ }
53
+
54
+ req_rand = random.randint(100000000, 9999999999)
55
+
56
+ json_data: dict[str, Any] = {
57
+ "text" : conversation,
58
+ "category" : "04f58f64a4aa4191a957b47290fee864",
59
+ "model" : "ee8d4f29cb7047f78cbe84313ed6ace8",
60
+ "model_params": {
61
+ "system_prompt" : "You are ChatGPT, a large language model trained by OpenAI, based on the GPT-3.5 architecture.\nKnowledge cutoff: 2021-09\nCurrent date: {{YYYY-MM-DD}}",
62
+ "temperature" : kwargs.get("temperature", 1),
63
+ "top_p" : kwargs.get("top_p", 1),
64
+ "frequency_penalty" : kwargs.get("frequency_penalty", 0),
65
+ "presence_penalty" : kwargs.get("presence_penalty", 0),
66
+ "long_term_memory" : "auto"
67
+ }
68
+ }
69
+
70
+ response = requests.post(f"https://beta.theb.ai/api/conversation?org_id={org_id}&req_rand={req_rand}",
71
+ headers=headers, json=json_data, stream=True)
72
+
73
+ response.raise_for_status()
74
+ content = ""
75
+ next_content = ""
76
+ for chunk in response.iter_lines():
77
+ if b"content" in chunk:
78
+ next_content = content
79
+ data = json.loads(chunk.decode().split("data: ")[1])
80
+ content = data["content"]
81
+ yield data["content"].replace(next_content, "")
82
+
83
+ @classmethod
84
+ @property
85
+ def params(cls):
86
+ params = [
87
+ ("model", "str"),
88
+ ("messages", "list[dict[str, str]]"),
89
+ ("auth", "list[dict[str, str]]"),
90
+ ("stream", "bool"),
91
+ ("temperature", "float"),
92
+ ("presence_penalty", "int"),
93
+ ("frequency_penalty", "int"),
94
+ ("top_p", "int")
95
+ ]
96
+ param = ", ".join([": ".join(p) for p in params])
97
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/V50.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import uuid
4
+
5
+ import requests
6
+
7
+ from ..typing import Any, CreateResult
8
+ from .base_provider import BaseProvider
9
+
10
+
11
+ class V50(BaseProvider):
12
+ url = 'https://p5.v50.ltd'
13
+ supports_gpt_35_turbo = True
14
+ supports_stream = False
15
+ needs_auth = False
16
+ working = False
17
+
18
+ @staticmethod
19
+ def create_completion(
20
+ model: str,
21
+ messages: list[dict[str, str]],
22
+ stream: bool, **kwargs: Any) -> CreateResult:
23
+
24
+ conversation = "\n".join(f"{message['role']}: {message['content']}" for message in messages)
25
+ conversation += "\nassistant: "
26
+
27
+ payload = {
28
+ "prompt" : conversation,
29
+ "options" : {},
30
+ "systemMessage" : ".",
31
+ "temperature" : kwargs.get("temperature", 0.4),
32
+ "top_p" : kwargs.get("top_p", 0.4),
33
+ "model" : model,
34
+ "user" : str(uuid.uuid4())
35
+ }
36
+
37
+ headers = {
38
+ 'authority' : 'p5.v50.ltd',
39
+ 'accept' : 'application/json, text/plain, */*',
40
+ 'accept-language' : 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
41
+ 'content-type' : 'application/json',
42
+ 'origin' : 'https://p5.v50.ltd',
43
+ 'referer' : 'https://p5.v50.ltd/',
44
+ 'sec-ch-ua-platform': '"Windows"',
45
+ 'sec-fetch-dest' : 'empty',
46
+ 'sec-fetch-mode' : 'cors',
47
+ 'sec-fetch-site' : 'same-origin',
48
+ 'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
49
+ }
50
+ response = requests.post("https://p5.v50.ltd/api/chat-process",
51
+ json=payload, headers=headers, proxies=kwargs['proxy'] if 'proxy' in kwargs else {})
52
+
53
+ if "https://fk1.v50.ltd" not in response.text:
54
+ yield response.text
55
+
56
+ @classmethod
57
+ @property
58
+ def params(cls):
59
+ params = [
60
+ ("model", "str"),
61
+ ("messages", "list[dict[str, str]]"),
62
+ ("stream", "bool"),
63
+ ("temperature", "float"),
64
+ ("top_p", "int"),
65
+ ]
66
+ param = ", ".join([": ".join(p) for p in params])
67
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/Vercel.py ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import base64, json, uuid, random
4
+ from curl_cffi.requests import AsyncSession
5
+
6
+ from ..typing import Any, TypedDict
7
+ from .base_provider import AsyncProvider
8
+
9
+
10
+ class Vercel(AsyncProvider):
11
+ url = "https://sdk.vercel.ai"
12
+ working = True
13
+ supports_gpt_35_turbo = True
14
+ model = "replicate:replicate/llama-2-70b-chat"
15
+
16
+ @classmethod
17
+ async def create_async(
18
+ cls,
19
+ model: str,
20
+ messages: list[dict[str, str]],
21
+ proxy: str = None,
22
+ **kwargs
23
+ ) -> str:
24
+ if model in ["gpt-3.5-turbo", "gpt-4"]:
25
+ model = "openai:" + model
26
+ model = model if model else cls.model
27
+ proxies = None
28
+ if proxy:
29
+ if "://" not in proxy:
30
+ proxy = "http://" + proxy
31
+ proxies = {"http": proxy, "https": proxy}
32
+ headers = {
33
+ "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.{rand1}.{rand2} Safari/537.36".format(
34
+ rand1=random.randint(0,9999),
35
+ rand2=random.randint(0,9999)
36
+ ),
37
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
38
+ "Accept-Encoding": "gzip, deflate, br",
39
+ "Accept-Language": "en-US,en;q=0.5",
40
+ "TE": "trailers",
41
+ }
42
+ async with AsyncSession(headers=headers, proxies=proxies, impersonate="chrome107") as session:
43
+ response = await session.get(cls.url + "/openai.jpeg")
44
+ response.raise_for_status()
45
+ custom_encoding = _get_custom_encoding(response.text)
46
+ headers = {
47
+ "Content-Type": "application/json",
48
+ "Custom-Encoding": custom_encoding,
49
+ }
50
+ data = _create_payload(model, messages)
51
+ response = await session.post(cls.url + "/api/generate", json=data, headers=headers)
52
+ response.raise_for_status()
53
+ return response.text
54
+
55
+
56
+ def _create_payload(model: str, messages: list[dict[str, str]]) -> dict[str, Any]:
57
+ if model not in model_info:
58
+ raise RuntimeError(f'Model "{model}" are not supported')
59
+ default_params = model_info[model]["default_params"]
60
+ return {
61
+ "messages": messages,
62
+ "playgroundId": str(uuid.uuid4()),
63
+ "chatIndex": 0,
64
+ "model": model
65
+ } | default_params
66
+
67
+ # based on https://github.com/ading2210/vercel-llm-api
68
+ def _get_custom_encoding(text: str) -> str:
69
+ data = json.loads(base64.b64decode(text, validate=True))
70
+ script = """
71
+ String.prototype.fontcolor = function() {{
72
+ return `<font>${{this}}</font>`
73
+ }}
74
+ var globalThis = {{marker: "mark"}};
75
+ ({script})({key})
76
+ """.format(
77
+ script=data["c"], key=data["a"]
78
+ )
79
+ context = quickjs.Context() # type: ignore
80
+ token_data = json.loads(context.eval(script).json()) # type: ignore
81
+ token_data[2] = "mark"
82
+ token = {"r": token_data, "t": data["t"]}
83
+ token_str = json.dumps(token, separators=(",", ":")).encode("utf-16le")
84
+ return base64.b64encode(token_str).decode()
85
+
86
+
87
+ class ModelInfo(TypedDict):
88
+ id: str
89
+ default_params: dict[str, Any]
90
+
91
+
92
+ model_info: dict[str, ModelInfo] = {
93
+ "anthropic:claude-instant-v1": {
94
+ "id": "anthropic:claude-instant-v1",
95
+ "default_params": {
96
+ "temperature": 1,
97
+ "maxTokens": 200,
98
+ "topP": 1,
99
+ "topK": 1,
100
+ "presencePenalty": 1,
101
+ "frequencyPenalty": 1,
102
+ "stopSequences": ["\n\nHuman:"],
103
+ },
104
+ },
105
+ "anthropic:claude-v1": {
106
+ "id": "anthropic:claude-v1",
107
+ "default_params": {
108
+ "temperature": 1,
109
+ "maxTokens": 200,
110
+ "topP": 1,
111
+ "topK": 1,
112
+ "presencePenalty": 1,
113
+ "frequencyPenalty": 1,
114
+ "stopSequences": ["\n\nHuman:"],
115
+ },
116
+ },
117
+ "anthropic:claude-v2": {
118
+ "id": "anthropic:claude-v2",
119
+ "default_params": {
120
+ "temperature": 1,
121
+ "maxTokens": 200,
122
+ "topP": 1,
123
+ "topK": 1,
124
+ "presencePenalty": 1,
125
+ "frequencyPenalty": 1,
126
+ "stopSequences": ["\n\nHuman:"],
127
+ },
128
+ },
129
+ "replicate:a16z-infra/llama7b-v2-chat": {
130
+ "id": "replicate:a16z-infra/llama7b-v2-chat",
131
+ "default_params": {
132
+ "temperature": 0.75,
133
+ "maxTokens": 500,
134
+ "topP": 1,
135
+ "repetitionPenalty": 1,
136
+ },
137
+ },
138
+ "replicate:a16z-infra/llama13b-v2-chat": {
139
+ "id": "replicate:a16z-infra/llama13b-v2-chat",
140
+ "default_params": {
141
+ "temperature": 0.75,
142
+ "maxTokens": 500,
143
+ "topP": 1,
144
+ "repetitionPenalty": 1,
145
+ },
146
+ },
147
+ "replicate:replicate/llama-2-70b-chat": {
148
+ "id": "replicate:replicate/llama-2-70b-chat",
149
+ "default_params": {
150
+ "temperature": 0.75,
151
+ "maxTokens": 1000,
152
+ "topP": 1,
153
+ "repetitionPenalty": 1,
154
+ },
155
+ },
156
+ "huggingface:bigscience/bloom": {
157
+ "id": "huggingface:bigscience/bloom",
158
+ "default_params": {
159
+ "temperature": 0.5,
160
+ "maxTokens": 200,
161
+ "topP": 0.95,
162
+ "topK": 4,
163
+ "repetitionPenalty": 1.03,
164
+ },
165
+ },
166
+ "huggingface:google/flan-t5-xxl": {
167
+ "id": "huggingface:google/flan-t5-xxl",
168
+ "default_params": {
169
+ "temperature": 0.5,
170
+ "maxTokens": 200,
171
+ "topP": 0.95,
172
+ "topK": 4,
173
+ "repetitionPenalty": 1.03,
174
+ },
175
+ },
176
+ "huggingface:EleutherAI/gpt-neox-20b": {
177
+ "id": "huggingface:EleutherAI/gpt-neox-20b",
178
+ "default_params": {
179
+ "temperature": 0.5,
180
+ "maxTokens": 200,
181
+ "topP": 0.95,
182
+ "topK": 4,
183
+ "repetitionPenalty": 1.03,
184
+ "stopSequences": [],
185
+ },
186
+ },
187
+ "huggingface:OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5": {
188
+ "id": "huggingface:OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
189
+ "default_params": {"maxTokens": 200, "typicalP": 0.2, "repetitionPenalty": 1},
190
+ },
191
+ "huggingface:OpenAssistant/oasst-sft-1-pythia-12b": {
192
+ "id": "huggingface:OpenAssistant/oasst-sft-1-pythia-12b",
193
+ "default_params": {"maxTokens": 200, "typicalP": 0.2, "repetitionPenalty": 1},
194
+ },
195
+ "huggingface:bigcode/santacoder": {
196
+ "id": "huggingface:bigcode/santacoder",
197
+ "default_params": {
198
+ "temperature": 0.5,
199
+ "maxTokens": 200,
200
+ "topP": 0.95,
201
+ "topK": 4,
202
+ "repetitionPenalty": 1.03,
203
+ },
204
+ },
205
+ "cohere:command-light-nightly": {
206
+ "id": "cohere:command-light-nightly",
207
+ "default_params": {
208
+ "temperature": 0.9,
209
+ "maxTokens": 200,
210
+ "topP": 1,
211
+ "topK": 0,
212
+ "presencePenalty": 0,
213
+ "frequencyPenalty": 0,
214
+ "stopSequences": [],
215
+ },
216
+ },
217
+ "cohere:command-nightly": {
218
+ "id": "cohere:command-nightly",
219
+ "default_params": {
220
+ "temperature": 0.9,
221
+ "maxTokens": 200,
222
+ "topP": 1,
223
+ "topK": 0,
224
+ "presencePenalty": 0,
225
+ "frequencyPenalty": 0,
226
+ "stopSequences": [],
227
+ },
228
+ },
229
+ "openai:gpt-4": {
230
+ "id": "openai:gpt-4",
231
+ "default_params": {
232
+ "temperature": 0.7,
233
+ "maxTokens": 500,
234
+ "topP": 1,
235
+ "presencePenalty": 0,
236
+ "frequencyPenalty": 0,
237
+ "stopSequences": [],
238
+ },
239
+ },
240
+ "openai:gpt-4-0613": {
241
+ "id": "openai:gpt-4-0613",
242
+ "default_params": {
243
+ "temperature": 0.7,
244
+ "maxTokens": 500,
245
+ "topP": 1,
246
+ "presencePenalty": 0,
247
+ "frequencyPenalty": 0,
248
+ "stopSequences": [],
249
+ },
250
+ },
251
+ "openai:code-davinci-002": {
252
+ "id": "openai:code-davinci-002",
253
+ "default_params": {
254
+ "temperature": 0.5,
255
+ "maxTokens": 200,
256
+ "topP": 1,
257
+ "presencePenalty": 0,
258
+ "frequencyPenalty": 0,
259
+ "stopSequences": [],
260
+ },
261
+ },
262
+ "openai:gpt-3.5-turbo": {
263
+ "id": "openai:gpt-3.5-turbo",
264
+ "default_params": {
265
+ "temperature": 0.7,
266
+ "maxTokens": 500,
267
+ "topP": 1,
268
+ "topK": 1,
269
+ "presencePenalty": 1,
270
+ "frequencyPenalty": 1,
271
+ "stopSequences": [],
272
+ },
273
+ },
274
+ "openai:gpt-3.5-turbo-16k": {
275
+ "id": "openai:gpt-3.5-turbo-16k",
276
+ "default_params": {
277
+ "temperature": 0.7,
278
+ "maxTokens": 500,
279
+ "topP": 1,
280
+ "topK": 1,
281
+ "presencePenalty": 1,
282
+ "frequencyPenalty": 1,
283
+ "stopSequences": [],
284
+ },
285
+ },
286
+ "openai:gpt-3.5-turbo-16k-0613": {
287
+ "id": "openai:gpt-3.5-turbo-16k-0613",
288
+ "default_params": {
289
+ "temperature": 0.7,
290
+ "maxTokens": 500,
291
+ "topP": 1,
292
+ "topK": 1,
293
+ "presencePenalty": 1,
294
+ "frequencyPenalty": 1,
295
+ "stopSequences": [],
296
+ },
297
+ },
298
+ "openai:text-ada-001": {
299
+ "id": "openai:text-ada-001",
300
+ "default_params": {
301
+ "temperature": 0.5,
302
+ "maxTokens": 200,
303
+ "topP": 1,
304
+ "presencePenalty": 0,
305
+ "frequencyPenalty": 0,
306
+ "stopSequences": [],
307
+ },
308
+ },
309
+ "openai:text-babbage-001": {
310
+ "id": "openai:text-babbage-001",
311
+ "default_params": {
312
+ "temperature": 0.5,
313
+ "maxTokens": 200,
314
+ "topP": 1,
315
+ "presencePenalty": 0,
316
+ "frequencyPenalty": 0,
317
+ "stopSequences": [],
318
+ },
319
+ },
320
+ "openai:text-curie-001": {
321
+ "id": "openai:text-curie-001",
322
+ "default_params": {
323
+ "temperature": 0.5,
324
+ "maxTokens": 200,
325
+ "topP": 1,
326
+ "presencePenalty": 0,
327
+ "frequencyPenalty": 0,
328
+ "stopSequences": [],
329
+ },
330
+ },
331
+ "openai:text-davinci-002": {
332
+ "id": "openai:text-davinci-002",
333
+ "default_params": {
334
+ "temperature": 0.5,
335
+ "maxTokens": 200,
336
+ "topP": 1,
337
+ "presencePenalty": 0,
338
+ "frequencyPenalty": 0,
339
+ "stopSequences": [],
340
+ },
341
+ },
342
+ "openai:text-davinci-003": {
343
+ "id": "openai:text-davinci-003",
344
+ "default_params": {
345
+ "temperature": 0.5,
346
+ "maxTokens": 200,
347
+ "topP": 1,
348
+ "presencePenalty": 0,
349
+ "frequencyPenalty": 0,
350
+ "stopSequences": [],
351
+ },
352
+ },
353
+ }
g4f/Provider/Wewordle.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import random, string, time
4
+ from aiohttp import ClientSession
5
+
6
+ from .base_provider import AsyncProvider
7
+
8
+
9
+ class Wewordle(AsyncProvider):
10
+ url = "https://wewordle.org"
11
+ working = True
12
+ supports_gpt_35_turbo = True
13
+
14
+ @classmethod
15
+ async def create_async(
16
+ cls,
17
+ model: str,
18
+ messages: list[dict[str, str]],
19
+ proxy: str = None,
20
+ **kwargs
21
+ ) -> str:
22
+
23
+ headers = {
24
+ "accept" : "*/*",
25
+ "pragma" : "no-cache",
26
+ "Content-Type" : "application/json",
27
+ "Connection" : "keep-alive"
28
+ }
29
+
30
+ _user_id = "".join(random.choices(f"{string.ascii_lowercase}{string.digits}", k=16))
31
+ _app_id = "".join(random.choices(f"{string.ascii_lowercase}{string.digits}", k=31))
32
+ _request_date = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime())
33
+ data = {
34
+ "user" : _user_id,
35
+ "messages" : messages,
36
+ "subscriber": {
37
+ "originalPurchaseDate" : None,
38
+ "originalApplicationVersion" : None,
39
+ "allPurchaseDatesMillis" : {},
40
+ "entitlements" : {"active": {}, "all": {}},
41
+ "allPurchaseDates" : {},
42
+ "allExpirationDatesMillis" : {},
43
+ "allExpirationDates" : {},
44
+ "originalAppUserId" : f"$RCAnonymousID:{_app_id}",
45
+ "latestExpirationDate" : None,
46
+ "requestDate" : _request_date,
47
+ "latestExpirationDateMillis" : None,
48
+ "nonSubscriptionTransactions" : [],
49
+ "originalPurchaseDateMillis" : None,
50
+ "managementURL" : None,
51
+ "allPurchasedProductIdentifiers": [],
52
+ "firstSeen" : _request_date,
53
+ "activeSubscriptions" : [],
54
+ }
55
+ }
56
+
57
+
58
+ async with ClientSession(
59
+ headers=headers
60
+ ) as session:
61
+ async with session.post(f"{cls.url}/gptapi/v1/android/turbo", proxy=proxy, json=data) as response:
62
+ response.raise_for_status()
63
+ content = (await response.json())["message"]["content"]
64
+ if content:
65
+ return content
g4f/Provider/Wuguokai.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import random
4
+
5
+ import requests
6
+
7
+ from ..typing import Any, CreateResult
8
+ from .base_provider import BaseProvider
9
+
10
+
11
+ class Wuguokai(BaseProvider):
12
+ url = 'https://chat.wuguokai.xyz'
13
+ supports_gpt_35_turbo = True
14
+ working = True
15
+
16
+ @staticmethod
17
+ def create_completion(
18
+ model: str,
19
+ messages: list[dict[str, str]],
20
+ stream: bool,
21
+ **kwargs: Any,
22
+ ) -> CreateResult:
23
+ base = ''
24
+ for message in messages:
25
+ base += '%s: %s\n' % (message['role'], message['content'])
26
+ base += 'assistant:'
27
+
28
+ headers = {
29
+ 'authority': 'ai-api.wuguokai.xyz',
30
+ 'accept': 'application/json, text/plain, */*',
31
+ 'accept-language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
32
+ 'content-type': 'application/json',
33
+ 'origin': 'https://chat.wuguokai.xyz',
34
+ 'referer': 'https://chat.wuguokai.xyz/',
35
+ 'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
36
+ 'sec-ch-ua-mobile': '?0',
37
+ 'sec-ch-ua-platform': '"Windows"',
38
+ 'sec-fetch-dest': 'empty',
39
+ 'sec-fetch-mode': 'cors',
40
+ 'sec-fetch-site': 'same-site',
41
+ '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'
42
+ }
43
+ data ={
44
+ "prompt": base,
45
+ "options": {},
46
+ "userId": f"#/chat/{random.randint(1,99999999)}",
47
+ "usingContext": True
48
+ }
49
+ response = requests.post("https://ai-api20.wuguokai.xyz/api/chat-process", headers=headers, timeout=3, json=data, proxies=kwargs['proxy'] if 'proxy' in kwargs else {})
50
+ _split = response.text.split("> 若回答失败请重试或多刷新几次界面后重试")
51
+ if response.status_code == 200:
52
+ if len(_split) > 1:
53
+ yield _split[1].strip()
54
+ else:
55
+ yield _split[0].strip()
56
+ else:
57
+ raise Exception(f"Error: {response.status_code} {response.reason}")
58
+
59
+ @classmethod
60
+ @property
61
+ def params(cls):
62
+ params = [
63
+ ("model", "str"),
64
+ ("messages", "list[dict[str, str]]"),
65
+ ("stream", "bool")
66
+ ]
67
+ param = ", ".join([": ".join(p) for p in params])
68
+ return f"g4f.provider.{cls.__name__} supports: ({param})"
g4f/Provider/You.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+
5
+ from aiohttp import ClientSession
6
+
7
+ from ..typing import AsyncGenerator
8
+ from .base_provider import AsyncGeneratorProvider, format_prompt, get_cookies
9
+
10
+
11
+ class You(AsyncGeneratorProvider):
12
+ url = "https://you.com"
13
+ working = True
14
+ supports_gpt_35_turbo = True
15
+ supports_stream = True
16
+
17
+ @staticmethod
18
+ async def create_async_generator(
19
+ model: str,
20
+ messages: list[dict[str, str]],
21
+ cookies: dict = None,
22
+ **kwargs,
23
+ ) -> AsyncGenerator:
24
+ if not cookies:
25
+ cookies = get_cookies("you.com")
26
+ headers = {
27
+ "Accept": "text/event-stream",
28
+ "Referer": "https://you.com/search?fromSearchBar=true&tbm=youchat",
29
+ "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0"
30
+ }
31
+ async with ClientSession(headers=headers, cookies=cookies) as session:
32
+ async with session.get(
33
+ "https://you.com/api/streamingSearch",
34
+ params={"q": format_prompt(messages), "domain": "youchat", "chat": ""},
35
+ ) as response:
36
+ start = 'data: {"youChatToken": '
37
+ async for line in response.content:
38
+ line = line.decode('utf-8')
39
+ if line.startswith(start):
40
+ yield json.loads(line[len(start): -2])
g4f/Provider/Yqcloud.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from aiohttp import ClientSession
4
+
5
+ from ..typing import AsyncGenerator
6
+ from .base_provider import AsyncGeneratorProvider, format_prompt
7
+
8
+
9
+ class Yqcloud(AsyncGeneratorProvider):
10
+ url = "https://chat9.yqcloud.top/"
11
+ working = True
12
+ supports_gpt_35_turbo = True
13
+
14
+ @staticmethod
15
+ async def create_async_generator(
16
+ model: str,
17
+ messages: list[dict[str, str]],
18
+ proxy: str = None,
19
+ **kwargs,
20
+ ) -> AsyncGenerator:
21
+ async with ClientSession(
22
+ headers=_create_header()
23
+ ) as session:
24
+ payload = _create_payload(messages)
25
+ async with session.post("https://api.aichatos.cloud/api/generateStream", proxy=proxy, json=payload) as response:
26
+ response.raise_for_status()
27
+ async for stream in response.content.iter_any():
28
+ if stream:
29
+ yield stream.decode()
30
+
31
+
32
+ def _create_header():
33
+ return {
34
+ "accept" : "application/json, text/plain, */*",
35
+ "content-type" : "application/json",
36
+ "origin" : "https://chat9.yqcloud.top",
37
+ }
38
+
39
+
40
+ def _create_payload(messages: list[dict[str, str]]):
41
+ return {
42
+ "prompt": format_prompt(messages),
43
+ "network": True,
44
+ "system": "",
45
+ "withoutContext": False,
46
+ "stream": True,
47
+ "userId": "#/chat/1693025544336"
48
+ }
g4f/Provider/__init__.py CHANGED
@@ -1,30 +1,69 @@
1
- from . import Provider
2
- from .Providers import (
3
- Ails,
4
- You,
5
- Bing,
6
- Yqcloud,
7
- Theb,
8
- Aichat,
9
- Bard,
10
- Vercel,
11
- Forefront,
12
- Lockchat,
13
- Liaobots,
14
- H2o,
15
- ChatgptLogin,
16
- DeepAi,
17
- GetGpt,
18
- AItianhu,
19
- EasyChat,
20
- Acytoo,
21
- DfeHub,
22
- AiService,
23
- BingHuan,
24
- Wewordle,
25
- ChatgptAi,
26
- opchatgpts,
27
- Raycast,
28
- )
 
 
 
 
29
 
30
- Palm = Bard
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ from .Acytoo import Acytoo
3
+ from .Aichat import Aichat
4
+ from .Ails import Ails
5
+ from .AiService import AiService
6
+ from .AItianhu import AItianhu
7
+ from .Bard import Bard
8
+ from .Bing import Bing
9
+ from .ChatgptAi import ChatgptAi
10
+ from .ChatgptLogin import ChatgptLogin
11
+ from .DeepAi import DeepAi
12
+ from .DfeHub import DfeHub
13
+ from .EasyChat import EasyChat
14
+ from .Forefront import Forefront
15
+ from .GetGpt import GetGpt
16
+ from .H2o import H2o
17
+ from .HuggingChat import HuggingChat
18
+ from .Liaobots import Liaobots
19
+ from .Lockchat import Lockchat
20
+ from .Opchatgpts import Opchatgpts
21
+ from .OpenaiChat import OpenaiChat
22
+ from .OpenAssistant import OpenAssistant
23
+ from .Raycast import Raycast
24
+ from .Theb import Theb
25
+ from .Vercel import Vercel
26
+ from .Wewordle import Wewordle
27
+ from .You import You
28
+ from .Yqcloud import Yqcloud
29
+ from .Equing import Equing
30
+ from .FastGpt import FastGpt
31
+ from .V50 import V50
32
+ from .Wuguokai import Wuguokai
33
 
34
+ from .base_provider import BaseProvider, AsyncProvider, AsyncGeneratorProvider
35
+
36
+ __all__ = [
37
+ 'BaseProvider',
38
+ 'Acytoo',
39
+ 'Aichat',
40
+ 'Ails',
41
+ 'AiService',
42
+ 'AItianhu',
43
+ 'Bard',
44
+ 'Bing',
45
+ 'ChatgptAi',
46
+ 'ChatgptLogin',
47
+ 'DeepAi',
48
+ 'DfeHub',
49
+ 'EasyChat',
50
+ 'Forefront',
51
+ 'GetGpt',
52
+ 'H2o',
53
+ 'HuggingChat',
54
+ 'Liaobots',
55
+ 'Lockchat',
56
+ 'Opchatgpts',
57
+ 'Raycast',
58
+ 'OpenaiChat',
59
+ 'OpenAssistant',
60
+ 'Theb',
61
+ 'Vercel',
62
+ 'Wewordle',
63
+ 'You',
64
+ 'Yqcloud',
65
+ 'Equing',
66
+ 'FastGpt',
67
+ 'Wuguokai',
68
+ 'V50'
69
+ ]
g4f/Provider/__pycache__/AItianhu.cpython-311.pyc ADDED
Binary file (4.1 kB). View file
 
g4f/Provider/__pycache__/AItianhu.cpython-38.pyc ADDED
Binary file (2.45 kB). View file
 
g4f/Provider/__pycache__/Acytoo.cpython-311.pyc ADDED
Binary file (2.88 kB). View file
 
g4f/Provider/__pycache__/Acytoo.cpython-38.pyc ADDED
Binary file (1.59 kB). View file
 
g4f/Provider/__pycache__/AiService.cpython-311.pyc ADDED
Binary file (2.13 kB). View file
 
g4f/Provider/__pycache__/AiService.cpython-38.pyc ADDED
Binary file (1.51 kB). View file
 
g4f/Provider/__pycache__/Aichat.cpython-311.pyc ADDED
Binary file (3.12 kB). View file
 
g4f/Provider/__pycache__/Aichat.cpython-38.pyc ADDED
Binary file (1.79 kB). View file
 
g4f/Provider/__pycache__/Ails.cpython-311.pyc ADDED
Binary file (6.33 kB). View file
 
g4f/Provider/__pycache__/Ails.cpython-38.pyc ADDED
Binary file (3.57 kB). View file
 
g4f/Provider/__pycache__/Bard.cpython-311.pyc ADDED
Binary file (5.09 kB). View file
 
g4f/Provider/__pycache__/Bard.cpython-38.pyc ADDED
Binary file (2.62 kB). View file
 
g4f/Provider/__pycache__/Bing.cpython-311.pyc ADDED
Binary file (13.7 kB). View file
 
g4f/Provider/__pycache__/Bing.cpython-38.pyc ADDED
Binary file (7.7 kB). View file
 
g4f/Provider/__pycache__/ChatgptAi.cpython-311.pyc ADDED
Binary file (4.63 kB). View file
 
g4f/Provider/__pycache__/ChatgptAi.cpython-38.pyc ADDED
Binary file (2.44 kB). View file
 
g4f/Provider/__pycache__/ChatgptLogin.cpython-311.pyc ADDED
Binary file (4.57 kB). View file
 
g4f/Provider/__pycache__/ChatgptLogin.cpython-38.pyc ADDED
Binary file (2.48 kB). View file