XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

~ | major refractoring + new providers | v0.0.2.0

g4f.Provider.FastGpt & g4f.Provider.Equing gpt-3.5-turbo-0613

882910c1
abc <98614666+xtekky@users.noreply.github.com>
提交于

代码差异

5 个文件 +164 -3
Added g4f/Provider/Equing.py +74 -0
@@ -0,0 +1,74 @@
1 import requests, json
2 from abc import ABC, abstractmethod
3
4 from ..typing import Any, CreateResult
5
6
7 class Equing(ABC):
8 url: str = 'https://next.eqing.tech/'
9 working = True
10 needs_auth = False
11 supports_stream = True
12 supports_gpt_35_turbo = True
13 supports_gpt_4 = False
14
15 @staticmethod
16 @abstractmethod
17 def create_completion(
18 model: str,
19 messages: list[dict[str, str]],
20 stream: bool,
21 **kwargs: Any) -> CreateResult:
22
23 headers = {
24 'authority': 'next.eqing.tech',
25 'accept': 'text/event-stream',
26 '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',
27 'cache-control': 'no-cache',
28 'content-type': 'application/json',
29 'origin': 'https://next.eqing.tech',
30 'plugins': '0',
31 'pragma': 'no-cache',
32 'referer': 'https://next.eqing.tech/',
33 'sec-ch-ua': '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
34 'sec-ch-ua-mobile': '?0',
35 'sec-ch-ua-platform': '"macOS"',
36 'sec-fetch-dest': 'empty',
37 'sec-fetch-mode': 'cors',
38 'sec-fetch-site': 'same-origin',
39 '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',
40 'usesearch': 'false',
41 'x-requested-with': 'XMLHttpRequest',
42 }
43
44 json_data = {
45 'messages': messages,
46 'stream': stream,
47 'model': model,
48 'temperature': kwargs.get('temperature', 0.5),
49 'presence_penalty': kwargs.get('presence_penalty', 0),
50 'frequency_penalty': kwargs.get('frequency_penalty', 0),
51 'top_p': kwargs.get('top_p', 1),
52 }
53
54 response = requests.post('https://next.eqing.tech/api/openai/v1/chat/completions',
55 headers=headers, json=json_data, stream=stream)
56
57 for line in response.iter_content(chunk_size=1024):
58 if line:
59 if b'content' in line:
60 line_json = json.loads(line.decode('utf-8').split('data: ')[1])
61 token = line_json['choices'][0]['delta'].get('content')
62 if token:
63 yield token
64
65 @classmethod
66 @property
67 def params(cls):
68 params = [
69 ("model", "str"),
70 ("messages", "list[dict[str, str]]"),
71 ("stream", "bool"),
72 ]
73 param = ", ".join([": ".join(p) for p in params])
74 return f"g4f.provider.{cls.__name__} supports: ({param})"
Added g4f/Provider/FastGpt.py +83 -0
@@ -0,0 +1,83 @@
1 import requests, json, random
2 from abc import ABC, abstractmethod
3
4 from ..typing import Any, CreateResult
5
6
7 class FastGpt(ABC):
8 url: str = 'https://chat9.fastgpt.me/'
9 working = True
10 needs_auth = False
11 supports_stream = True
12 supports_gpt_35_turbo = True
13 supports_gpt_4 = False
14
15 @staticmethod
16 @abstractmethod
17 def create_completion(
18 model: str,
19 messages: list[dict[str, str]],
20 stream: bool,
21 **kwargs: Any) -> CreateResult:
22
23 headers = {
24 'authority': 'chat9.fastgpt.me',
25 'accept': 'text/event-stream',
26 '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',
27 'cache-control': 'no-cache',
28 'content-type': 'application/json',
29 # 'cookie': 'cf_clearance=idIAwtoSCn0uCzcWLGuD.KtiAJv9a1GsPduEOqIkyHU-1692278595-0-1-cb11fd7a.ab1546d4.ccf35fd7-0.2.1692278595; Hm_lvt_563fb31e93813a8a7094966df6671d3f=1691966491,1692278597; Hm_lpvt_563fb31e93813a8a7094966df6671d3f=1692278597',
30 'origin': 'https://chat9.fastgpt.me',
31 'plugins': '0',
32 'pragma': 'no-cache',
33 'referer': 'https://chat9.fastgpt.me/',
34 'sec-ch-ua': '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
35 'sec-ch-ua-mobile': '?0',
36 'sec-ch-ua-platform': '"macOS"',
37 'sec-fetch-dest': 'empty',
38 'sec-fetch-mode': 'cors',
39 'sec-fetch-site': 'same-origin',
40 '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',
41 'usesearch': 'false',
42 'x-requested-with': 'XMLHttpRequest',
43 }
44
45 json_data = {
46 'messages': messages,
47 'stream': stream,
48 'model': model,
49 'temperature': kwargs.get('temperature', 0.5),
50 'presence_penalty': kwargs.get('presence_penalty', 0),
51 'frequency_penalty': kwargs.get('frequency_penalty', 0),
52 'top_p': kwargs.get('top_p', 1),
53 }
54
55 subdomain = random.choice([
56 'jdaen979ew',
57 'chat9'
58 ])
59
60 response = requests.post(f'https://{subdomain}.fastgpt.me/api/openai/v1/chat/completions',
61 headers=headers, json=json_data, stream=stream)
62
63 for line in response.iter_lines():
64 if line:
65 try:
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 except:
72 continue
73
74 @classmethod
75 @property
76 def params(cls):
77 params = [
78 ("model", "str"),
79 ("messages", "list[dict[str, str]]"),
80 ("stream", "bool"),
81 ]
82 param = ", ".join([": ".join(p) for p in params])
83 return f"g4f.provider.{cls.__name__} supports: ({param})"
Modified g4f/Provider/__init__.py +4 -0
@@ -23,6 +23,8 @@ from .Vercel import Vercel
23 23 from .Wewordle import Wewordle
24 24 from .You import You
25 25 from .Yqcloud import Yqcloud
26 from .Equing import Equing
27 from .FastGpt import FastGpt
26 28
27 29 __all__ = [
28 30 "BaseProvider",
@@ -50,4 +52,6 @@ __all__ = [
50 52 "Wewordle",
51 53 "You",
52 54 "Yqcloud",
55 "Equing",
56 "FastGpt"
53 57 ]
Modified g4f/Provider/base_provider.py +1 -1
@@ -30,4 +30,4 @@ class BaseProvider(ABC):
30 30 ("stream", "bool"),
31 31 ]
32 32 param = ", ".join([": ".join(p) for p in params])
33 return f"g4f.provider.{cls.__name__} supports: ({param})"
33 return f"g4f.provider.{cls.__name__} supports: ({param})"
Modified g4f/models.py +2 -2
@@ -1,6 +1,6 @@
1 1 from dataclasses import dataclass
2 2
3 from .Provider import Bard, BaseProvider, GetGpt, H2o, Liaobots, Vercel
3 from .Provider import Bard, BaseProvider, GetGpt, H2o, Liaobots, Vercel, Equing
4 4
5 5
6 6 @dataclass
@@ -131,7 +131,7 @@ gpt_35_turbo_16k = Model(
131 131 gpt_35_turbo_16k_0613 = Model(
132 132 name="openai:gpt-3.5-turbo-16k-0613",
133 133 base_provider="openai",
134 best_provider=Vercel,
134 best_provider=Equing,
135 135 )
136 136
137 137 gpt_4_0613 = Model(