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

XFEstudio/gpt4free

update header & response easychat

0dd20ff7
Bagus Indrayana <bagusindrayanaindo@gmail.com>
提交于

代码差异

1 个文件 +30 -9
Modified g4f/Provider/EasyChat.py +30 -9
@@ -10,6 +10,7 @@ class EasyChat(BaseProvider):
10 10 url = "https://free.easychat.work"
11 11 supports_stream = True
12 12 supports_gpt_35_turbo = True
13 working = True
13 14
14 15 @staticmethod
15 16 def create_completion(
@@ -25,6 +26,7 @@ class EasyChat(BaseProvider):
25 26 "https://chat2.fastgpt.me",
26 27 "https://chat3.fastgpt.me",
27 28 "https://chat4.fastgpt.me",
29 "https://gxos1h1ddt.fastgpt.me"
28 30 ]
29 31 server = active_servers[kwargs.get("active_server", 0)]
30 32 headers = {
@@ -34,9 +36,17 @@ class EasyChat(BaseProvider):
34 36 "content-type": "application/json",
35 37 "origin": f"{server}",
36 38 "referer": f"{server}/",
37 "sec-ch-ua": '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
38 "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",
39 39 "x-requested-with": "XMLHttpRequest",
40 'plugins': '0',
41 'sec-ch-ua': '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
42 'sec-ch-ua-mobile': '?0',
43 'sec-ch-ua-platform': '"Windows"',
44 'sec-fetch-dest': 'empty',
45 'sec-fetch-mode': 'cors',
46 'sec-fetch-site': 'same-origin',
47 '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',
48 'usesearch': 'false',
49 'x-requested-with': 'XMLHttpRequest'
40 50 }
41 51
42 52 json_data = {
@@ -57,14 +67,25 @@ class EasyChat(BaseProvider):
57 67 f"{server}/api/openai/v1/chat/completions",
58 68 headers=headers,
59 69 json=json_data,
70 stream=stream,
60 71 )
61
62 response.raise_for_status()
63 print(response.text)
64 for chunk in response.iter_lines():
65 if b"content" in chunk:
66 data = json.loads(chunk.decode().split("data: ")[1])
67 yield data["choices"][0]["delta"]["content"]
72 if response.status_code == 200:
73 if stream == False:
74 json_data = response.json()
75 if "choices" in json_data:
76 yield json_data["choices"][0]["message"]["content"]
77 else:
78 yield Exception("No response from server")
79 else:
80
81 for chunk in response.iter_lines():
82 if b"content" in chunk:
83 splitData = chunk.decode().split("data: ")
84 if len(splitData) > 1:
85 yield json.loads(splitData[1])["choices"][0]["delta"]["content"]
86 else:
87 yield Exception(f"Error {response.status_code} from server")
88
68 89
69 90 @classmethod
70 91 @property